assemblyscript
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -11,108 +11,126 @@ /** | ||
/** An 8-bit signed integer. */ | ||
declare type sbyte = number; | ||
declare type i8 = number; | ||
/** An 8-bit unsigned integer. */ | ||
declare type byte = number; | ||
declare type u8 = number; | ||
/** A 16-bit signed integer. */ | ||
declare type short = number; | ||
declare type i16 = number; | ||
/** A 16-bit unsigned integer. */ | ||
declare type ushort = number; | ||
declare type u16 = number; | ||
/** A 32-bit signed integer. */ | ||
declare type int = number; | ||
declare type i32 = number; | ||
/** A 32-bit unsigned integer. */ | ||
declare type uint = number; | ||
declare type u32 = number; | ||
/** A 64-bit signed integer. */ | ||
declare type long = number; | ||
declare type i64 = number; | ||
/** A 64-bit unsigned integer. */ | ||
declare type ulong = number; | ||
declare type u64 = number; | ||
/** A 32-bit float. */ | ||
declare type f32 = number; | ||
/** A 64-bit float. */ | ||
declare type f64 = number; | ||
/** A 1-bit unsigned integer. */ | ||
declare type bool = any; // as required for logical '&&' / '||' | ||
/** A 32-bit float. */ | ||
declare type float = number; | ||
/** A 64-bit float. */ | ||
declare type double = number; | ||
/** A 32-bit unsigned integer when targeting WASM32 respectively a 64-bit unsigned integer when targeting WASM64. */ | ||
declare type uintptr = number; | ||
declare type usize = number; | ||
// Core type aliases | ||
/** An 8-bit signed integer. */ | ||
declare type int8 = sbyte; | ||
/** An 8-bit unsigned integer. */ | ||
declare type uint8 = byte; | ||
/** A 16-bit signed integer. */ | ||
declare type int16 = short; | ||
/** A 16-bit unsigned integer. */ | ||
declare type uint16 = ushort; | ||
/** A 32-bit signed integer. */ | ||
declare type int32 = int; | ||
/** A 32-bit signed integer. */ | ||
declare type uint32 = uint; | ||
/** A 64-bit signed integer. */ | ||
declare type int64 = long; | ||
/** A 64-bit unsigned integer. */ | ||
declare type uint64 = ulong; | ||
/** A 32-bit float. */ | ||
declare type float32 = float; | ||
/** A 64-bit float. */ | ||
declare type float64 = double; | ||
/** An 8-bit signed integer. Alias of `i8`. */ | ||
declare type sbyte = i8; | ||
/** An 8-bit unsigned integer. Alias of `u8`. */ | ||
declare type byte = u8; | ||
/** A 16-bit signed integer. Alias of `i16`. */ | ||
declare type short = i16; | ||
/** A 16-bit unsigned integer. Alias of `u16`. */ | ||
declare type ushort = u16; | ||
/** A 32-bit signed integer. Alias of `i32`. */ | ||
declare type int = i32; | ||
/** A 32-bit signed integer. Alias of `u32`. */ | ||
declare type uint = u32; | ||
/** A 64-bit signed integer. Alias of `i64`. */ | ||
declare type long = i64; | ||
/** A 64-bit unsigned integer. Alias of `u64`. */ | ||
declare type ulong = u64; | ||
/** A 32-bit float. Alias of `f32`. */ | ||
declare type float = f32; | ||
/** A 64-bit float. Alias of `f64`. */ | ||
declare type double = f64; | ||
/** A 32-bit unsigned integer when targeting WASM32 respectively a 64-bit unsigned integer when targeting WASM64. Alias of `usize`. */ | ||
declare type uintptr = usize; | ||
/** An 8-bit signed integer. Alias of `i8`. */ | ||
declare type int8 = i8; | ||
/** An 8-bit unsigned integer. Alias of `u8`. */ | ||
declare type uint8 = u8; | ||
/** A 16-bit signed integer. Alias of `i16`. */ | ||
declare type int16 = i16; | ||
/** A 16-bit unsigned integer. Alias of `u16`. */ | ||
declare type uint16 = u16; | ||
/** A 32-bit signed integer. Alias of `i32`. */ | ||
declare type int32 = i32; | ||
/** A 32-bit signed integer. Alias of `u32`. */ | ||
declare type uint32 = u32; | ||
/** A 64-bit signed integer. Alias of `i64`. */ | ||
declare type int64 = i64; | ||
/** A 64-bit unsigned integer. Alias of `u64`. */ | ||
declare type uint64 = u64; | ||
/** A 32-bit float. Alias of `f32`. */ | ||
declare type float32 = f32; | ||
/** A 64-bit float. Alias of `f64`. */ | ||
declare type float64 = f64; | ||
// Globals | ||
/** NaN (not a number) as a 64-bit float. */ | ||
declare const NaN: double; | ||
declare const NaN: f64; | ||
/** NaN (not a number) as a 32-bit float. */ | ||
declare const NaNf: float; | ||
declare const NaNf: f32; | ||
/** Positive infinity as a 64-bit float. */ | ||
declare const Infinity: double; | ||
declare const Infinity: f64; | ||
/** Positive infinity as a 32-bit float. */ | ||
declare const Infinityf: float; | ||
declare const Infinityf: f32; | ||
declare abstract class Disposable implements IDisposable { | ||
dispose(): void; | ||
} | ||
// Arrays | ||
/** A fixed-size array. */ | ||
declare class Array<T> extends Disposable { | ||
declare class Array<T> implements IDisposable { | ||
/** Maximum number of elements this array can hold without resizing. */ | ||
readonly capacity: int; | ||
readonly capacity: i32; | ||
/** Number of elements this array currently holds. */ | ||
length: int; | ||
length: i32; | ||
/** Constructs a new array with the specified number of elements. */ | ||
constructor(arrayLength: int); | ||
constructor(arrayLength: i32); | ||
/** Returns the first index at which a given element can be found in the array, or `-1` if it is not present. The array is searched forward, starting at `fromIndex`. */ | ||
indexOf(searchElement: T, fromIndex?: int): int; | ||
indexOf(searchElement: T, fromIndex?: i32): i32; | ||
/** Returns the last index at which a given element can be found in the array, or `-1` if it is not present. The array is searched backwards, starting at `fromIndex`. */ | ||
lastIndexOf(searchElement: T, fromIndex?: int): int; | ||
lastIndexOf(searchElement: T, fromIndex?: i32): i32; | ||
/** Creates a shallow copy of a portion of the array as a new array object selected from `begin` to `end` (`end` not included). The original array will not be modified. */ | ||
slice(begin?: int, end?: int): this; | ||
slice(begin?: i32, end?: i32): this; | ||
/** Reverses the array's elements in place. The first array element becomes the last, and the last array element becomes the first. */ | ||
reverse(): this; | ||
/** Grows the array to the specified new capacity, frees the current reference (unsafe) and returns the new reference. Traps if `newCapacity` is less than or equal the current capacity. */ | ||
// unsafeGrow(newCapacity: int): this; | ||
dispose(): void; | ||
} | ||
/** A fixed-size 8-bit signed integer array. */ | ||
declare class Int8Array extends Array<sbyte> {} | ||
declare class Int8Array extends Array<i8> {} | ||
/** A fixed-size 8-bit unsigned integer array. */ | ||
declare class Uint8Array extends Array<byte> {} | ||
declare class Uint8Array extends Array<u8> {} | ||
/** A fixed-size 16-bit signed integer array. */ | ||
declare class Int16Array extends Array<short> {} | ||
declare class Int16Array extends Array<i16> {} | ||
/** A fixed-size 16-bit unsigned integer array. */ | ||
declare class Uint16Array extends Array<ushort> {} | ||
declare class Uint16Array extends Array<u16> {} | ||
/** A fixed-size 32-bit signed integer array. */ | ||
declare class Int32Array extends Array<int> {} | ||
declare class Int32Array extends Array<i32> {} | ||
/** A fixed-size 32-bit unsigned integer array. */ | ||
declare class Uint32Array extends Array<uint> {} | ||
declare class Uint32Array extends Array<u32> {} | ||
/** A fixed-size 64-bit signed integer array. */ | ||
declare class Int64Array extends Array<long> {} | ||
declare class Int64Array extends Array<i64> {} | ||
/** A fixed-size 64-bit unsigned integer array. */ | ||
declare class Uint64Array extends Array<ulong> {} | ||
declare class Uint64Array extends Array<u64> {} | ||
/** A fixed-size 32-bit float array. */ | ||
declare class Float32Array extends Array<float> {} | ||
declare class Float32Array extends Array<f32> {} | ||
/** A fixed-size 64-bit float array. */ | ||
declare class Float64Array extends Array<double> {} | ||
declare class Float64Array extends Array<f64> {} | ||
@@ -122,8 +140,8 @@ // Strings | ||
/** A fixed-size UTF-16LE encoded string. */ | ||
declare class String extends Array<ushort> { | ||
declare class String extends Array<u16> { | ||
/** Constructs a new string with the specified number of characters. */ | ||
constructor(size: int); | ||
constructor(size: i32); | ||
/** Returns the index within the string of the first occurrence of the specified value or `-1` if the value is not found. */ | ||
indexOfString(value: string): int; | ||
indexOfString(value: string): i32; | ||
/** Determines whether the string begins with the specified value. */ | ||
@@ -135,4 +153,17 @@ startsWith(value: string): bool; | ||
// Errors | ||
/** An error. */ | ||
declare class Error { | ||
/** Error message. */ | ||
message: string; | ||
/** Constructs a new error with the specified message. */ | ||
constructor(message: string); | ||
} | ||
// Console | ||
/** Imported log interface. */ | ||
declare function log(type: i32, message: string): void; | ||
/** Console bindings. */ | ||
@@ -153,69 +184,69 @@ declare class console { | ||
/** Performs the sign-agnostic rotate left operation on a 32-bit integer. */ | ||
declare function rotl(value: int, shift: int): int; | ||
declare function rotl(value: i32, shift: i32): i32; | ||
/** Performs the sign-agnostic rotate left operation on a 64-bit integer. */ | ||
declare function rotll(value: long, shift: long): long; | ||
declare function rotll(value: i64, shift: i64): i64; | ||
/** Performs the sign-agnostic rotate right operation on a 32-bit integer. */ | ||
declare function rotr(value: int, shift: int): int; | ||
declare function rotr(value: i32, shift: i32): i32; | ||
/** Performs the sign-agnostic rotate right operation on a 64-bit integer. */ | ||
declare function rotrl(value: long, shift: long): long; | ||
declare function rotrl(value: i64, shift: i64): i64; | ||
/** Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. */ | ||
declare function clz(value: int): int; | ||
declare function clz(value: i32): i32; | ||
/** Performs the sign-agnostic count leading zero bits operation on a 64-bit integer. All zero bits are considered leading if the value is zero. */ | ||
declare function clzl(value: long): long; | ||
declare function clzl(value: i64): i64; | ||
/** Performs the sign-agnostic count trailing zero bits operation on a 32-bit integer. All zero bits are considered trailing if the value is zero. */ | ||
declare function ctz(value: int): int; | ||
declare function ctz(value: i32): i32; | ||
/** Performs the sign-agnostic count trailing zero bits operation on a 64-bit integer. All zero bits are considered trailing if the value is zero. */ | ||
declare function ctzl(value: long): long; | ||
declare function ctzl(value: i64): i64; | ||
/** Performs the sign-agnostic count number of one bits operation on a 32-bit integer. */ | ||
declare function popcnt(value: int): int; | ||
declare function popcnt(value: i32): i32; | ||
/** Performs the sign-agnostic count number of one bits operation on a 64-bit integer. */ | ||
declare function popcntl(value: long): long; | ||
declare function popcntl(value: i64): i64; | ||
/** Computes the absolute value of a 64-bit float. */ | ||
declare function abs(value: double): double; | ||
declare function abs(value: f64): f64; | ||
/** Computes the absolute value of a 32-bit float. */ | ||
declare function absf(value: float): float; | ||
declare function absf(value: f32): f32; | ||
/** Performs the ceiling operatoion on a 64-bit float. */ | ||
declare function ceil(value: double): double; | ||
declare function ceil(value: f64): f64; | ||
/** Performs the ceiling operation on a 32-bit float. */ | ||
declare function ceilf(value: float): float; | ||
declare function ceilf(value: f32): f32; | ||
/** Performs the floor operation on a 64-bit float. */ | ||
declare function floor(value: double): double; | ||
declare function floor(value: f64): f64; | ||
/** Performs the floor operation on a 32-bit float. */ | ||
declare function floorf(value: float): float; | ||
declare function floorf(value: f32): f32; | ||
/** Calculates the square root of a 64-bit float. */ | ||
declare function sqrt(value: double): double; | ||
declare function sqrt(value: f64): f64; | ||
/** Calculates the square root of a 32-bit float. */ | ||
declare function sqrtf(value: float): float; | ||
declare function sqrtf(value: f32): f32; | ||
/** Rounds to nearest integer towards zero of a 64-bit float. */ | ||
declare function trunc(value: double): double; | ||
declare function trunc(value: f64): f64; | ||
/** Rounds to nearest integer towards zero of a 32-bit float. */ | ||
declare function truncf(value: float): float; | ||
declare function truncf(value: f32): f32; | ||
/** Rounds to nearest integer tied to even of a 64-bit float. */ | ||
declare function nearest(value: double): double; | ||
declare function nearest(value: f64): f64; | ||
/** Rounds to nearest integer tied to even of a 32-bit float. */ | ||
declare function nearestf(value: float): float; | ||
declare function nearestf(value: f32): f32; | ||
/** Determines the minimum of two 64-bit floats. If either operand is NaN, returns NaN. */ | ||
declare function min(left: double, right: double): double; | ||
declare function min(left: f64, right: f64): f64; | ||
/** Determines the minimum of two 32-bit floats. If either operand is NaN, returns NaN. */ | ||
declare function minf(left: float, right: float): float; | ||
declare function minf(left: f32, right: f32): f32; | ||
/** Determines the maximum of two 64-bit floats. If either operand is NaN, returns NaN. */ | ||
declare function max(left: double, right: double): double; | ||
declare function max(left: f64, right: f64): f64; | ||
/** Determines the maximum of two 32-bit floats. If either operand is NaN, returns NaN. */ | ||
declare function maxf(left: float, right: float): float; | ||
declare function maxf(left: f32, right: f32): f32; | ||
/** Composes a 64-bit float from the magnitude of `x` and the sign of `y`. */ | ||
declare function copysign(x: double, y: double): double; | ||
declare function copysign(x: f64, y: f64): f64; | ||
/** Composes a 32-bit float from the magnitude of `x` and the sign of `y`. */ | ||
declare function copysignf(x: float, y: float): float; | ||
declare function copysignf(x: f32, y: f32): f32; | ||
/** Reinterprets the bits of a 32-bit float as a 32-bit integer. */ | ||
declare function reinterpreti(value: float): int; | ||
declare function reinterpreti(value: f32): i32; | ||
/** Reinterprets the bits of a 64-bit float as a 64-bit integer. */ | ||
declare function reinterpretl(value: double): long; | ||
declare function reinterpretl(value: f64): i64; | ||
/** Reinterprets the bits of a 32-bit integer as a 32-bit float. */ | ||
declare function reinterpretf(value: int): float; | ||
declare function reinterpretf(value: i32): f32; | ||
/** Reinterprets the bits of a 64-bit integer as a 64-bit double. */ | ||
declare function reinterpretd(value: long): double; | ||
declare function reinterpretd(value: i64): f64; | ||
/** Returns the current memory size in units of pages. One page is 64kb. */ | ||
declare function current_memory(): int; | ||
declare function current_memory(): i32; | ||
/** Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. */ | ||
declare function grow_memory(value: uint): int; | ||
declare function grow_memory(value: i32): i32; | ||
/** Emits an unreachable operation that results in a runtime error when executed. */ | ||
@@ -225,29 +256,50 @@ declare function unreachable(): void; | ||
/** Determines the byte size of the specified core or class type. Compiles to a constant. */ | ||
declare function sizeof<T>(): uintptr; | ||
declare function sizeof<T>(): usize; | ||
/** Loads a value of the specified type from memory. */ | ||
declare function load<T>(offset: usize): T; | ||
/** Stores a value of the specified type to memory. */ | ||
declare function store<T>(offset: usize, value: T): void; | ||
/** Casts a value of type `T1` to a value of type `T2`. Useful for casting classes to pointers and vice-versa. Does not perform any checks. */ | ||
declare function unsafe_cast<T1,T2>(value: T1): T2; | ||
/** Tests if a 64-bit float is a NaN. */ | ||
declare function isNaN(value: double): bool; | ||
declare function isNaN(value: f64): bool; | ||
/** Tests if a 32-bit float is a NaN. */ | ||
declare function isNaNf(value: float): bool; | ||
declare function isNaNf(value: f32): bool; | ||
/** Tests if a 64-bit float is finite. */ | ||
declare function isFinite(value: double): bool; | ||
declare function isFinite(value: f64): bool; | ||
/** Tests if a 32-bit float is finite. */ | ||
declare function isFinitef(value: float): bool; | ||
declare function isFinitef(value: f32): bool; | ||
// Optional malloc implementation | ||
// Core runtime | ||
/** Sets a chunk of memory to the provided value `c`. Usually used to reset it to all `0`s. */ | ||
declare function memset(dest: uintptr, c: int, size: uintptr): uintptr; | ||
declare function memset(dest: usize, c: i32, size: usize): usize; | ||
/** Copies data from one chunk of memory to another. */ | ||
declare function memcpy(dest: uintptr, src: uintptr, size: uintptr): uintptr; | ||
declare function memcpy(dest: usize, src: usize, size: usize): usize; | ||
/** Compares a chunk of memory to another. Returns `0` if both are equal, otherwise the difference `vl[i] - vr[i]` of the first differing byte values. */ | ||
declare function memcmp(left: uintptr, right: uintptr, size: uintptr): int; | ||
/** Allocates a chunk of memory of the specified size and returns a pointer to it. */ | ||
declare function malloc(size: uintptr): uintptr; | ||
/** Frees a previously allocated chunk of memory by its pointer. */ | ||
declare function free(ptr: uintptr): void; | ||
/** Called to initialize malloc if imported. */ | ||
declare function malloc_init(offset: uintptr): void; | ||
declare function memcmp(left: usize, right: usize, size: usize): i32; | ||
/** Allocates a chunk of memory of the specified size. */ | ||
declare function malloc(size: usize): usize; | ||
/** Changes the size of an allocated memory block. */ | ||
declare function realloc(ptr: usize, size: usize): usize; | ||
/** Frees a previously allocated chunk of memory. */ | ||
declare function free(ptr: usize): void; | ||
// Experimental garbage collector runtime | ||
/** Pauses automatic garbage collection. */ | ||
declare function gc_pause(): void; | ||
/** Resumes automatic garbage collection. */ | ||
declare function gc_resume(): void; | ||
/** Runs the garbage collector. */ | ||
declare function gc_collect(): void; | ||
/** Allocates a garbage collector controlled chunk of memory of the specified size. */ | ||
declare function gc_alloc(size: usize, flags: i32): usize; | ||
/** Changes the size of a garbage collector controlled memory block. */ | ||
declare function gc_realloc(ptr: usize, size: usize): usize; | ||
/** Retains a gargabe collector controlled memory block. */ | ||
declare function gc_retain(ptr: usize): usize; | ||
/** Releases a garbage collector controlled memory block previously retained. */ | ||
declare function gc_release(ptr: usize): usize; | ||
// Temporary fillers | ||
@@ -254,0 +306,0 @@ |
@@ -13,7 +13,7 @@ var fs = require("fs"); | ||
if (isDev) { | ||
if (fs.existsSync(__dirname + "/../out/index.js")) { | ||
if (process.argv.indexOf("--debugger") > -1 && fs.existsSync(__dirname + "/../out/index.js")) { | ||
assemblyscript = require("../out"); | ||
isOut = true; | ||
} else { | ||
require("ts-node/register"); | ||
require("ts-node").register({ project: __dirname + "/../src" }); | ||
assemblyscript = require("../src"); | ||
@@ -58,4 +58,7 @@ } | ||
else if (files.length) | ||
if (!fs.existsSync(configFile = path.join(path.dirname(files[0]), "asconfig.json"))) | ||
if (!fs.existsSync(configFile = path.join(path.dirname(files[0]), "asconfig.json"))) { | ||
configFile = undefined; | ||
if (!fs.existsSync(configFile = path.join(path.dirname(files[0]), "tsconfig.json"))) | ||
configFile = undefined; | ||
} | ||
@@ -66,10 +69,15 @@ // load config file | ||
var config = JSON.parse(fs.readFileSync(configFile, "utf8")); | ||
if (config.assembly) | ||
config = config.assembly; | ||
if (config.entryFile) { | ||
if (!files.length) // prefer command line | ||
files = [ config.entryFile ]; | ||
delete config.file; | ||
delete config.entryFile; | ||
} | ||
Object.keys(config).forEach(key => { | ||
if (options[key] && key !== "config") | ||
argv[key] = config[key]; | ||
if (options[key] && key !== "config") // prefer command line | ||
if (options[key].isPath) | ||
argv[key] = path.isAbsolute(config[key]) ? config[key] : path.join(path.dirname(configFile), config[key]); | ||
else | ||
argv[key] = config[key]; | ||
}); | ||
@@ -96,5 +104,5 @@ } catch (e) { | ||
cmd += ", -" + opt.aliases[0]; | ||
while (cmd.length < 20) | ||
while (cmd.length < 18) | ||
cmd += " "; | ||
return cmd + opt.desc.replace(/\n/g, "\n ") + "\n"; | ||
return cmd + " " + opt.desc.replace(/\n/g, "\n ") + "\n"; | ||
})).join("\n").replace(/\[default\]/g, chalk.gray("[default]"))); | ||
@@ -108,3 +116,8 @@ return callback(argv.help ? ESUCCESS : EUSAGE); | ||
target: argv.target, | ||
memoryModel: argv.memoryModel | ||
noTreeShaking: !!argv.noTreeShaking, | ||
noImplicitConversion: !!argv.noImplicitConversion, | ||
noRuntime: !!argv.noRuntime, | ||
exportRuntime: Array.isArray(argv.exportRuntime) ? argv.exportRuntime | ||
: typeof argv.exportRuntime === "string" ? [ argv.exportRuntime ] | ||
: undefined | ||
}); | ||
@@ -132,3 +145,3 @@ | ||
// default to text format if --outFile references a .wast or .wat and --textFormat isn't specified | ||
// default to text format if --outFile references a .wast, .wat or .js and --textFormat isn't specified | ||
if (argv.outFile && !argv.textFormat) { | ||
@@ -139,2 +152,4 @@ if (/\.wast$/.test(argv.outFile)) | ||
argv.textFormat = "linear"; | ||
else if (/\.js$/.test(argv.outfile)) | ||
argv.textFormat = "asmjs"; | ||
} | ||
@@ -145,17 +160,28 @@ | ||
// emit a text file alongside a binary if --textFile is provided | ||
if (argv.textFile) | ||
writeBinary(wasmModule, output, function(err) { | ||
if (err) return finish(err); | ||
writeText(wasmModule, argv.textFormat || /\.wat$/.test(argv.textFile) && "linear" || "sexpr", fs.createWriteStream(argv.textFile), finish); | ||
}); | ||
// emit text format (textFormat is requested but no textFile has been specified) + asm.js (if applicable) | ||
if ((argv.textFormat !== undefined || output.isTTY) && !argv.textFile) { | ||
if (argv.textFormat === "asmjs" || /\.js$/.test(argv.outFile)) | ||
writeAsmjs(wasmModule, output, finish); | ||
else | ||
writeText(wasmModule, argv.textFormat, output, maybeWriteAsmjs); | ||
// emit just text format if --textFormat is provided but --textFile isn't | ||
else if (argv.textFormat !== undefined || output.isTTY) | ||
writeText(wasmModule, argv.textFormat, output, finish); | ||
// emit a binary + text format (if specified) + asm.js (if specified) | ||
} else | ||
writeBinary(wasmModule, output, maybeWriteText); | ||
// emit a binary otherwise | ||
else | ||
writeBinary(wasmModule, output, finish); | ||
function maybeWriteText(err) { | ||
if (err || !argv.textFile) | ||
return finish(err); | ||
if (argv.textFormat === "asmjs" || (!argv.textFormat && /\.js$/.test(argv.textFile))) | ||
writeAsmjs(wasmModule, fs.createWriteStream(argv.textFile), finish); | ||
else | ||
writeText(wasmModule, argv.textFormat || /\.wat$/.test(argv.textFile) && "linear" || "sexpr", fs.createWriteStream(argv.textFile), maybeWriteAsmjs); | ||
} | ||
function maybeWriteAsmjs(err) { | ||
if (err || !argv.asmjsFile) | ||
return finish(err); | ||
writeAsmjs(wasmModule, fs.createWriteStream(argv.asmjsFile), finish); | ||
} | ||
function finish(err) { | ||
@@ -199,2 +225,12 @@ wasmModule.dispose(); | ||
/** Writes the asm.js representation of the specified module. */ | ||
function writeAsmjs(wasmModule, output, callback) { | ||
output.write(Buffer.from(wasmModule.emitAsmjs()), end); | ||
function end(err) { | ||
if (err || output === process.stdout) return callback(err); | ||
output.end(callback); | ||
} | ||
} | ||
exports.writeBinary = writeBinary; |
@@ -8,5 +8,6 @@ { | ||
"outFile": { | ||
"desc": "Specifies the output file name. Emits text format if ending with .wast\n(sexpr) or .wat (linear). Prints to stdout if omitted.", | ||
"desc": "Specifies the output file name. Emits text format if ending with .wast\n(sexpr), .wat (linear) or .js (asmjs). Prints to stdout if omitted.", | ||
"type": "string", | ||
"aliases": [ "o", "outfile", "out-file", "out" ] | ||
"aliases": [ "o", "outfile", "out-file", "out" ], | ||
"isPath": true | ||
}, | ||
@@ -37,10 +38,4 @@ "optimize": { | ||
}, | ||
"memoryModel": { | ||
"desc": "Specifies the memory model to use / how to proceed with malloc etc.:\n\nmalloc Bundles malloc etc. [default]\nexportmalloc Bundles malloc etc. and exports each\nimportmalloc Imports malloc etc. from 'env'\nbare Excludes malloc etc. entirely", | ||
"type": "string", | ||
"aliases": [ "m", "memorymodel", "memory-model" ], | ||
"default": "malloc" | ||
}, | ||
"textFormat": { | ||
"desc": "Specifies the format to use for text output:\n\nsexpr Emits s-expression syntax (.wast) [default]\nlinear Emits official linear syntax (.wat)\n\nText format only is emitted when used without --textFile.", | ||
"desc": "Specifies the format to use for text output:\n\nsexpr Emits s-expression syntax (.wast) [default]\nlinear Emits official linear syntax (.wat)\nasmjs Emits just asm.js (.js) - experimental\n\nText format only is emitted when used without --textFile.", | ||
"type": "string", | ||
@@ -52,4 +47,33 @@ "aliases": [ "f", "textformat", "text-format", "text" ] | ||
"type": "string", | ||
"aliases": [ "textfile", "text-file", "textOut", "textout", "text-out" ] | ||
"aliases": [ "textfile", "text-file", "textOut", "textout", "text-out" ], | ||
"isPath": true | ||
}, | ||
"asmjsFile": { | ||
"desc": "Can be used to save asm.js alongside a binary in one command. - experimental", | ||
"type": "string", | ||
"aliases": ["asmjsfile", "asmjs-file", "asmjs"] | ||
}, | ||
"noTreeShaking": { | ||
"desc": "Whether to disable built-in tree-shaking.", | ||
"type": "boolean", | ||
"aliases": [ "no-tree-shaking" ], | ||
"default": false | ||
}, | ||
"noImplicitConversion": { | ||
"desc": "Whether to disallow implicit type conversions.", | ||
"type": "boolean", | ||
"aliases": [ "no-implicit-conversion" ], | ||
"default": false | ||
}, | ||
"noRuntime": { | ||
"desc": "Whether to exclude the runtime.", | ||
"type": "boolean", | ||
"aliases": [ "no-runtime" ], | ||
"default": false | ||
}, | ||
"exportRuntime": { | ||
"desc": "Runtime functions to export, defaults to 'malloc' and 'free'. [multiple]", | ||
"type": "string", | ||
"aliases": [ "e", "export-runtime", "export" ] | ||
}, | ||
"help": { | ||
@@ -56,0 +80,0 @@ "desc": "Displays this help message.", |
@@ -6,3 +6,3 @@ Distributions | ||
Note that [binaryen.js](https://github.com/dcodeIO/binaryen.js) (required) and [wabt.js](https://github.com/dcodeIO/wabt.js) (optional) are not included in the bundle because these are rather large asm.js compilations. Compatible versions of both dependencies can be obtained from their [respective](https://github.com/dcodeIO/binaryen.js/tags) [repositories](https://github.com/dcodeIO/wabt.js/tags). | ||
Note that [binaryen.js](https://github.com/AssemblyScript/binaryen.js) (required) and [wabt.js](https://github.com/AssemblyScript/wabt.js) (optional) are not included in the bundle because these are rather large asm.js compilations. Compatible versions of both dependencies can be obtained from their [respective](https://github.com/AssemblyScript/binaryen.js/tags) [repositories](https://github.com/AssemblyScript/wabt.js/tags). | ||
@@ -23,5 +23,5 @@ Usage | ||
```html | ||
<script src="//rawgit.com/dcodeIO/binaryen.js/master/index.js"></script> | ||
<script src="//rawgit.com/dcodeIO/wabt.js/master/index.js"></script><!-- optional --> | ||
<script src="//rawgit.com/dcodeIO/AssemblyScript/master/dist/assemblyscript.js"></script> | ||
<script src="//rawgit.com/AssemblyScript/binaryen.js/master/index.js"></script> | ||
<script src="//rawgit.com/AssemblyScript/wabt.js/master/index.js"></script><!-- optional --> | ||
<script src="//rawgit.com/AssemblyScript/assemblyscript/master/dist/assemblyscript.js"></script> | ||
``` | ||
@@ -28,0 +28,0 @@ |
{ | ||
"name": "assemblyscript", | ||
"description": "A subset of TypeScript that compiles to WebAssembly.", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -9,6 +9,6 @@ "license": "Apache-2.0", | ||
"type": "git", | ||
"url": "https://github.com/dcodeIO/AssemblyScript.git" | ||
"url": "https://github.com/AssemblyScript/assemblyscript.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dcodeIO/AssemblyScript/issues" | ||
"url": "https://github.com/AssemblyScript/assemblyscript/issues" | ||
}, | ||
@@ -27,21 +27,18 @@ "keywords": [ | ||
"scripts": { | ||
"build:runtime": "node scripts/build-runtime", | ||
"build:typescript": "tsc -P lib/typescript && echo export = ts; >> lib/typescript/build/index.d.ts", | ||
"build:alldeps": "node scripts/build-check && npm run build:runtime && npm run build:typescript", | ||
"build:runtime": "cd lib/runtime && npm install && npm run build && cd ../..", | ||
"build:typescript": "cd lib/typescript && npm install && npm run build && cd ../..", | ||
"build:diagnostics": "node scripts/build-diagnostics", | ||
"build:library": "node scripts/build-library", | ||
"build:bundle-loader": "node scripts/build-bundle-loader", | ||
"build:bundle": "tsc -P src && node scripts/build-bundle", | ||
"build": "npm run build:diagnostics && npm run lint && npm run build:library && npm run build:bundle && npm run build:bundle-loader", | ||
"build": "(node scripts/check-typescript || npm run build:typescript) && npm run build:diagnostics && npm run build:library && npm run lint && npm run build:bundle", | ||
"clean": "node scripts/clean", | ||
"lint": "tslint --config tslint.json src/**/*.ts cli/**/*.ts assembly.d.ts", | ||
"test": "ts-node tests", | ||
"test:spec": "ts-node tests | tap-spec", | ||
"docs:api": "typedoc --tsconfig src/tsconfig.json --mode modules --name \"AssemblyScript API Documentation\" --out docs/api/ --readme none --ignoreCompilerErrors --excludeNotExported --excludePrivate", | ||
"docs:std": "typedoc --tsconfig tsconfig.assembly.json --mode file --name \"AssemblyScript Standard Library Documentation\" --out docs/std/ --readme none --ignoreCompilerErrors --excludeExternals --excludePrivate --includeDeclarations", | ||
"test": "ts-node -P tests/tsconfig.json tests", | ||
"docs:api": "typedoc --tsconfig src/tsconfig.json --mode modules --name \"AssemblyScript API Documentation\" --out ../website/docs/api/ --readme none --ignoreCompilerErrors --excludeNotExported --excludePrivate", | ||
"docs:std": "typedoc --tsconfig tsconfig.assembly.json --mode file --name \"AssemblyScript Standard Library Documentation\" --out ../website/docs/std/ --readme none --ignoreCompilerErrors --excludeExternals --excludePrivate --includeDeclarations", | ||
"docs": "npm run docs:api && npm run docs:std" | ||
}, | ||
"dependencies": { | ||
"binaryen": "1.37.16-nightly.20170719", | ||
"chalk": "^2.0.1", | ||
"binaryen": "37.0.0-nightly.20170909", | ||
"chalk": "^2.1.0", | ||
"minimist": "^1.2.0", | ||
@@ -53,14 +50,14 @@ "wabt": "0.0.13-nightly.20170628" | ||
"@types/chalk": "^0.4.31", | ||
"@types/diff": "^3.2.0", | ||
"@types/long": "^3.0.31", | ||
"@types/diff": "^3.2.2", | ||
"@types/long": "^3.0.32", | ||
"@types/minimist": "^1.2.0", | ||
"@types/node": "^8.0.17", | ||
"@types/rimraf": "0.0.28", | ||
"@types/node": "^8.0.28", | ||
"@types/rimraf": "^2.0.2", | ||
"@types/tape": "^4.2.30", | ||
"@types/webassembly-js-api": "0.0.1", | ||
"browserify": "^14.4.0", | ||
"diff": "^3.3.0", | ||
"diff": "^3.3.1", | ||
"dts-bundle": "^0.7.3", | ||
"gulp-header": "^1.8.9", | ||
"gulp-sourcemaps": "^2.6.0", | ||
"gulp-sourcemaps": "^2.6.1", | ||
"gulp-uglify": "^3.0.0", | ||
@@ -70,13 +67,11 @@ "long": "^3.2.0", | ||
"rimraf": "^2.6.1", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.7.0", | ||
"tape": "^4.8.0", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.5.0", | ||
"tslint": "^5.7.0", | ||
"typedoc": "^0.8.0", | ||
"typedoc-plugin-external-module-name": "github:dcodeIO/typedoc-plugin-external-module-name", | ||
"typescript": "^2.4.2", | ||
"typescript": "^2.5.2", | ||
"vinyl-buffer": "^1.0.0", | ||
"vinyl-fs": "^2.4.4", | ||
"vinyl-source-stream": "^1.1.0", | ||
"webassembly": "^0.11.0" | ||
"vinyl-source-stream": "^1.1.0" | ||
}, | ||
@@ -83,0 +78,0 @@ "browser": { |
251
README.md
@@ -1,9 +0,9 @@ | ||
![AssemblyScript](https://raw.githubusercontent.com/dcodeIO/AssemblyScript/master/logo.png) | ||
![AssemblyScript](https://raw.githubusercontent.com/AssemblyScript/assemblyscript/master/logo.png) | ||
============== | ||
[AssemblyScript](https://github.com/dcodeIO/AssemblyScript) defines a subset of [TypeScript](http://www.typescriptlang.org) that it compiles to [WebAssembly](http://webassembly.org). It aims to provide everyone with an existing background in TypeScript and standard JavaScript-APIs with a comfortable way to compile to WebAssembly, eliminating the need to switch between languages or to learn new ones just for this purpose. | ||
[AssemblyScript](https://github.com/AssemblyScript) defines a subset of [TypeScript](http://www.typescriptlang.org) that it compiles to [WebAssembly](http://webassembly.org). It aims to provide everyone with an existing background in TypeScript and standard JavaScript-APIs with a comfortable way to compile to WebAssembly, eliminating the need to switch between languages or to learn new ones just for this purpose. | ||
Try it out in your browser: [dcode.io/AssemblyScript](http://dcode.io/AssemblyScript/) | ||
Try it out [in your browser](http://assemblyscript.org/try)! | ||
[![npm](https://img.shields.io/npm/v/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript) [![Build Status](https://travis-ci.org/dcodeIO/AssemblyScript.svg?branch=master)](https://travis-ci.org/dcodeIO/AssemblyScript) [![npm](https://img.shields.io/npm/dm/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript) <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2Fprotobuf.js"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a> | ||
[![npm](https://img.shields.io/npm/v/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript) [![Build Status](https://travis-ci.org/AssemblyScript/assemblyscript.svg?branch=master)](https://travis-ci.org/AssemblyScript/assemblyscript) [![npm](https://img.shields.io/npm/dm/assemblyscript.svg)](https://www.npmjs.com/package/assemblyscript) <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=Open%20Source%20Software%20Donation&item_number=dcodeIO%2FAssemblyScript"><img alt="donate ❤" src="https://img.shields.io/badge/donate-❤-ff2244.svg"></a> | ||
@@ -44,3 +44,3 @@ Contents | ||
The compiler is able to produce WebAssembly binaries (.wasm) as well as their corresponding text format. Both Binaryen's s-expression format (.wast) and, with a little help of [WABT](https://github.com/WebAssembly/wabt), official linear text format (.wat) are supported. See also: [CLI](#command-line) | ||
The compiler is able to produce WebAssembly binaries (.wasm) as well as their corresponding text format. Both Binaryen's s-expression format (.wast) and, with a little help of [WABT](https://github.com/WebAssembly/wabt), official linear text format (.wat) are supported. Currently, there are also efforts on the Binaryen side to support asm.js (.js) output suitable as a compatibility fallback. See also: [CLI](#command-line) | ||
@@ -60,3 +60,3 @@ What to expect | ||
* Optional function parameters require an initializer expression | ||
* Union types, `any` and `undefined` are not supported by design | ||
* Union types (except `classType | null` representing a nullable), `any` and `undefined` are not supported by design | ||
* The result of logical `&&` / `||` expressions is always `bool` | ||
@@ -70,4 +70,4 @@ | ||
```ts | ||
export function add(a: int, b: double): short { | ||
return (a + (b as int)) as short; | ||
export function add(a: i32, b: i32): i16 { | ||
return (a + (b as i32)) as i16; | ||
} | ||
@@ -103,7 +103,7 @@ ``` | ||
See the pre-configured [example project](./examples/project) for a quickstart. | ||
See [the examples repository](https://github.com/AssemblyScript/examples) for more. | ||
### Running a module | ||
The stand-alone [loader component](./lib/loader) provides an easy way to run and work with compiled WebAssembly modules: | ||
The stand-alone [loader component](https://github.com/AssemblyScript/loader) provides an easy way to run and work with compiled WebAssembly modules: | ||
@@ -134,3 +134,3 @@ ``` | ||
The environment is configured by either referencing [assembly.d.ts](./assembly.d.ts) directly or by using a `tsconfig.json` that simply extends [tsconfig.assembly.json](https://github.com/dcodeIO/AssemblyScript/blob/master/tsconfig.assembly.json), like so: | ||
The environment is configured by either referencing [assembly.d.ts](./assembly.d.ts) directly or by using a `tsconfig.json` that simply extends [tsconfig.assembly.json](https://github.com/AssemblyScript/assemblyscript/blob/master/tsconfig.assembly.json), like so: | ||
@@ -150,106 +150,110 @@ ```json | ||
Type | Alias | Native type | sizeof | Description | ||
----------|-----------|-------------|--------|------------- | ||
`sbyte` | `int8` | i32 | 1 | An 8-bit signed integer. | ||
`byte` | `uint8` | i32 | 1 | An 8-bit unsigned integer. | ||
`short` | `int16` | i32 | 2 | A 16-bit signed integer. | ||
`ushort` | `uint16` | i32 | 2 | A 16-bit unsigned integer. | ||
`int` | `int32` | i32 | 4 | A 32-bit signed integer. | ||
`uint` | `uint32` | i32 | 4 | A 32-bit unsigned integer. | ||
`long` | `int64` | i64 | 8 | A 64-bit signed integer. | ||
`ulong` | `uint64` | i64 | 8 | A 64-bit unsigned integer. | ||
`uintptr` | - | i32 / i64 | 4 / 8 | A 32-bit unsigned integer when targeting 32-bit WebAssembly.<br />A 64-bit unsigned integer when targeting 64-bit WebAssembly. | ||
`float` | `float32` | f32 | 4 | A 32-bit float. | ||
`double` | `float64` | f64 | 8 | A 64-bit float. | ||
`bool` | - | i32 | 1 | A 1-bit unsigned integer. | ||
`void` | - | none | - | No return type | ||
Type | Aliases | Native type | sizeof | Description | ||
--------|---------------------|-------------|--------|------------- | ||
`i8` | `int8`, `sbyte` | i32 | 1 | An 8-bit signed integer. | ||
`u8` | `uint8`, `byte` | i32 | 1 | An 8-bit unsigned integer. | ||
`i16` | `int16`, `short` | i32 | 2 | A 16-bit signed integer. | ||
`u16` | `uint16`, `ushort` | i32 | 2 | A 16-bit unsigned integer. | ||
`i32` | `int32`, `int` | i32 | 4 | A 32-bit signed integer. | ||
`u32` | `uint32`, `uint` | i32 | 4 | A 32-bit unsigned integer. | ||
`i64` | `int64`, `long` | i64 | 8 | A 64-bit signed integer. | ||
`u64` | `uint64`, `ulong` | i64 | 8 | A 64-bit unsigned integer. | ||
`usize` | `uintptr` | i32 / i64 | 4 / 8 | A 32-bit unsigned integer when targeting 32-bit WebAssembly.<br />A 64-bit unsigned integer when targeting 64-bit WebAssembly. | ||
`f32` | `float32`, `float` | f32 | 4 | A 32-bit float. | ||
`f64` | `float64`, `double` | f64 | 8 | A 64-bit float. | ||
`bool` | - | i32 | 1 | A 1-bit unsigned integer. | ||
`void` | - | none | - | No return type | ||
While generating a warning to avoid type confusion, the JavaScript types `number` and `boolean` resolve to `double` and `bool` respectively. | ||
While generating a warning to avoid type confusion, the JavaScript types `number` and `boolean` resolve to `f64` and `bool` respectively. | ||
WebAssembly-specific operations are available as built-in functions that translate to the respective opcode directly: | ||
* **rotl**(value: `int`, shift: `int`): `int`<br /> | ||
* **rotl**(value: `i32`, shift: `i32`): `i32`<br /> | ||
Performs the sign-agnostic rotate left operation on a 32-bit integer. | ||
* **rotll**(value: `long`, shift: `long`): `long`<br /> | ||
* **rotll**(value: `i64`, shift: `i64`): `i64`<br /> | ||
Performs the sign-agnostic rotate left operation on a 64-bit integer. | ||
* **rotr**(value: `int`, shift: `int`): `int`<br /> | ||
* **rotr**(value: `i32`, shift: `i32`): `i32`<br /> | ||
Performs the sign-agnostic rotate right operation on a 32-bit integer. | ||
* **rotrl**(value: `long`, shift: `long`): `long`<br /> | ||
* **rotrl**(value: `i64`, shift: `i64`): `i64`<br /> | ||
Performs the sign-agnostic rotate right operation on a 64-bit integer. | ||
* **clz**(value: `int`): `int`<br /> | ||
* **clz**(value: `i32`): `i32`<br /> | ||
Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. | ||
* **clzl**(value: `long`): `long`<br /> | ||
* **clzl**(value: `i64`): `i64`<br /> | ||
Performs the sign-agnostic count leading zero bits operation on a 64-bit integer. All zero bits are considered leading if the value is zero. | ||
* **ctz**(value: `int`): `int`<br /> | ||
* **ctz**(value: `i32`): `i32`<br /> | ||
Performs the sign-agnostic count tailing zero bits operation on a 32-bit integer. All zero bits are considered trailing if the value is zero. | ||
* **ctzl**(value: `long`): `long`<br /> | ||
* **ctzl**(value: `i64`): `i64`<br /> | ||
Performs the sign-agnostic count trailing zero bits operation on a 64-bit integer. All zero bits are considered trailing if the value is zero. | ||
* **popcnt**(value: `int`): `int`<br /> | ||
* **popcnt**(value: `i32`): `i32`<br /> | ||
Performs the sign-agnostic count number of one bits operation on a 32-bit integer. | ||
* **popcntl**(value: `long`): `long`<br /> | ||
* **popcntl**(value: `i64`): `i64`<br /> | ||
Performs the sign-agnostic count number of one bits operation on a 64-bit integer. | ||
* **abs**(value: `double`): `double`<br /> | ||
* **abs**(value: `f64`): `f64`<br /> | ||
Computes the absolute value of a 64-bit float. | ||
* **absf**(value: `float`): `float`<br /> | ||
* **absf**(value: `f32`): `f32`<br /> | ||
Computes the absolute value of a 32-bit float. | ||
* **ceil**(value: `double`): `double`<br /> | ||
* **ceil**(value: `f64`): `f64`<br /> | ||
Performs the ceiling operation on a 64-bit float. | ||
* **ceilf**(value: `float`): `float`<br /> | ||
* **ceilf**(value: `f32`): `f32`<br /> | ||
Performs the ceiling operation on a 32-bit float. | ||
* **floor**(value: `double`): `double`<br /> | ||
* **floor**(value: `f64`): `f64`<br /> | ||
Performs the floor operation on a 64-bit float. | ||
* **floorf**(value: `float`): `float`<br /> | ||
* **floorf**(value: `f32`): `f32`<br /> | ||
Performs the floor operation on a 32-bit float. | ||
* **sqrt**(value: `double`): `double`<br /> | ||
* **sqrt**(value: `f64`): `f64`<br /> | ||
Calculates the square root of a 64-bit float. | ||
* **sqrtf**(value: `float`): `float`<br /> | ||
* **sqrtf**(value: `f32`): `f32`<br /> | ||
Calculates the square root of a 32-bit float. | ||
* **trunc**(value: `double`): `double`<br /> | ||
* **trunc**(value: `f64`): `f64`<br /> | ||
Rounds to the nearest integer towards zero of a 64-bit float. | ||
* **truncf**(value: `float`): `float`<br /> | ||
* **truncf**(value: `f32`): `f32`<br /> | ||
Rounds to the nearest integer towards zero of a 32-bit float. | ||
* **nearest**(value: `double`): `double`<br /> | ||
* **nearest**(value: `f64`): `f64`<br /> | ||
Rounds to the nearest integer tied to even of a 64-bit float. | ||
* **nearestf**(value: `float`): `float`<br /> | ||
* **nearestf**(value: `f32`): `f32`<br /> | ||
Rounds to the nearest integer tied to even of a 32-bit float. | ||
* **min**(left: `double`, right: `double`): `double`<br /> | ||
* **min**(left: `f64`, right: `f64`): `f64`<br /> | ||
Determines the minimum of two 64-bit floats. If either operand is `NaN`, returns `NaN`. | ||
* **minf**(left: `float`, right: `float`): `float`<br /> | ||
* **minf**(left: `f32`, right: `f32`): `f32`<br /> | ||
Determines the minimum of two 32-bit floats. If either operand is `NaN`, returns `NaN`. | ||
* **max**(left: `double`, right: `double`): `double`<br /> | ||
* **max**(left: `f64`, right: `f64`): `f64`<br /> | ||
Determines the maximum of two 64-bit floats. If either operand is `NaN`, returns `NaN`. | ||
* **maxf**(left: `float`, right: `float`): `float`<br /> | ||
* **maxf**(left: `f32`, right: `f32`): `f32`<br /> | ||
Determines the maximum of two 32-bit floats. If either operand is `NaN`, returns `NaN`. | ||
* **copysign**(x: `double`, y: `double`): `double`<br /> | ||
* **copysign**(x: `f64`, y: `f64`): `f64`<br /> | ||
Composes a 64-bit float from the magnitude of `x` and the sign of `y`. | ||
* **copysignf**(x: `float`, y: `float`): `float`<br /> | ||
* **copysignf**(x: `f32`, y: `f32`): `f32`<br /> | ||
Composes a 32-bit float from the magnitude of `x` and the sign of `y`. | ||
* **reinterpreti**(value: `float`): `int`<br /> | ||
* **reinterpreti**(value: `f32`): `i32`<br /> | ||
Reinterprets the bits of a 32-bit float as a 32-bit integer. | ||
* **reinterpretl**(value: `double`): `long`<br /> | ||
* **reinterpretl**(value: `f64`): `i64`<br /> | ||
Reinterprets the bits of a 64-bit float as a 64-bit integer. | ||
* **reinterpretf**(value: `int`): `float`<br /> | ||
* **reinterpretf**(value: `i32`): `f32`<br /> | ||
Reinterprets the bits of a 32-bit integer as a 32-bit float. | ||
* **reinterpretd**(value: `long`): `double`<br /> | ||
* **reinterpretd**(value: `i64`): `f64`<br /> | ||
Reinterprets the bits of a 64-bit integer as a 64-bit double. | ||
* **current_memory**(): `int`<br /> | ||
* **current_memory**(): `i32`<br /> | ||
Returns the current memory size in units of pages. One page is 64kb. | ||
* **grow_memory**(value: `uint`): `int`<br /> | ||
* **grow_memory**(value: `i32`): `i32`<br /> | ||
Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. | ||
* **unreachable**(): `void`<br /> | ||
Emits an unreachable operation that results in a runtime error when executed. | ||
* **load**<`T`>(offset: `usize`): `T`<br /> | ||
Loads a value of the specified type from memory. | ||
* **store**<`T`>(offset: `usize`, value: `T`): `void`<br /> | ||
Stores a value of the specified type to memory. | ||
The following AssemblyScript-specific operations are implemented as built-ins as well: | ||
* **sizeof**<`T`>(): `uintptr`<br /> | ||
* **sizeof**<`T`>(): `usize`<br /> | ||
Determines the byte size of the specified core or class type. Compiles to a constant. | ||
* **unsafe_cast**<`T1`,`T2`>(value: `T1`): `T2`<br /> | ||
Casts a value of type `T1` to a value of type `T2`. Useful for casting classes to pointers and vice-versa. Does not perform any checks. | ||
* **isNaN**(value: `double`): `bool`<br /> | ||
* **isNaN**(value: `f64`): `bool`<br /> | ||
Tests if a 64-bit float is a NaN. | ||
* **isNaNf**(value: `float`): `bool`<br /> | ||
* **isNaNf**(value: `f32`): `bool`<br /> | ||
Tests if a 32-bit float is a NaN. | ||
* **isFinite**(value: `double`): `bool`<br /> | ||
* **isFinite**(value: `f64`): `bool`<br /> | ||
Tests if a 64-bit float is finite. | ||
* **isFinitef**(value: `float`): `bool`<br /> | ||
* **isFinitef**(value: `f32`): `bool`<br /> | ||
Tests if a 32-bit float is finite. | ||
@@ -259,31 +263,33 @@ | ||
* **NaN**: `double`<br /> | ||
* **NaN**: `f64`<br /> | ||
NaN (not a number) as a 64-bit float. | ||
* **NaNf**: `float`<br /> | ||
* **NaNf**: `f32`<br /> | ||
NaN (not a number) as a 32-bit float. | ||
* **Infinity**: `double`<br /> | ||
* **Infinity**: `f64`<br /> | ||
Positive infinity as a 64-bit float. | ||
* **Infinityf**: `float`<br /> | ||
* **Infinityf**: `f32`<br /> | ||
Positive infinity as a 32-bit float. | ||
By default, standard memory management routines based on [dlmalloc](http://g.oswego.edu/dl/html/malloc.html) and [musl](http://www.musl-libc.org/) will be linked statically and can be configured to be exported to the embedder: | ||
By default, [AssemblyScript's memory management runtime](https://github.com/AssemblyScript/runtime) will be linked statically: | ||
* **malloc**(size: `uintptr`): `uintptr`<br /> | ||
Allocates a chunk of memory of the specified size and returns a pointer to it. | ||
* **free**(ptr: `uintptr`): `void`<br /> | ||
Frees a previously allocated chunk of memory by its pointer. | ||
* **memcpy**(dest: `uintptr`, src: `uintptr`, size: `uintptr`): `uintptr`<br /> | ||
* **memcpy**(dest: `usize`, src: `usize`, size: `usize`): `usize`<br /> | ||
Copies data from one chunk of memory to another. | ||
* **memset**(dest: `uintptr`, c: `int`, size: `uintptr`): `uintptr`<br /> | ||
* **memset**(dest: `usize`, c: `i32`, size: `usize`): `usize`<br /> | ||
Sets a chunk of memory to the provided value `c`. Usually used to reset it to all `0`s. | ||
* **memcmp**(vl: `uintptr`, vr: `uintptr`, n: `uintptr`): `int`<br /> | ||
* **memcmp**(vl: `usize`, vr: `usize`, n: `usize`): `i32`<br /> | ||
Compares a chunk of memory to another. Returns `0` if both are equal, otherwise `vl[i] - vr[i]` at the first difference's byte offset `i`. | ||
* **malloc**(size: `usize`): `usize`<br /> | ||
Allocates a chunk of memory of the specified size. | ||
* **realloc**(ptr: `usize`, size: `usize`): `usize`<br /> | ||
Changes the size of an allocated memory block. | ||
* **free**(ptr: `usize`): `void`<br /> | ||
Frees a previously allocated chunk of memory. | ||
Linking in memory management routines adds about 11kb to a module. Once WebAssembly exposes the garbage collector natively, there'll be other options as well. Note that the `new` operator depends on `malloc` and will break when `--no-malloc` is specified (and no other `malloc` is present). Also note that calling `grow_memory` where `malloc` is present will most likely break `malloc` as it expects contiguous memory. | ||
Linking in the runtime adds up to 14kb to a module, but the optimizer is able to eliminate unused runtime code. Once WebAssembly exposes the garbage collector natively, there'll be other options as well. If the runtime has been excluded through `--noRuntime`, its methods will be imported where referenced (i.e. when using `new`). Also note that manually calling `grow_memory` where the runtime is present will most likely break it. | ||
Type coercion requires an explicit cast where precision or signage is lost respectively is implicit where it is maintained. For example, to cast a `double` to an `int`: | ||
Type coercion requires an explicit cast where precision or signage is lost respectively is implicit where it is maintained. For example, to cast a `f64` to an `i32`: | ||
```ts | ||
function example(value: double): int { | ||
return value as int; // translates to the respective opcode | ||
function example(value: f64): i32 { | ||
return value as i32; // translates to the respective opcode | ||
} | ||
@@ -312,10 +318,2 @@ ``` | ||
Naming a function `start` with no arguments and a `void` return type will automatically make it the start function that is being called on load even before returning to the embedder. | ||
```ts | ||
function start(): void { | ||
... | ||
} | ||
``` | ||
Command line | ||
@@ -335,3 +333,3 @@ ------------ | ||
--outFile, -o Specifies the output file name. Emits text format if ending with .wast | ||
(sexpr) or .wat (linear). Prints to stdout if omitted. | ||
(sexpr), .wat (linear) or .js (asmjs). Prints to stdout if omitted. | ||
@@ -349,9 +347,2 @@ --optimize, -O Runs optimizing binaryen IR passes. | ||
--memoryModel, -m Specifies the memory model to use / how to proceed with malloc etc.: | ||
malloc Bundles malloc etc. [default] | ||
exportmalloc Bundles malloc etc. and exports each | ||
importmalloc Imports malloc etc. from 'env' | ||
bare Excludes malloc etc. entirely | ||
--textFormat, -f Specifies the format to use for text output: | ||
@@ -361,2 +352,3 @@ | ||
linear Emits official linear syntax (.wat) | ||
asmjs Emits just asm.js (.js) - experimental | ||
@@ -367,2 +359,12 @@ Text format only is emitted when used without --textFile. | ||
--asmjsFile Can be used to save asm.js alongside a binary in one command. - experimental | ||
--noTreeShaking Whether to disable built-in tree-shaking. | ||
--noImplicitConversion Whether to disallow implicit type conversions. | ||
--noRuntime Whether to exclude the runtime. | ||
--exportRuntime, -e Runtime functions to export, defaults to 'malloc' and 'free'. [multiple] | ||
--help, -h Displays this help message. | ||
@@ -392,8 +394,12 @@ ``` | ||
Whether compilation shall be performed in silent mode without writing to console. Defaults to `false`. | ||
* **treeShaking**: `boolean`<br /> | ||
Whether to use built-in tree-shaking. Defaults to `true`. Disable this when building a dynamically linked library. | ||
* **target**: `CompilerTarget | string`<br /> | ||
Specifies the target architecture. Defaults to `CompilerTarget.WASM32`. | ||
* **memoryModel**: `CompilerMemoryModel | string`<br /> | ||
Specifies the memory model to use. Defaults to `CompilerMemoryModel.MALLOC`. | ||
* **noTreeShaking**: `boolean`<br /> | ||
Whether to disable built-in tree-shaking. Defaults to `false`. | ||
* **noImplicitConversion**: `boolean`<br /> | ||
Whether to disallow implicit type conversions. Defaults to `false`. | ||
* **noRuntime**: `boolean`<br /> | ||
Whether to exclude the runtime. | ||
* **exportRuntime**: `string[]`<br /> | ||
Runtime functions to export, defaults to 'malloc' and 'free'. | ||
@@ -404,18 +410,6 @@ * **CompilerTarget**<br /> | ||
* **WASM32**<br /> | ||
32-bit WebAssembly target using uint pointers. | ||
32-bit WebAssembly target using 32-bit (`usize := u32`) pointers. | ||
* **WASM64**<br /> | ||
64-bit WebAssembly target using ulong pointers. | ||
64-bit WebAssembly target using 64-bit (`usize := u64`) pointers. Not yet supported by most runtimes. | ||
* **CompilerMemoryModel**<br /> | ||
Compiler memory model. | ||
* **BARE**<br /> | ||
Does not bundle any memory management routines. | ||
* **MALLOC**<br /> | ||
Bundles malloc, free, etc. | ||
* **EXPORT_MALLOC**<br /> | ||
Bundles malloc, free, etc. and exports each to the embedder. | ||
* **IMPORT_MALLOC**<br /> | ||
Imports malloc, free, etc. as provided by the embedder. | ||
### Example | ||
@@ -427,3 +421,3 @@ | ||
const module = Compiler.compileString(` | ||
export function add(a: int, b: int): int { | ||
export function add(a: i32, b: i32): i32 { | ||
return a + b; | ||
@@ -433,3 +427,2 @@ } | ||
target: CompilerTarget.WASM32, | ||
memoryModel: CompilerMemoryModel.MALLOC, | ||
silent: true | ||
@@ -462,4 +455,4 @@ }); | ||
* [Standard Library Documentation](http://dcode.io/AssemblyScript/std) | ||
* [API Documentation](http://dcode.io/AssemblyScript/api) | ||
* [Standard Library Documentation](http://assemblyscript.org/docs/std) | ||
* [API Documentation](http://assemblyscript.org/docs/api) | ||
@@ -473,11 +466,11 @@ #### WebAssembly | ||
Clone the GitHub repository and install the development dependencies: | ||
Clone the GitHub repository including submodules and install the development dependencies: | ||
``` | ||
$> git clone https://github.com/dcodeIO/AssemblyScript.git | ||
$> cd AssemblyScript | ||
$> git clone --recursive https://github.com/AssemblyScript/assemblyscript.git | ||
$> cd assemblyscript | ||
$> npm install | ||
``` | ||
Afterwards, to build the distribution files to [dist/](./dist), run: | ||
Afterwards, to build the distribution files to *dist/*, run: | ||
@@ -488,12 +481,14 @@ ``` | ||
To build the documentation to [docs/api/](./docs/api), run: | ||
**Note** that the first invocation of `build` also builds the TypeScript submodule (lib/typescript) and may take some time. | ||
To run the [tests](./tests) (ideally on node.js >= 8): | ||
``` | ||
$> npm run docs | ||
$> npm test | ||
``` | ||
Running the [tests](./tests) (ideally on node.js >= 8): | ||
To build the documentation to the [website repostory](https://github.com/AssemblyScript/website) checked out next to this repository, run: | ||
``` | ||
$> npm test | ||
$> npm run docs | ||
``` | ||
@@ -500,0 +495,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
6552449
27
6959
0
480
+ Addedbinaryen@37.0.0-nightly.20170909(transitive)
- Removedbinaryen@1.37.16-nightly.20170719(transitive)
Updatedchalk@^2.1.0