@assemblyscript/loader
Advanced tools
Comparing version 0.9.4-nightly.20200325 to 0.9.4-nightly.20200329
@@ -11,11 +11,11 @@ /// <reference lib="esnext.bigint" /> | ||
/** WebAssembly imports with two levels of nesting. */ | ||
export interface Imports extends Record<string, Record<string, ImportValue>> { | ||
export type Imports = { | ||
env?: { | ||
memory?: WebAssembly.Memory, | ||
table?: WebAssembly.Table, | ||
seed?: () => number, | ||
abort?(msg: number, file: number, line: number, column: number): void, | ||
trace?(msg: number, numArgs?: number, ...args: number[]): void | ||
}; | ||
} | ||
memory?: WebAssembly.Memory; | ||
table?: WebAssembly.Table; | ||
seed?(): number; | ||
abort?(msg: number, file: number, line: number, column: number): void; | ||
trace?(msg: number, numArgs?: number, ...args: number[]): void; | ||
} & Record<string, ImportValue>; | ||
} & Record<string, Record<string, ImportValue>>; | ||
@@ -22,0 +22,0 @@ /** Utility mixed in by the loader. */ |
100
index.js
@@ -15,16 +15,17 @@ "use strict"; | ||
const ARRAY = 1 << 1; | ||
const SET = 1 << 2; | ||
const MAP = 1 << 3; | ||
const VAL_ALIGN_OFFSET = 5; | ||
const STATICARRAY = 1 << 2; | ||
const SET = 1 << 3; | ||
const MAP = 1 << 4; | ||
const VAL_ALIGN_OFFSET = 6; | ||
const VAL_ALIGN = 1 << VAL_ALIGN_OFFSET; | ||
const VAL_SIGNED = 1 << 10; | ||
const VAL_FLOAT = 1 << 11; | ||
const VAL_NULLABLE = 1 << 12; | ||
const VAL_MANAGED = 1 << 13; | ||
const KEY_ALIGN_OFFSET = 14; | ||
const VAL_SIGNED = 1 << 11; | ||
const VAL_FLOAT = 1 << 12; | ||
const VAL_NULLABLE = 1 << 13; | ||
const VAL_MANAGED = 1 << 14; | ||
const KEY_ALIGN_OFFSET = 15; | ||
const KEY_ALIGN = 1 << KEY_ALIGN_OFFSET; | ||
const KEY_SIGNED = 1 << 19; | ||
const KEY_FLOAT = 1 << 20; | ||
const KEY_NULLABLE = 1 << 21; | ||
const KEY_MANAGED = 1 << 22; | ||
const KEY_SIGNED = 1 << 20; | ||
const KEY_FLOAT = 1 << 21; | ||
const KEY_NULLABLE = 1 << 22; | ||
const KEY_MANAGED = 1 << 23; | ||
@@ -166,12 +167,18 @@ // Array(BufferView) layout | ||
const info = getInfo(id); | ||
if (!(info & (ARRAYBUFFERVIEW | ARRAY))) throw Error("not an array: " + id + ", flags= " + info); | ||
if (!(info & (ARRAYBUFFERVIEW | ARRAY | STATICARRAY))) throw Error("not an array: " + id + ", flags= " + info); | ||
const align = getValueAlign(info); | ||
const length = values.length; | ||
const buf = alloc(length << align, ARRAYBUFFER_ID); | ||
const arr = alloc(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); | ||
const U32 = new Uint32Array(memory.buffer); | ||
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf); | ||
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf; | ||
U32[arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2] = length << align; | ||
if (info & ARRAY) U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length; | ||
const buf = alloc(length << align, info & STATICARRAY ? id : ARRAYBUFFER_ID); | ||
let result; | ||
if (info & STATICARRAY) { | ||
result = buf; | ||
} else { | ||
const arr = alloc(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); | ||
const U32 = new Uint32Array(memory.buffer); | ||
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf); | ||
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf; | ||
U32[arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2] = length << align; | ||
if (info & ARRAY) U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length; | ||
result = arr; | ||
} | ||
const view = getView(align, info & VAL_SIGNED, info & VAL_FLOAT); | ||
@@ -183,3 +190,3 @@ if (info & VAL_MANAGED) { | ||
} | ||
return arr; | ||
return result; | ||
} | ||
@@ -194,5 +201,7 @@ | ||
const info = getInfo(id); | ||
if (!(info & (ARRAYBUFFERVIEW | ARRAY))) throw Error("not an array: " + id + ", flags=" + info); | ||
if (!(info & (ARRAYBUFFERVIEW | ARRAY | STATICARRAY))) throw Error("not an array: " + id + ", flags=" + info); | ||
const align = getValueAlign(info); | ||
let buf = U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2]; | ||
let buf = info & STATICARRAY | ||
? arr | ||
: U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2]; | ||
const length = info & ARRAY | ||
@@ -240,26 +249,27 @@ ? U32[arr + ARRAY_LENGTH_OFFSET >>> 2] | ||
extendedExports.__getInt8Array = getTypedArray.bind(null, Int8Array, 0); | ||
extendedExports.__getInt8ArrayView = getTypedArrayView.bind(null, Int8Array, 0); | ||
extendedExports.__getUint8Array = getTypedArray.bind(null, Uint8Array, 0); | ||
extendedExports.__getUint8ArrayView = getTypedArrayView.bind(null, Uint8Array, 0); | ||
extendedExports.__getUint8ClampedArray = getTypedArray.bind(null, Uint8ClampedArray, 0); | ||
extendedExports.__getUint8ClampedArrayView = getTypedArrayView.bind(null, Uint8ClampedArray, 0); | ||
extendedExports.__getInt16Array = getTypedArray.bind(null, Int16Array, 1); | ||
extendedExports.__getInt16ArrayView = getTypedArrayView.bind(null, Int16Array, 1); | ||
extendedExports.__getUint16Array = getTypedArray.bind(null, Uint16Array, 1); | ||
extendedExports.__getUint16ArrayView = getTypedArrayView.bind(null, Uint16Array, 1); | ||
extendedExports.__getInt32Array = getTypedArray.bind(null, Int32Array, 2); | ||
extendedExports.__getInt32ArrayView = getTypedArrayView.bind(null, Int32Array, 2); | ||
extendedExports.__getUint32Array = getTypedArray.bind(null, Uint32Array, 2); | ||
extendedExports.__getUint32ArrayView = getTypedArrayView.bind(null, Uint32Array, 2); | ||
/** Attach a set of get TypedArray and View functions to the exports. */ | ||
function attachTypedArrayFunctions(ctor, name, align) { | ||
extendedExports["__get" + name] = getTypedArray.bind(null, ctor, align); | ||
extendedExports["__get" + name + "View"] = getTypedArrayView.bind(null, ctor, align); | ||
} | ||
[ | ||
Int8Array, | ||
Uint8Array, | ||
Uint8ClampedArray, | ||
Int16Array, | ||
Uint16Array, | ||
Int32Array, | ||
Uint32Array, | ||
Float32Array, | ||
Float64Array | ||
].forEach(ctor => { | ||
attachTypedArrayFunctions(ctor, ctor.name, 31 - Math.clz32(ctor.BYTES_PER_ELEMENT)); | ||
}); | ||
if (BIGINT) { | ||
extendedExports.__getInt64Array = getTypedArray.bind(null, BigInt64Array, 3); | ||
extendedExports.__getInt64ArrayView = getTypedArrayView.bind(null, BigInt64Array, 3); | ||
extendedExports.__getUint64Array = getTypedArray.bind(null, BigUint64Array, 3); | ||
extendedExports.__getUint64ArrayView = getTypedArrayView.bind(null, BigUint64Array, 3); | ||
[BigUint64Array, BigInt64Array].forEach(ctor => { | ||
attachTypedArrayFunctions(ctor, ctor.name.slice(3), 3); | ||
}); | ||
} | ||
extendedExports.__getFloat32Array = getTypedArray.bind(null, Float32Array, 2); | ||
extendedExports.__getFloat32ArrayView = getTypedArrayView.bind(null, Float32Array, 2); | ||
extendedExports.__getFloat64Array = getTypedArray.bind(null, Float64Array, 3); | ||
extendedExports.__getFloat64ArrayView = getTypedArrayView.bind(null, Float64Array, 3); | ||
@@ -266,0 +276,0 @@ /** Tests whether an object is an instance of the class represented by the specified base id. */ |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "0.9.4-nightly.20200325", | ||
"version": "0.9.4-nightly.20200329", | ||
"author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>", | ||
@@ -15,0 +15,0 @@ "license": "Apache-2.0", |
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
487
33118