assemblyscript-loader
Advanced tools
Comparing version 0.2.0 to 0.3.0
133
index.d.ts
/// <reference types="webassembly-js-api" /> | ||
import * as Long from "long"; | ||
/** Options to set up the environment created by {@link load}. */ | ||
export interface ILoadOptions { | ||
/** Memory instance to import, if applicable. */ | ||
memory?: WebAssembly.Memory; | ||
/** Imported elements. Usually functions. */ | ||
imports?: { [key: string]: any } | ||
} | ||
/** Number memory accessor. */ | ||
export interface INumberMemoryAccessor { | ||
/** Gets a value of the underlying type from memory at the specified pointer. */ | ||
get(ptr: number): number; | ||
/** Sets a value of the underlying type in memory at the specified pointer. */ | ||
set(ptr: number, value: number): void; | ||
} | ||
/** Long memory accessor. */ | ||
export interface ILongMemoryAccessor { | ||
/** Gets a Long from memory at the specified pointer. */ | ||
get(ptr: number): Long; | ||
/** Sets a Long in memory at the specified pointer. */ | ||
set(ptr: number, value: Long): void; | ||
} | ||
/** Array memory accessor. */ | ||
export interface IArrayMemoryAccessor { | ||
/** Gets an array from memory at the specified pointer and returns its capacity, length and element base pointer. */ | ||
get(ptr: number): { capacity: number, length: number, base: number }; | ||
/** Creates an array in memory and returns its pointer and element base pointer. */ | ||
create(length: number, elementByteSize: number): { ptr: number, base: number }; | ||
} | ||
/** String memory accessor. */ | ||
export interface IStringMemoryAccessor { | ||
/** Gets a string from memory at the specified pointer. */ | ||
get(ptr: number): string; | ||
/** Creates a string in memory and returns its pointer. */ | ||
create(value: string): number; | ||
} | ||
/** Log message type. */ | ||
export enum LogType { | ||
LOG = 0, | ||
INFO = 1, | ||
WARN = 2, | ||
ERROR = 3 | ||
} | ||
/** Common module interface as returned by {@link load}. */ | ||
export interface IModule { | ||
/** A reference to the underlying memory instance. */ | ||
memory: WebAssembly.Memory; | ||
/** An unsigned byte view on the underlying memory. Note that this view is updated when memory grows, hence make sure to always access it on the module instance directly. */ | ||
buffer: Uint8Array; | ||
/** Imported elements. Usually functions. */ | ||
imports: { [key: string]: any }; | ||
/** Exported elements. Usually functions. */ | ||
exports: { [key: string]: any }; | ||
/** Gets the current size of the memory in 64kb pages. */ | ||
currentMemory(): number; | ||
/** Grows the memory by the specified number of 64kb pages. */ | ||
growMemory(numPages: number): number; | ||
/** An overridable function called for each log message. */ | ||
log(type: LogType, message: string): void; | ||
/** Signed 8-bit integer accessors. */ | ||
sbyte: INumberMemoryAccessor; | ||
/** Signed 8-bit integer accessors. Alias of `sbyte`. */ | ||
s8: INumberMemoryAccessor; | ||
/** Unsigned 8-bit integer accessors. */ | ||
byte: INumberMemoryAccessor; | ||
/** Unsigned 8-bit integer accessors. Alias of `byte`. */ | ||
u8: INumberMemoryAccessor; | ||
/** Signed 16-bit integer accessors. */ | ||
short: INumberMemoryAccessor; | ||
/** Signed 16-bit integer value accessors. Alias of `short`. */ | ||
s16: INumberMemoryAccessor; | ||
/** Unsigned 16-bit integer accessors. */ | ||
ushort: INumberMemoryAccessor; | ||
/** Unsigned 16-bit integer accessors. Alias of `ushort`. */ | ||
u16: INumberMemoryAccessor; | ||
/** Signed 32-bit integer accessors. */ | ||
int: INumberMemoryAccessor; | ||
/** Signed 32-bit integer accessors. Alias of `int`. */ | ||
s32: INumberMemoryAccessor; | ||
/** Unsigned 32-bit integer accessors. */ | ||
uint: INumberMemoryAccessor; | ||
/** Unsigned 32-bit integer accessors. Alias of `uint`. */ | ||
u32: INumberMemoryAccessor; | ||
/** Signed 64-bit integer accessors. */ | ||
long: ILongMemoryAccessor; | ||
/** Signed 64-bit integer accessors. Alias of `long`. */ | ||
s64: ILongMemoryAccessor; | ||
/** Unsigned 64-bit integer accessors. */ | ||
ulong: ILongMemoryAccessor; | ||
/** Unsigned 64-bit integer accessors. Alias of `ulong`. */ | ||
u64: ILongMemoryAccessor; | ||
/** 32-bit float accessors. */ | ||
float: INumberMemoryAccessor; | ||
/** 32-bit float accessors. Alias of `float`. */ | ||
f32: INumberMemoryAccessor; | ||
/** 64-bit float accessors. */ | ||
double: INumberMemoryAccessor; | ||
/** 64-bit float accessors. Alias of `double`. */ | ||
f64: INumberMemoryAccessor; | ||
/** Array accessors. */ | ||
array: IArrayMemoryAccessor; | ||
/** String accessors. */ | ||
string: IStringMemoryAccessor; | ||
} | ||
/** Loads a WebAssembly module either from a buffer or from a file and returns a promise for an {@link IModule}. */ | ||
export function load(file: ArrayBuffer | Uint8Array | string, options?: ILoadOptions): Promise<IModule>; | ||
export { load as default }; | ||
/// <reference path="./dist/assemblyscript-loader.d.ts" /> | ||
export * from "assemblyscript-loader"; |
311
index.js
@@ -1,310 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
module.exports = load; | ||
var Long; try { Long = require("long"); } catch (e) { /**/ } | ||
if (typeof Long !== "function") Long = undefined; // might have been excluded | ||
var arrayHeaderSize = 8; // capacity and length | ||
load.LogType = { LOG: 0, INFO: 1, WARN: 2, ERROR: 3 }; | ||
load.load = load.default = load; | ||
function load(file, options) { | ||
if (!options) options = {}; | ||
var imports = options.imports || {}; | ||
if (options.memory) | ||
imports.memory = options.memory; | ||
if (!imports.env) | ||
imports.env = {}; | ||
var buffer; | ||
if (!imports.env.log) | ||
imports.env.log = function log(type, message) { | ||
return module.log(type, module.string.get(message)); | ||
} | ||
var module = { | ||
memory: options.memory || null, | ||
imports: imports, | ||
exports: {}, | ||
currentMemory: function currentMemory() { | ||
return this.memory.buffer.byteLength >>> 16; | ||
}, | ||
growMemory: function growMemory(additionalPages) { | ||
var previousPages = this.memory.grow(additionalPages); | ||
onGrowMemory(); | ||
return previousPages; | ||
}, | ||
log: function log(type, message) { | ||
switch (type) { | ||
case 1: type = "info"; break; | ||
case 2: type = "warn"; break; | ||
case 3: type = "error"; break; | ||
default: type = "log"; | ||
} | ||
console[type](message); | ||
} | ||
}; | ||
module.byte = module.u8 = { | ||
get: function get_byte(ptr) { | ||
return buffer[ptr]; | ||
}, | ||
set: function set_byte(ptr, value) { | ||
buffer[ptr] = value; | ||
} | ||
}; | ||
module.sbyte = module.s8 = { | ||
get: function get_sbyte(ptr) { | ||
return buffer[ptr] << 24 >> 24; | ||
}, | ||
set: function set_sbyte(ptr, value) { | ||
buffer[ptr] = value; | ||
} | ||
}; | ||
module.short = module.s16 = { | ||
get: function get_short(ptr) { | ||
return (buffer[ptr ] | ||
| buffer[ptr + 1] << 8) << 16 >> 16; | ||
}, | ||
set: function set_short(ptr, value) { | ||
buffer[ptr ] = value & 255; | ||
buffer[ptr + 1] = value >>> 8 & 255; | ||
} | ||
}; | ||
module.ushort = module.u16 = { | ||
get: function get_ushort(ptr) { | ||
return buffer[ptr ] | ||
| buffer[ptr + 1] << 8; | ||
}, | ||
set: function set_ushort(ptr, value) { | ||
buffer[ptr ] = value & 255; | ||
buffer[ptr + 1] = value >>> 8 & 255; | ||
} | ||
}; | ||
module.int = module.s32 = { | ||
get: function get_int(ptr) { | ||
return buffer[ptr ] | ||
| buffer[ptr + 1] << 8 | ||
| buffer[ptr + 2] << 16 | ||
| buffer[ptr + 3] << 24; | ||
}, | ||
set: function set_int(ptr, value) { | ||
buffer[ptr ] = value & 255; | ||
buffer[ptr + 1] = value >>> 8 & 255; | ||
buffer[ptr + 2] = value >>> 16 & 255; | ||
buffer[ptr + 3] = value >>> 24; | ||
} | ||
}; | ||
module.uint = module.u32 = { | ||
get: function get_uint(ptr) { | ||
return (buffer[ptr ] | ||
| buffer[ptr + 1] << 8 | ||
| buffer[ptr + 2] << 16 | ||
| buffer[ptr + 3] << 24) >>> 0; | ||
}, | ||
set: function set_uint(ptr, value) { | ||
buffer[ptr ] = value & 255; | ||
buffer[ptr + 1] = value >>> 8 & 255; | ||
buffer[ptr + 2] = value >>> 16 & 255; | ||
buffer[ptr + 3] = value >>> 24; | ||
} | ||
}; | ||
function get_long_s(ptr, unsigned) { | ||
var lo = buffer[ptr ] | ||
| buffer[ptr + 1] << 8 | ||
| buffer[ptr + 2] << 16 | ||
| buffer[ptr + 3] << 24; | ||
var hi = buffer[ptr + 4] | ||
| buffer[ptr + 5] << 8 | ||
| buffer[ptr + 6] << 16 | ||
| buffer[ptr + 7] << 24; | ||
return Long | ||
? Long.fromBits(lo, hi, !!unsigned) | ||
: { low: lo, high: hi, unsigned: !!unsigned }; | ||
} | ||
function set_long_s(ptr, value) { | ||
buffer[ptr ] = value.low & 255; | ||
buffer[ptr + 1] = value.low >>> 8 & 255; | ||
buffer[ptr + 2] = value.low >>> 16 & 255; | ||
buffer[ptr + 3] = value.low >>> 24; | ||
buffer[ptr + 4] = value.high & 255; | ||
buffer[ptr + 5] = value.high >>> 8 & 255; | ||
buffer[ptr + 6] = value.high >>> 16 & 255; | ||
buffer[ptr + 7] = value.high >>> 24; | ||
} | ||
module.long = module.s64 = { | ||
get: function get_long(ptr) { return get_long_s(ptr, false); }, | ||
set: set_long_s | ||
}; | ||
module.ulong = module.u64 = { | ||
get: function get_ulong(ptr) { return get_long_s(ptr, true); }, | ||
set: set_long_s | ||
}; | ||
var f64 = new Float64Array([ -0 ]); | ||
var f32 = new Float32Array(f64.buffer); | ||
var f8b = new Uint8Array(f64.buffer); | ||
var fle = f8b[7] === 128; | ||
module.float = module.f32 = { | ||
get: function get_float(ptr) { | ||
if (fle) { | ||
f8b[0] = buffer[ptr ]; | ||
f8b[1] = buffer[ptr + 1]; | ||
f8b[2] = buffer[ptr + 2]; | ||
f8b[3] = buffer[ptr + 3]; | ||
} else { | ||
f8b[3] = buffer[ptr ]; | ||
f8b[2] = buffer[ptr + 1]; | ||
f8b[1] = buffer[ptr + 2]; | ||
f8b[0] = buffer[ptr + 3]; | ||
} | ||
return f32[0]; | ||
}, | ||
set: function set_float(ptr, value) { | ||
f32[0] = value; | ||
if (fle) { | ||
buffer[ptr ] = f8b[0]; | ||
buffer[ptr + 1] = f8b[1]; | ||
buffer[ptr + 2] = f8b[2]; | ||
buffer[ptr + 3] = f8b[3]; | ||
} else { | ||
buffer[ptr ] = f8b[3]; | ||
buffer[ptr + 1] = f8b[2]; | ||
buffer[ptr + 2] = f8b[1]; | ||
buffer[ptr + 3] = f8b[0]; | ||
} | ||
} | ||
}; | ||
module.double = module.f64 = { | ||
get: function get_double(ptr) { | ||
if (fle) { | ||
f8b[0] = buffer[ptr ]; | ||
f8b[1] = buffer[ptr + 1]; | ||
f8b[2] = buffer[ptr + 2]; | ||
f8b[3] = buffer[ptr + 3]; | ||
f8b[4] = buffer[ptr + 4]; | ||
f8b[5] = buffer[ptr + 5]; | ||
f8b[6] = buffer[ptr + 6]; | ||
f8b[7] = buffer[ptr + 7]; | ||
} else { | ||
f8b[7] = buffer[ptr ]; | ||
f8b[6] = buffer[ptr + 1]; | ||
f8b[5] = buffer[ptr + 2]; | ||
f8b[4] = buffer[ptr + 3]; | ||
f8b[3] = buffer[ptr + 4]; | ||
f8b[2] = buffer[ptr + 5]; | ||
f8b[1] = buffer[ptr + 6]; | ||
f8b[0] = buffer[ptr + 7]; | ||
} | ||
return f64[0]; | ||
}, | ||
set: function set_double(ptr, value) { | ||
f64[0] = value; | ||
if (fle) { | ||
buffer[ptr ] = f8b[0]; | ||
buffer[ptr + 1] = f8b[1]; | ||
buffer[ptr + 2] = f8b[2]; | ||
buffer[ptr + 3] = f8b[3]; | ||
buffer[ptr + 4] = f8b[4]; | ||
buffer[ptr + 5] = f8b[5]; | ||
buffer[ptr + 6] = f8b[6]; | ||
buffer[ptr + 7] = f8b[7]; | ||
} else { | ||
buffer[ptr ] = f8b[7]; | ||
buffer[ptr + 1] = f8b[6]; | ||
buffer[ptr + 2] = f8b[5]; | ||
buffer[ptr + 3] = f8b[4]; | ||
buffer[ptr + 4] = f8b[3]; | ||
buffer[ptr + 5] = f8b[2]; | ||
buffer[ptr + 6] = f8b[1]; | ||
buffer[ptr + 7] = f8b[0]; | ||
} | ||
} | ||
}; | ||
module.array = { | ||
get: function(ptr) { | ||
var capacity = module.int.get(ptr); | ||
var length = module.int.get(ptr + 4); | ||
return { | ||
capacity: capacity, | ||
length: length, | ||
base: ptr + arrayHeaderSize | ||
}; | ||
}, | ||
create: function(length, elementByteSize) { | ||
var ptr = (module.exports.malloc || imports.env.malloc)(arrayHeaderSize + length * elementByteSize); | ||
module.int.set(ptr, length); // capacity | ||
module.int.set(ptr + 4, length); // length | ||
return { | ||
ptr: ptr, | ||
base: ptr + arrayHeaderSize | ||
}; | ||
} | ||
}; | ||
module.string = { | ||
get: function(ptr) { | ||
var capacity = module.int.get(ptr); | ||
var length = module.int.get(ptr + 4); | ||
var chars = new Array(length); | ||
for (var i = 0, base = arrayHeaderSize + ptr; i < length; ++i) | ||
chars[i] = module.ushort.get(base + (i << 1)); | ||
return String.fromCharCode.apply(String, chars); // TODO: chunking | ||
}, | ||
create: function(value) { | ||
var ptr = (module.exports.malloc || imports.env.malloc)(arrayHeaderSize + (value.length << 1)); | ||
module.int.set(ptr, value.length); // capacity | ||
module.int.set(ptr + 4, value.length); // length | ||
for (var i = 0, base = arrayHeaderSize + ptr; i < value.length; ++i) | ||
module.ushort.set(base + (i << 1), value.charCodeAt(i)); | ||
return ptr; | ||
} | ||
}; | ||
function onGrowMemory() { | ||
buffer = module.buffer = new Uint8Array(module.memory.buffer); | ||
} | ||
imports.onGrowMemory = onGrowMemory; | ||
return (typeof file === "string" | ||
? (typeof fetch === "function" && fetch || fetch_node)(file) | ||
.then(function(result) { return result.arrayBuffer(); }) | ||
.then(function(buffer) { return WebAssembly.instantiate(buffer, imports); }) | ||
: WebAssembly.instantiate(file, imports) | ||
) | ||
.then(function(result) { | ||
module.exports = result.instance.exports; | ||
if (module.exports.memory) | ||
module.memory = module.exports.memory; | ||
onGrowMemory(); | ||
return module; | ||
}); | ||
} | ||
var fs; | ||
function fetch_node(file) { | ||
return new Promise(function(resolve, reject) { | ||
(fs || (fs = eval("equire".replace(/^/, "r"))("fs"))) | ||
.readFile(file, function(err, data) { | ||
return err | ||
? reject(err) | ||
: resolve({ arrayBuffer: function() { return data; } }); | ||
}) | ||
}); | ||
} | ||
module.exports = require("./dist/assemblyscript-loader"); |
{ | ||
"name": "assemblyscript-loader", | ||
"description": "AssemblyScript's loader component as a stand-alone module.", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -9,7 +9,8 @@ "license": "Apache-2.0", | ||
"type": "git", | ||
"url": "https://github.com/dcodeIO/AssemblyScript.git" | ||
"url": "https://github.com/AssemblyScript/loader.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dcodeIO/AssemblyScript/issues" | ||
"url": "https://github.com/AssemblyScript/loader/issues" | ||
}, | ||
"homepage": "http://assemblyscript.org", | ||
"keywords": [ | ||
@@ -24,13 +25,38 @@ "webassembly", | ||
"files": [ | ||
"dist/assemblyscript-loader.d.ts", | ||
"dist/assemblyscript-loader.js", | ||
"dist/assemblyscript-loader.js.map", | ||
"index.js", | ||
"index.d.ts", | ||
"package.json", | ||
"package-lock.json", | ||
"index.js", | ||
"index.d.ts", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build:compile": "tsc -P src", | ||
"build:bundle": "node scripts/build-bundle", | ||
"build": "npm run build:compile && npm run build:bundle", | ||
"test": "ts-node tests" | ||
}, | ||
"dependencies": { | ||
"@types/long": "^3.0.31", | ||
"@types/long": "^3.0.32", | ||
"@types/webassembly-js-api": "0.0.1", | ||
"long": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.24", | ||
"@types/tape": "^4.2.30", | ||
"browserify": "^14.4.0", | ||
"dts-bundle": "^0.7.3", | ||
"gulp-header": "^1.8.9", | ||
"gulp-sourcemaps": "^2.6.1", | ||
"gulp-uglify": "^3.0.0", | ||
"rimraf": "^2.6.1", | ||
"tape": "^4.8.0", | ||
"ts-node": "^3.3.0", | ||
"vinyl-buffer": "^1.0.0", | ||
"vinyl-fs": "^2.4.4", | ||
"vinyl-source-stream": "^1.1.0", | ||
"typescript": "^2.5.1" | ||
} | ||
} |
134
README.md
AssemblyScript Loader | ||
===================== | ||
[AssemblyScript](https://github.com/dcodeIO/AssemblyScript)'s loader component to run and work with compiled WebAssembly modules, as a stand-alone module. | ||
[AssemblyScript](http://assemblyscript.org)'s loader component to run and work with compiled WebAssembly modules, as a stand-alone module. | ||
[![npm](https://img.shields.io/npm/v/assemblyscript-loader.svg)](https://www.npmjs.com/package/assemblyscript-loader) | ||
[![npm](https://img.shields.io/npm/v/assemblyscript-loader.svg)](https://www.npmjs.com/package/assemblyscript-loader) [![Build Status](https://travis-ci.org/AssemblyScript/loader.svg?branch=master)](https://travis-ci.org/AssemblyScript/loader) | ||
@@ -18,3 +18,3 @@ Usage | ||
load("path/to/module.wasm", { | ||
load("path/to/myModule.wasm", { | ||
imports: { | ||
@@ -29,10 +29,25 @@ ... | ||
Alternatively, when `LoadOptions#exports` is specified, the respective object is pre-initialized | ||
with the (always present) `ready` promise that is resolved when loading is complete: | ||
```js | ||
// myModule.js (CommonJS) | ||
require("assemblyscript-loader").load("path/to/myModule.wasm", { exports: module.exports }); | ||
``` | ||
```js | ||
// otherModule.js (CommonJS) | ||
var myModule = require("./myModule.js"); | ||
myModule.ready.then(() => { | ||
... | ||
}); | ||
``` | ||
API | ||
--- | ||
* **load**(file: `ArrayBuffer | Uint8Array | string`, options: `ILoadOptions`): `Promise<IModule>`<br /> | ||
Loads a WebAssembly module either from a buffer or from a file and returns a promise for an | ||
`IModule`. | ||
* **load**(file: `string | Uint8Array | ArrayBuffer`, options: `LoadOptions`): `Promise<Module>`<br /> | ||
Loads a WebAssembly module either from a file or a buffer and returns a promise for the loaded `Module`. | ||
* **ILoadOptions**<br /> | ||
* **LoadOptions**<br /> | ||
Options to set up the environment created by `load`. | ||
@@ -44,48 +59,63 @@ | ||
Import elements. Usually functions. | ||
* **exports**: `{ [key: string]: any }`<br /> | ||
Object to populate with exports. Creates a new object if omitted. | ||
* **IModule**<br /> | ||
* **Module**<br /> | ||
Common module interface as returned by `load`. | ||
* **memory**: `WebAssembly.Memory`<br /> | ||
A reference to the underlying memory instance | ||
* **buffer**: `Uint8Array`<br /> | ||
An unsigned byte view on the underlying memory. Note that this view is updated when memory | ||
grows, hence make sure to always access it on the module instance directly. | ||
* **imports**: `{ [key: string]: any }`<br /> | ||
* **imports**: `Imports`<br /> | ||
Imported elements. Usually functions. | ||
* **exports**: `{ [key: string]: any }`<br /> | ||
* **exports**: `Exports`<br /> | ||
Exported elements. Usually functions. | ||
* **currentMemory**(): `number`<br /> | ||
Gets the current size of the memory in 64kb pages. | ||
* **growMemory**(numPages: `number`): `number`<br /> | ||
Grows the memory by the specified number of 64kb pages. | ||
* **memory**: `Memory`<br /> | ||
A reference to the underlying memory instance. | ||
* **log**(type: `LogType`, message: `string`): `void`<br /> | ||
An overridable method receiving console outputs. | ||
Accessors provided for typed memory access: | ||
* **Imports**<br /> | ||
An object of imported functions. | ||
* **sbyte** / **s8**: `INumberMemoryAccessor`<br /> | ||
* **Exports**<br /> | ||
An object of exported functions (plus the `ready` promise). | ||
* **LogType**<br /> | ||
An enum of log types: | ||
Key | Value | ||
------|------- | ||
LOG | 0 | ||
INFO | 1 | ||
WARN | 2 | ||
ERROR | 3 | ||
* **Memory** extends *WebAssembly.Memory*<br /> | ||
The [WebAssembly Memory](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) | ||
instance populated with additional accessors for more convenient memory access. | ||
* **sbyte** / **s8**: `NumberAccessor`<br /> | ||
Signed 8-bit integer accessors. | ||
* **byte** / **u8**: `INumberMemoryAccessor`<br /> | ||
* **byte** / **u8**: `NumberAccessor`<br /> | ||
Unsigned 8-bit integer accessors. | ||
* **short** / **s16**: `INumberMemoryAccessor`<br /> | ||
* **short** / **s16**: `NumberAccessor`<br /> | ||
Signed 16-bit integer accessors. | ||
* **ushort** / **u16**: `INumberMemoryAccessor`<br /> | ||
* **ushort** / **u16**: `NumberAccessor`<br /> | ||
Unsigned 16-bit integer accessors. | ||
* **int** / **s32**: `INumberMemoryAccessor`<br /> | ||
* **int** / **s32**: `NumberAccessor`<br /> | ||
Signed 32-bit integer accessors. | ||
* **uint** / **u32**: `INumberMemoryAccessor`<br /> | ||
* **uint** / **u32**: `NumberAccessor`<br /> | ||
Unsigned 32-bit integer accessors. | ||
* **long** / **s64**: `ILongMemoryAccessor`<br /> | ||
* **long** / **s64**: `LongAccessor`<br /> | ||
Signed 64-bit integer accessors. | ||
* **ulong** / **u64**: `ILongMemoryAccessor`<br /> | ||
* **ulong** / **u64**: `LongAccessor`<br /> | ||
Unsigned 64-bit integer accessors. | ||
* **float** / **f32**: `INumberMemoryAccessor`<br /> | ||
* **float** / **f32**: `NumberAccessor`<br /> | ||
32-bit float accessors. | ||
* **double** / **f64**: `INumberMemoryAccessor`<br /> | ||
* **double** / **f64**: `NumberAccessor`<br /> | ||
64-bit float accessors. | ||
* **array**: `IArrayMemoryAccessor`<br /> | ||
* **array**: `ArrayAccessor`<br /> | ||
Array accessors. | ||
* **string**: `IStringMemoryAccessor`<br /> | ||
* **string**: `StringAccessor`<br /> | ||
String accessors. | ||
* **INumberMemoryAccessor**<br /> | ||
* **NumberAccessor**<br /> | ||
Number memory accessor. | ||
@@ -98,3 +128,3 @@ | ||
* **ILongMemoryAccessor**<br /> | ||
* **LongAccessor**<br /> | ||
Long memory accessor. See also: [long.js](https://github.com/dcodeIO/long.js) | ||
@@ -107,3 +137,3 @@ | ||
* **IArrayMemoryAccessor**<br /> | ||
* **ArrayAccessor**<br /> | ||
Array memory accessor. | ||
@@ -117,3 +147,3 @@ | ||
* **IStringMemoryAccessor**<br /> | ||
* **StringAccessor**<br /> | ||
String memory accessor. | ||
@@ -126,6 +156,13 @@ | ||
* **initializeMemory**(memoryInstance: `WebAssembly.Memory`, malloc: `Function`, memset: `Function`): `Memory`<br /> | ||
Just populates a WebAssembly Memory instance with the AssemblyScript-typical accessors. | ||
* **xfetch**(file: `string`): `Promise<Response>`<br /> | ||
Underlying [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) | ||
implementation that also works under node.js. | ||
**Note** that the `create` methods of array and string accessors require an exported or imported | ||
implementation of `malloc`, `free` etc. to be present. Also remember that memory is unmanaged here | ||
and that `free` must be called manually to clean up memory, just like in C. Once WebAssembly | ||
exposes the garbage collector natively, there will be other options as well. | ||
implementation of `malloc`, `memset`, `free` etc. to be present. Also remember that memory is | ||
unmanaged here and that `free` must be called manually to clean up memory, just like in C. Once | ||
WebAssembly exposes the garbage collector natively, there will be other options as well. | ||
@@ -135,2 +172,19 @@ The [long.js](https://github.com/dcodeIO/long.js) dependency can be safely excluded if working with | ||
Long-like objects having a `low` and a `high` property representing the respective low and high | ||
32-bits. | ||
32-bits. | ||
Building | ||
======== | ||
Clone the GitHub repository and install the development dependencies: | ||
``` | ||
$> git clone https://github.com/AssemblyScript/loader.git | ||
$> cd loader | ||
$> npm install | ||
``` | ||
Afterwards, to build the distribution files to *dist/*, run: | ||
``` | ||
$> npm run build | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
50142
8
183
14
115
2
4
Updated@types/long@^3.0.32