checked builtin array get, optimize abv layout

This commit is contained in:
dcode 2019-03-17 08:46:26 +01:00
parent e63c6bd388
commit f21b339563
20 changed files with 4772 additions and 1568 deletions

View File

@ -61,7 +61,8 @@ import {
Field,
Global,
DecoratorFlags,
Local
Local,
Program
} from "./program";
import {
@ -4084,8 +4085,8 @@ export function compileIterateRoots(compiler: Compiler): void {
);
}
function typedArraySymbolToType(symbol: string): Type | null {
switch (symbol) {
function determineTypedArrayType(target: Class, program: Program): Type | null {
switch (target.internalName) {
case BuiltinSymbols.Int8Array: return Type.i8;
case BuiltinSymbols.Uint8ClampedArray:
case BuiltinSymbols.Uint8Array: return Type.u8;
@ -4098,32 +4099,21 @@ function typedArraySymbolToType(symbol: string): Type | null {
case BuiltinSymbols.Float32Array: return Type.f32;
case BuiltinSymbols.Float64Array: return Type.f64;
}
var typeArguments = target.typeArguments;
if (typeArguments && typeArguments.length == 1) {
return typeArguments[0]; // Array<T>, TypedArray<T>
}
return null;
}
export function compileArrayGet(
export function compileBuiltinArrayGet(
compiler: Compiler,
target: Class,
thisExpression: Expression,
elementExpression: Expression,
contextualType: Type
): ExpressionRef {
var type = typedArraySymbolToType(target.internalName);
if (!type) {
assert(target.prototype == compiler.program.arrayPrototype);
type = assert(target.typeArguments)[0];
}
return compileTypedArrayGet(compiler, target, type, thisExpression, elementExpression, contextualType);
}
function compileTypedArrayGet(
compiler: Compiler,
target: Class,
type: Type,
thisExpression: Expression,
elementExpression: Expression,
contextualType: Type
): ExpressionRef {
var type = assert(determineTypedArrayType(target, compiler.program));
var module = compiler.module;
var outType = (
type.is(TypeFlags.INTEGER) &&
@ -4133,80 +4123,134 @@ function compileTypedArrayGet(
var dataStart = assert(target.lookupInSelf("dataStart"));
assert(dataStart.kind == ElementKind.FIELD);
var dataEnd = assert(target.lookupInSelf("dataEnd"));
assert(dataEnd.kind == ElementKind.FIELD);
var dataLength = assert(target.lookupInSelf("dataLength"));
assert(dataLength.kind == ElementKind.FIELD);
var constantOffset: i32 = 0;
var dynamicOffset = module.precomputeExpression(compiler.compileExpression(
// compile the index expression and shift it to become the actual byteOffset
var dynamicOffset = compiler.compileExpression(
elementExpression,
Type.i32,
ConversionKind.IMPLICIT,
WrapMode.NONE
));
if (getExpressionId(dynamicOffset) == ExpressionId.Const) {
constantOffset = getConstValueI32(dynamicOffset);
dynamicOffset = 0;
} else if (getExpressionId(dynamicOffset) == ExpressionId.Binary) {
if (getBinaryOp(dynamicOffset) == BinaryOp.AddI32) {
let left = getBinaryLeft(dynamicOffset);
let right = getBinaryRight(dynamicOffset);
if (getExpressionId(left) == ExpressionId.Const) {
constantOffset = getConstValueI32(left);
dynamicOffset = right;
} else if (getExpressionId(right) == ExpressionId.Const) {
constantOffset = getConstValueI32(right);
dynamicOffset = left;
}
}
);
var alignLog2 = type.alignLog2;
if (alignLog2) {
dynamicOffset = module.createBinary(BinaryOp.ShlI32,
dynamicOffset,
module.createI32(alignLog2)
);
}
var flow = compiler.currentFlow;
var usizeType = compiler.options.usizeType;
var nativeSizeType = compiler.options.nativeSizeType;
var dataStartExpr = module.createLoad(usizeType.byteSize, true,
compiler.compileExpression(
thisExpression,
target.type,
ConversionKind.IMPLICIT,
WrapMode.NONE
),
nativeSizeType, (<Field>dataStart).memoryOffset
);
var isUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT);
var ptrExpr: ExpressionRef;
var constantOffset: i32 = 0;
var typeAlignLog2 = type.alignLog2;
constantOffset <<= typeAlignLog2;
if (dynamicOffset) {
if (typeAlignLog2) {
dynamicOffset = module.createBinary(BinaryOp.ShlI32,
dynamicOffset,
module.createI32(typeAlignLog2)
);
if (isUnchecked) {
// precompute byteOffset into a constant and a dynamic part
dynamicOffset = module.precomputeExpression(dynamicOffset);
if (getExpressionId(dynamicOffset) == ExpressionId.Const) {
constantOffset = getConstValueI32(dynamicOffset);
dynamicOffset = 0;
} else if (getExpressionId(dynamicOffset) == ExpressionId.Binary) {
if (getBinaryOp(dynamicOffset) == BinaryOp.AddI32) {
let left = getBinaryLeft(dynamicOffset);
let right = getBinaryRight(dynamicOffset);
if (getExpressionId(left) == ExpressionId.Const) {
constantOffset = getConstValueI32(left);
dynamicOffset = right;
} else if (getExpressionId(right) == ExpressionId.Const) {
constantOffset = getConstValueI32(right);
dynamicOffset = left;
}
}
}
// ptr = this.dataStart
ptrExpr = module.createLoad(usizeType.byteSize, true,
compiler.compileExpression(
thisExpression,
target.type,
ConversionKind.IMPLICIT,
WrapMode.NONE
),
nativeSizeType, (<Field>dataStart).memoryOffset
);
// ptr = ptr + <usize>dynamicOffset
if (dynamicOffset) {
if (nativeSizeType == NativeType.I64) {
ptrExpr = module.createBinary(BinaryOp.AddI64,
ptrExpr,
module.createUnary(UnaryOp.ExtendU32, dynamicOffset)
);
} else {
ptrExpr = module.createBinary(BinaryOp.AddI32,
ptrExpr,
dynamicOffset
);
}
}
} else /* checked */ {
let tempThis = flow.getTempLocal(usizeType, false);
let tempOffset = flow.getAndFreeTempLocal(Type.i32, false);
flow.freeTempLocal(tempThis);
// ptr = (tempThis = this).dataStart
ptrExpr = module.createLoad(usizeType.byteSize, true,
module.createTeeLocal(tempThis.index,
compiler.compileExpression(
thisExpression,
target.type,
ConversionKind.IMPLICIT,
WrapMode.NONE
)
),
nativeSizeType, (<Field>dataStart).memoryOffset
);
// ptr = ptr + <usize>(tempOffset = dynamicOffset)
if (nativeSizeType == NativeType.I64) {
dataStartExpr = module.createBinary(BinaryOp.AddI64,
dataStartExpr,
module.createUnary(UnaryOp.ExtendU32, dynamicOffset)
ptrExpr = module.createBinary(BinaryOp.AddI64,
ptrExpr,
module.createUnary(UnaryOp.ExtendU32,
module.createTeeLocal(tempOffset.index, dynamicOffset)
)
);
} else {
dataStartExpr = module.createBinary(BinaryOp.AddI32,
dataStartExpr,
dynamicOffset
ptrExpr = module.createBinary(BinaryOp.AddI32,
ptrExpr,
module.createTeeLocal(tempOffset.index, dynamicOffset)
);
}
}
// TODO: check offset
// ptr = select(ptr, -1, <u32>tempOffset < <u32>tempThis.dataLength)
// triggers "RuntimeError: memory access out of bounds" if OOB
ptrExpr = module.createSelect(
ptrExpr,
usizeType.toNativeNegOne(module),
module.createBinary(BinaryOp.LtU32,
module.createGetLocal(tempOffset.index, NativeType.I32),
module.createLoad(4, false,
module.createGetLocal(tempThis.index, nativeSizeType),
NativeType.I32, (<Field>dataLength).memoryOffset
)
)
);
}
compiler.currentType = outType;
return module.createLoad(
type.byteSize,
type.is(TypeFlags.SIGNED),
dataStartExpr,
ptrExpr,
outType.toNativeType(),
constantOffset
);
}
export function compileArraySet(
export function compileBuiltinArraySet(
compiler: Compiler,
target: Class,
thisExpression: Expression,
@ -4214,38 +4258,49 @@ export function compileArraySet(
valueExpression: Expression,
contextualType: Type
): ExpressionRef {
var program = compiler.program;
var type = typedArraySymbolToType(target.internalName);
if (!type) {
assert(target.prototype == program.arrayPrototype);
type = assert(target.typeArguments)[0];
}
return compileTypedArraySet(
var type = assert(determineTypedArrayType(target, compiler.program));
return compileBuiltinArraySetWithValue(
compiler,
target,
type,
thisExpression,
elementExpression,
valueExpression,
contextualType
compiler.compileExpression(
valueExpression,
type.is(TypeFlags.INTEGER | TypeFlags.VALUE)
? type.is(TypeFlags.LONG)
? type.is(TypeFlags.SIGNED)
? Type.i64
: Type.u64
: type.is(TypeFlags.SIGNED)
? Type.i32
: Type.u32
: type,
ConversionKind.IMPLICIT,
WrapMode.NONE
),
contextualType != Type.void
);
}
function compileTypedArraySet(
export function compileBuiltinArraySetWithValue(
compiler: Compiler,
target: Class,
type: Type,
thisExpression: Expression,
elementExpression: Expression,
valueExpression: Expression,
contextualType: Type
valueExpr: ExpressionRef,
tee: bool
): ExpressionRef {
// TODO: check offset
var program = compiler.program;
var type = assert(determineTypedArrayType(target, compiler.program));
var module = compiler.module;
var dataStart = assert(target.lookupInSelf("dataStart"));
assert(dataStart.kind == ElementKind.FIELD);
var dataEnd = assert(target.lookupInSelf("dataEnd"));
assert(dataEnd.kind == ElementKind.FIELD);
var dataLength = assert(target.lookupInSelf("dataLength"));
assert(dataLength.kind == ElementKind.FIELD);
var constantOffset: i32 = 0;
var dynamicOffset = module.precomputeExpression(
@ -4313,21 +4368,6 @@ function compileTypedArraySet(
}
}
var valueExpr = compiler.compileExpression(
valueExpression,
type.is(TypeFlags.INTEGER | TypeFlags.VALUE)
? type.is(TypeFlags.LONG)
? type.is(TypeFlags.SIGNED)
? Type.i64
: Type.u64
: type.is(TypeFlags.SIGNED)
? Type.i32
: Type.u32
: type,
ConversionKind.IMPLICIT,
WrapMode.NONE
);
// handle Array<Ref>: value = LINK<T, TArray>(value, this), value
if (typeIsManaged) {
let program = compiler.program;
@ -4379,9 +4419,7 @@ function compileTypedArraySet(
var nativeType = type.toNativeType();
// TODO: check offset
if (contextualType == Type.void) {
if (!tee) {
compiler.currentType = Type.void;
return module.createStore(
type.byteSize,

View File

@ -9,8 +9,9 @@ import {
compileIterateRoots,
ensureGCHook,
BuiltinSymbols,
compileArrayGet,
compileArraySet
compileBuiltinArrayGet,
compileBuiltinArraySet,
compileBuiltinArraySetWithValue
} from "./builtins";
import {
@ -4706,7 +4707,7 @@ export class Compiler extends DiagnosticEmitter {
let arrayBufferView = this.program.arrayBufferViewInstance;
if (arrayBufferView) {
if ((<Class>target).prototype.extends(arrayBufferView.prototype)) {
return compileArraySet(
return compileBuiltinArraySet(
this,
<Class>target,
assert(this.resolver.currentThisExpression),
@ -4939,6 +4940,19 @@ export class Compiler extends DiagnosticEmitter {
case ElementKind.CLASS: {
let elementExpression = this.resolver.currentElementExpression;
if (elementExpression) {
let arrayBufferView = this.program.arrayBufferViewInstance;
if (arrayBufferView) {
if ((<Class>target).prototype.extends(arrayBufferView.prototype)) {
return compileBuiltinArraySetWithValue(
this,
<Class>target,
assert(this.resolver.currentThisExpression),
elementExpression,
valueWithCorrectType,
tee
);
}
}
let isUnchecked = flow.is(FlowFlags.UNCHECKED_CONTEXT);
let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET, isUnchecked);
if (!indexedGet) {
@ -5946,21 +5960,21 @@ export class Compiler extends DiagnosticEmitter {
if (!target) return this.module.createUnreachable();
switch (target.kind) {
case ElementKind.CLASS: {
let arrayBufferView = this.program.arrayBufferViewInstance;
if (arrayBufferView) {
if ((<Class>target).prototype.extends(arrayBufferView.prototype)) {
return compileBuiltinArrayGet(
this,
<Class>target,
expression.expression,
expression.elementExpression,
contextualType
);
}
}
let isUnchecked = this.currentFlow.is(FlowFlags.UNCHECKED_CONTEXT);
let indexedGet = (<Class>target).lookupOverload(OperatorKind.INDEXED_GET, isUnchecked);
if (!indexedGet) {
let arrayBufferView = this.program.arrayBufferViewInstance;
if (arrayBufferView) {
if ((<Class>target).prototype.extends(arrayBufferView.prototype)) {
return compileArrayGet(
this,
<Class>target,
expression.expression,
expression.elementExpression,
contextualType
);
}
}
this.error(
DiagnosticCode.Index_signature_is_missing_in_type_0,
expression.expression.range, (<Class>target).internalName
@ -6570,7 +6584,7 @@ export class Compiler extends DiagnosticEmitter {
assert(!program.options.isWasm64); // TODO
assert(arrayInstance.writeField("data", bufferAddress32, buf, runtimeHeaderSize));
assert(arrayInstance.writeField("dataStart", bufferAddress32, buf, runtimeHeaderSize));
assert(arrayInstance.writeField("dataEnd", bufferAddress32 + bufferLength, buf, runtimeHeaderSize));
assert(arrayInstance.writeField("dataLength", bufferLength, buf, runtimeHeaderSize));
assert(arrayInstance.writeField("length_", arrayLength, buf, runtimeHeaderSize));
return this.addMemorySegment(buf);

View File

@ -4,6 +4,22 @@ import { COMPARATOR, SORT } from "./util/sort";
import { itoa, dtoa, itoa_stream, dtoa_stream, MAX_DOUBLE_LENGTH } from "./util/number";
import { isArray as builtin_isArray } from "./builtins";
/** Ensures that the given array has _at least_ the specified length. */
function ensureLength(array: ArrayBufferView, length: i32, alignLog2: u32): void {
var oldData = array.data;
var oldCapacity = oldData.byteLength >>> alignLog2;
if (<u32>length > <u32>oldCapacity) {
if (<u32>length > <u32>(MAX_BYTELENGTH >>> alignLog2)) throw new RangeError("Invalid array length");
let newByteLength = length << alignLog2;
let newData = REALLOCATE(changetype<usize>(oldData), <usize>newByteLength); // registers on move
if (newData !== changetype<usize>(oldData)) {
array.data = changetype<ArrayBuffer>(newData); // links
array.dataStart = newData;
array.dataLength = newByteLength;
}
}
}
export class Array<T> extends ArrayBufferView {
private length_: i32;
@ -25,26 +41,10 @@ export class Array<T> extends ArrayBufferView {
}
set length(length: i32) {
this.resize(length);
ensureLength(changetype<ArrayBufferView>(this), length, alignof<T>());
this.length_ = length;
}
private resize(length: i32): void {
var oldData = this.data;
var oldCapacity = oldData.byteLength >>> alignof<T>();
if (<u32>length > <u32>oldCapacity) {
const MAX_LENGTH = MAX_BYTELENGTH >>> alignof<T>();
if (<u32>length > <u32>MAX_LENGTH) throw new RangeError("Invalid array length");
let newCapacity = <usize>length << alignof<T>();
let newData = REALLOCATE(changetype<usize>(oldData), newCapacity); // registers on move
if (newData !== changetype<usize>(oldData)) {
this.data = changetype<ArrayBuffer>(newData); // links
this.dataStart = newData;
this.dataEnd = newData + newCapacity;
}
}
}
every(callbackfn: (element: T, index: i32, array: Array<T>) => bool): bool {
for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {
if (!callbackfn(load<T>(this.dataStart + (<usize>index << alignof<T>())), index, this)) return false;
@ -59,33 +59,14 @@ export class Array<T> extends ArrayBufferView {
return -1;
}
// @operator("[]")
// private __get(index: i32): T {
// var buffer = this.buffer_;
// return <u32>index < <u32>(buffer.byteLength >>> alignof<T>())
// ? LOAD<T>(buffer, index)
// : <T>unreachable();
// }
// @operator("{}")
// private __unchecked_get(index: i32): T {
// return LOAD<T>(this.buffer_, index);
// }
@operator("[]=")
private __set(index: i32, value: T): void {
this.resize(index + 1);
private __set(index: i32, value: T): void { // unchecked is built-in
ensureLength(changetype<ArrayBufferView>(this), index + 1, alignof<T>());
store<T>(this.dataStart + (<usize>index << alignof<T>()), value);
if (isManaged<T>()) LINK(value, this);
if (index >= this.length_) this.length_ = index + 1;
}
// @operator("{}=")
// private __unchecked_set(index: i32, value: T): void {
// STORE<T>(this.buffer_, index, value);
// if (isManaged<T>()) __gc_link(changetype<usize>(this), changetype<usize>(value)); // tslint:disable-line
// }
fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {
var dataStart = this.dataStart;
var length = this.length_;
@ -138,7 +119,7 @@ export class Array<T> extends ArrayBufferView {
push(element: T): i32 {
var newLength = this.length_ + 1;
this.resize(newLength);
ensureLength(changetype<ArrayBufferView>(this), newLength, alignof<T>());
this.length_ = newLength;
store<T>(this.dataStart + (<usize>(newLength - 1) << alignof<T>()), element);
if (isManaged<T>()) LINK(element, this);
@ -285,7 +266,7 @@ export class Array<T> extends ArrayBufferView {
unshift(element: T): i32 {
var newLength = this.length_;
this.resize(newLength);
ensureLength(changetype<ArrayBufferView>(this), newLength, alignof<T>());
var base = this.dataStart;
memory.copy(
base + sizeof<T>(),
@ -347,7 +328,7 @@ export class Array<T> extends ArrayBufferView {
reverse(): Array<T> {
var front = this.dataStart;
var back = this.dataEnd - sizeof<T>();
var back = this.dataStart + this.dataLength - sizeof<T>();
while (front < back) {
let temp = load<T>(front);
store<T>(front, load<T>(back));

View File

@ -5,7 +5,7 @@ export class DataView {
private data: ArrayBuffer;
private dataStart: usize;
private dataEnd: usize;
private dataLength: u32;
constructor(
buffer: ArrayBuffer,
@ -18,7 +18,7 @@ export class DataView {
this.data = buffer; // links
var dataStart = changetype<usize>(buffer) + <usize>byteOffset;
this.dataStart = dataStart;
this.dataEnd = dataStart + <usize>byteLength;
this.dataLength = byteLength;
}
get buffer(): ArrayBuffer {
@ -30,169 +30,129 @@ export class DataView {
}
get byteLength(): i32 {
return <i32>(this.dataEnd - this.dataStart);
return this.dataLength;
}
getFloat32(byteOffset: i32, littleEndian: boolean = false): f32 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
return littleEndian
? load<f32>(dataOffset)
? load<f32>(this.dataStart + <usize>byteOffset)
: reinterpret<f32>(
bswap<u32>(
load<u32>(dataOffset)
load<u32>(this.dataStart + <usize>byteOffset)
)
);
}
getFloat64(byteOffset: i32, littleEndian: boolean = false): f64 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
return littleEndian
? load<f64>(dataOffset)
? load<f64>(this.dataStart + <usize>byteOffset)
: reinterpret<f64>(
bswap<u64>(
load<u64>(dataOffset)
load<u64>(this.dataStart + <usize>byteOffset)
)
);
}
getInt8(byteOffset: i32): i8 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset >= this.dataEnd) throw new Error("Offset out of bounds");
return load<i8>(dataOffset);
if (byteOffset >= this.dataLength) throw new Error("Offset out of bounds");
return load<i8>(this.dataStart + <usize>byteOffset);
}
getInt16(byteOffset: i32, littleEndian: boolean = false): i16 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 2 > this.dataEnd) throw new Error("Offset out of bounds");
var result: i16 = load<i16>(dataOffset);
if (byteOffset + 2 > this.dataLength) throw new Error("Offset out of bounds");
var result: i16 = load<i16>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<i16>(result);
}
getInt32(byteOffset: i32, littleEndian: boolean = false): i32 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
var result: i32 = load<i32>(dataOffset);
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
var result: i32 = load<i32>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<i32>(result);
}
getUint8(byteOffset: i32): u8 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset >= this.dataEnd) throw new Error("Offset out of bounds");
return load<u8>(dataOffset);
if (byteOffset >= this.dataLength) throw new Error("Offset out of bounds");
return load<u8>(this.dataStart + <usize>byteOffset);
}
getUint16(byteOffset: i32, littleEndian: boolean = false): u16 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 2 > this.dataEnd) throw new Error("Offset out of bounds");
var result: u16 = load<u16>(dataOffset);
if (byteOffset + 2 > this.dataLength) throw new Error("Offset out of bounds");
var result: u16 = load<u16>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u16>(result);
}
getUint32(byteOffset: i32, littleEndian: boolean = false): u32 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 2 > this.dataEnd) throw new Error("Offset out of bounds");
var result: u32 = load<u32>(dataOffset);
if (byteOffset + 2 > this.dataLength) throw new Error("Offset out of bounds");
var result: u32 = load<u32>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u32>(result);
}
setFloat32(byteOffset: i32, value: f32, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
if (littleEndian) store<f32>(dataOffset, value);
else store<u32>(dataOffset, bswap(reinterpret<u32>(value)));
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
if (littleEndian) store<f32>(this.dataStart + <usize>byteOffset, value);
else store<u32>(this.dataStart + <usize>byteOffset, bswap<u32>(reinterpret<u32>(value)));
}
setFloat64(byteOffset: i32, value: f64, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
if (littleEndian) store<f64>(dataOffset, value);
else store<u64>(dataOffset, bswap(reinterpret<u64>(value)));
if (byteOffset + 8 > this.dataLength) throw new Error("Offset out of bounds");
if (littleEndian) store<f64>(this.dataStart + <usize>byteOffset, value);
else store<u64>(this.dataStart + <usize>byteOffset, bswap<u64>(reinterpret<u64>(value)));
}
setInt8(byteOffset: i32, value: i8): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset >= this.dataEnd) throw new Error("Offset out of bounds");
store<i8>(dataOffset, value);
if (byteOffset >= this.dataLength) throw new Error("Offset out of bounds");
store<i8>(this.dataStart + <usize>byteOffset, value);
}
setInt16(byteOffset: i32, value: i16, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 2 > this.dataEnd) throw new Error("Offset out of bounds");
store<i16>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 2 > this.dataLength) throw new Error("Offset out of bounds");
store<i16>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<i16>(value));
}
setInt32(byteOffset: i32, value: i32, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
store<i32>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
store<i32>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<i32>(value));
}
setUint8(byteOffset: i32, value: u8): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset >= this.dataEnd) throw new Error("Offset out of bounds");
store<u8>(dataOffset, value);
if (byteOffset >= this.dataLength) throw new Error("Offset out of bounds");
store<u8>(this.dataStart + <usize>byteOffset, value);
}
setUint16(byteOffset: i32, value: u16, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 2 > this.dataEnd) throw new Error("Offset out of bounds");
store<u16>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 2 > this.dataLength) throw new Error("Offset out of bounds");
store<u16>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<u16>(value));
}
setUint32(byteOffset: i32, value: u32, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 4 > this.dataEnd) throw new Error("Offset out of bounds");
store<u32>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 4 > this.dataLength) throw new Error("Offset out of bounds");
store<u32>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<u32>(value));
}
// Non-standard additions that make sense in WebAssembly, but won't work in JS:
getInt64(byteOffset: i32, littleEndian: boolean = false): i64 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 8 > this.dataEnd) throw new Error("Offset out of bounds");
var result: i64 = load<i64>(dataOffset);
return littleEndian ? result : bswap(result);
if (byteOffset + 8 > this.dataLength) throw new Error("Offset out of bounds");
var result: i64 = load<i64>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<i64>(result);
}
getUint64(byteOffset: i32, littleEndian: boolean = false): u64 {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 8 > this.dataEnd) throw new Error("Offset out of bounds");
var result = load<u64>(dataOffset);
return littleEndian ? result : bswap(result);
if (byteOffset + 8 > this.dataLength) throw new Error("Offset out of bounds");
var result = load<u64>(this.dataStart + <usize>byteOffset);
return littleEndian ? result : bswap<u64>(result);
}
setInt64(byteOffset: i32, value: i64, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 8 > this.dataEnd) throw new Error("Offset out of bounds");
store<i64>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 8 > this.dataLength) throw new Error("Offset out of bounds");
store<i64>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<i64>(value));
}
setUint64(byteOffset: i32, value: u64, littleEndian: boolean = false): void {
var dataStart = this.dataStart;
var dataOffset = dataStart + <usize>byteOffset;
if (dataOffset + 8 > this.dataEnd) throw new Error("Offset out of bounds");
store<u64>(dataOffset, littleEndian ? value : bswap(value));
if (byteOffset + 8 > this.dataLength) throw new Error("Offset out of bounds");
store<u64>(this.dataStart + <usize>byteOffset, littleEndian ? value : bswap<u64>(value));
}
toString(): string {

View File

@ -122,6 +122,7 @@ function doReallocate(ref: usize, newPayloadSize: usize): usize {
// @ts-ignore: decorator
@unsafe @inline
export function REGISTER<T>(ref: usize): T {
if (!isReference<T>()) ERROR("reference expected");
return changetype<T>(doRegister(ref, CLASSID<T>()));
}
@ -137,6 +138,8 @@ function doRegister(ref: usize, classId: u32): usize {
// @ts-ignore: decorator
@unsafe @inline
export function LINK<T,TParent>(ref: T, parentRef: TParent): void {
if (!isReference<T>()) ERROR("reference expected");
if (!isReference<TParent>()) ERROR("reference expected");
doLink(changetype<usize>(ref), changetype<usize>(parentRef));
}
@ -174,7 +177,7 @@ function doWrapArray(buffer: ArrayBuffer, classId: u32, alignLog2: usize): usize
var newBuffer = doRegister(doAllocate(bufferSize), classId);
changetype<ArrayBufferView>(array).data = changetype<ArrayBuffer>(newBuffer); // links
changetype<ArrayBufferView>(array).dataStart = changetype<usize>(newBuffer);
changetype<ArrayBufferView>(array).dataEnd = changetype<usize>(newBuffer) + bufferSize;
changetype<ArrayBufferView>(array).dataLength = bufferSize;
store<i32>(changetype<usize>(array), <i32>(bufferSize >>> alignLog2), offsetof<i32[]>("length_"));
memory.copy(changetype<usize>(newBuffer), changetype<usize>(buffer), bufferSize);
return changetype<usize>(array);
@ -217,14 +220,14 @@ export abstract class ArrayBufferView {
// @ts-ignore: decorator
@unsafe
dataEnd: usize;
dataLength: u32;
protected constructor(length: i32, alignLog2: i32) {
if (<u32>length > <u32>MAX_BYTELENGTH >>> alignLog2) throw new RangeError("Invalid length");
var buffer = new ArrayBuffer(length = length << alignLog2);
this.data = buffer;
this.dataStart = changetype<usize>(buffer);
this.dataEnd = changetype<usize>(buffer) + <usize>length;
this.dataLength = length;
}
get byteOffset(): i32 {
@ -232,7 +235,7 @@ export abstract class ArrayBufferView {
}
get byteLength(): i32 {
return <i32>(this.dataEnd - this.dataStart);
return this.dataLength;
}
get length(): i32 {

View File

@ -366,8 +366,8 @@ import { compareImpl, parse, CharCode, isWhiteSpaceOrLineTerminator } from "./ut
charStr,
load<u16>(changetype<usize>(this) + (<usize>i << 1))
);
store<String>(resultStart + (<usize>i << alignof<String>()), REGISTER<String>(charStr));
LINK(charStr, result);
store<usize>(resultStart + (<usize>i << alignof<usize>()), charStr); // result[i] = charStr
LINK(REGISTER<String>(charStr), result);
}
return result;
} else if (!length) {

View File

@ -1,9 +1,9 @@
import { ALLOCATE, REGISTER, LINK, ArrayBufferView } from "./runtime";
import { COMPARATOR, SORT as SORT_IMPL } from "./util/sort";
function clampToByte(value: i32): i32 {
return ~(value >> 31) & (((255 - value) >> 31) | value); // & 255
}
// function clampToByte(value: i32): i32 {
// return ~(value >> 31) & (((255 - value) >> 31) | value); // & 255
// }
export class Int8Array extends ArrayBufferView {
@ -809,7 +809,7 @@ function SUBARRAY<TArray extends ArrayBufferView, T>(
var dataStart = array.dataStart;
changetype<ArrayBufferView>(out).data = data; // links
changetype<ArrayBufferView>(out).dataStart = dataStart + (<usize>begin << alignof<T>());
changetype<ArrayBufferView>(out).dataEnd = dataStart + (<usize>end << alignof<T>());
changetype<ArrayBufferView>(out).dataLength = (end - begin) << alignof<T>();
return out;
}

View File

@ -123,7 +123,7 @@
if
i32.const 0
i32.const 16
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -137,7 +137,7 @@
if
i32.const 0
i32.const 16
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable

View File

@ -160,7 +160,7 @@
if
i32.const 0
i32.const 16
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -175,7 +175,7 @@
if
i32.const 0
i32.const 16
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable

View File

@ -62,7 +62,7 @@
(memory $0 1)
(data (i32.const 8) "\01\00\00\00\16\00\00\00s\00t\00d\00/\00m\00a\00t\00h\00.\00t\00s")
(data (i32.const 40) "\02\00\00\00 \00\00\00)\15DNn\83\f9\a2\c0\dd4\f5\d1W\'\fcA\90C<\99\95b\dba\c5\bb\de\abcQ\fe")
(data (i32.const 80) "\03\00\00\00\10\00\00\000\00\00\000\00\00\00P\00\00\00\04")
(data (i32.const 80) "\03\00\00\00\10\00\00\000\00\00\000\00\00\00 \00\00\00\04")
(data (i32.const 104) "\01\00\00\00\18\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s")
(table $0 1 funcref)
(elem (i32.const 0) $null)
@ -3489,8 +3489,7 @@
(local $7 i32)
(local $8 i64)
(local $9 i32)
(local $10 i32)
(local $11 i64)
(local $10 i64)
local.get $0
i32.reinterpret_f32
local.tee $3
@ -3782,6 +3781,8 @@
i32.trunc_f64_s
br $~lib/math/rempio2f|inlined.0
end
i32.const 92
i32.load
local.get $3
i32.const 23
i32.shr_s
@ -3793,17 +3794,18 @@
local.tee $9
i32.const 3
i32.shl
local.tee $10
i32.const 92
i32.load
i32.add
i64.load
local.set $11
local.set $10
i32.const 92
i32.load
local.get $10
local.get $9
i32.const 1
i32.add
i64.load offset=8
i32.const 3
i32.shl
i32.add
i64.load
local.set $5
local.get $6
i32.const 63
@ -3821,10 +3823,12 @@
i32.const 92
i32.load
local.get $9
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
i64.const 96
local.get $6
i64.extend_i32_s
@ -3851,7 +3855,7 @@
local.tee $5
i64.sub
i64.shr_u
local.get $11
local.get $10
local.get $5
i64.shl
i64.or
@ -9282,8 +9286,7 @@
(local $7 i32)
(local $8 i64)
(local $9 i32)
(local $10 i32)
(local $11 i64)
(local $10 i64)
local.get $0
i32.reinterpret_f32
local.tee $3
@ -9608,6 +9611,8 @@
i32.trunc_f64_s
br $~lib/math/rempio2f|inlined.1
end
i32.const 92
i32.load
local.get $3
i32.const 23
i32.shr_s
@ -9619,17 +9624,18 @@
local.tee $9
i32.const 3
i32.shl
local.tee $10
i32.const 92
i32.load
i32.add
i64.load
local.set $11
local.set $10
i32.const 92
i32.load
local.get $10
local.get $9
i32.const 1
i32.add
i64.load offset=8
i32.const 3
i32.shl
i32.add
i64.load
local.set $5
local.get $6
i32.const 63
@ -9647,10 +9653,12 @@
i32.const 92
i32.load
local.get $9
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
i64.const 96
local.get $6
i64.extend_i32_s
@ -9677,7 +9685,7 @@
local.tee $5
i64.sub
i64.shr_u
local.get $11
local.get $10
local.get $5
i64.shl
i64.or
@ -10008,8 +10016,7 @@
(local $7 i32)
(local $8 i64)
(local $9 i32)
(local $10 i32)
(local $11 i64)
(local $10 i64)
local.get $0
i32.reinterpret_f32
local.tee $4
@ -10327,6 +10334,8 @@
i32.trunc_f64_s
br $~lib/math/rempio2f|inlined.2
end
i32.const 92
i32.load
local.get $4
i32.const 23
i32.shr_s
@ -10338,17 +10347,18 @@
local.tee $9
i32.const 3
i32.shl
local.tee $10
i32.const 92
i32.load
i32.add
i64.load
local.set $11
local.set $10
i32.const 92
i32.load
local.get $10
local.get $9
i32.const 1
i32.add
i64.load offset=8
i32.const 3
i32.shl
i32.add
i64.load
local.set $5
local.get $6
i32.const 63
@ -10366,10 +10376,12 @@
i32.const 92
i32.load
local.get $9
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
i64.const 96
local.get $6
i64.extend_i32_s
@ -10396,7 +10408,7 @@
local.tee $5
i64.sub
i64.shr_u
local.get $11
local.get $10
local.get $5
i64.shl
i64.or

View File

@ -63,7 +63,7 @@
(memory $0 1)
(data (i32.const 8) "\01\00\00\00\16\00\00\00s\00t\00d\00/\00m\00a\00t\00h\00.\00t\00s\00")
(data (i32.const 40) "\02\00\00\00 \00\00\00)\15DNn\83\f9\a2\c0\dd4\f5\d1W\'\fcA\90C<\99\95b\dba\c5\bb\de\abcQ\fe")
(data (i32.const 80) "\03\00\00\00\10\00\00\000\00\00\000\00\00\00P\00\00\00\04\00\00\00")
(data (i32.const 80) "\03\00\00\00\10\00\00\000\00\00\000\00\00\00 \00\00\00\04\00\00\00")
(data (i32.const 104) "\01\00\00\00\18\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s\00")
(table $0 1 funcref)
(elem (i32.const 0) $null)
@ -4746,6 +4746,8 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 0
i32.add
i32.const 3
i32.shl
i32.add
@ -4754,10 +4756,12 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 1
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=8
i64.load
local.set $17
local.get $15
i32.const 32
@ -4766,10 +4770,12 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
local.set $19
local.get $19
i64.const 96
@ -11762,6 +11768,8 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 0
i32.add
i32.const 3
i32.shl
i32.add
@ -11770,10 +11778,12 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 1
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=8
i64.load
local.set $17
local.get $15
i32.const 32
@ -11782,10 +11792,12 @@
i32.const 88
i32.load offset=4
local.get $14
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
local.set $19
local.get $19
i64.const 96
@ -12748,6 +12760,8 @@
i32.const 88
i32.load offset=4
local.get $16
i32.const 0
i32.add
i32.const 3
i32.shl
i32.add
@ -12756,10 +12770,12 @@
i32.const 88
i32.load offset=4
local.get $16
i32.const 1
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=8
i64.load
local.set $19
local.get $17
i32.const 32
@ -12768,10 +12784,12 @@
i32.const 88
i32.load offset=4
local.get $16
i32.const 2
i32.add
i32.const 3
i32.shl
i32.add
i64.load offset=16
i64.load
local.set $21
local.get $21
i64.const 96

View File

@ -121,7 +121,7 @@
if
i32.const 0
i32.const 16
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -135,7 +135,7 @@
if
i32.const 0
i32.const 16
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable

View File

@ -162,7 +162,7 @@
if
i32.const 0
i32.const 16
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -177,7 +177,7 @@
if
i32.const 0
i32.const 16
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable

View File

@ -4,14 +4,14 @@
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 8) "\01\00\00\00\08\00\00\00\01\00\00\00\02")
(data (i32.const 24) "\02\00\00\00\10\00\00\00\10\00\00\00\10\00\00\00\18\00\00\00\02")
(data (i32.const 24) "\02\00\00\00\10\00\00\00\10\00\00\00\10\00\00\00\08\00\00\00\02")
(data (i32.const 48) "\01\00\00\00\10\00\00\00\03\00\00\00\00\00\00\00\04")
(data (i32.const 72) "\03\00\00\00\10\00\00\008\00\00\008\00\00\00H\00\00\00\02")
(data (i32.const 72) "\03\00\00\00\10\00\00\008\00\00\008\00\00\00\10\00\00\00\02")
(data (i32.const 96) "\01\00\00\00\08\00\00\00\00\00\c0?\00\00 @")
(data (i32.const 112) "\04\00\00\00\10\00\00\00h\00\00\00h\00\00\00p\00\00\00\02")
(data (i32.const 112) "\04\00\00\00\10\00\00\00h\00\00\00h\00\00\00\08\00\00\00\02")
(data (i32.const 136) "\01\00\00\00\10")
(data (i32.const 150) "\f4?\00\00\00\00\00\00\02@")
(data (i32.const 160) "\05\00\00\00\10\00\00\00\90\00\00\00\90\00\00\00\a0\00\00\00\02")
(data (i32.const 160) "\05\00\00\00\10\00\00\00\90\00\00\00\90\00\00\00\10\00\00\00\02")
(data (i32.const 184) "\06\00\00\00&\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s")
(table $0 1 funcref)
(elem (i32.const 0) $null)
@ -26,33 +26,47 @@
if
i32.const 0
i32.const 192
i32.const 8
i32.const 6
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 36
i32.load
i32.const -1
i32.const 0
i32.const 40
i32.load
i32.lt_u
select
i32.load
i32.const 1
i32.ne
if
i32.const 0
i32.const 192
i32.const 9
i32.const 7
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 36
i32.load
i32.load offset=4
i32.const 4
i32.add
i32.const -1
i32.const 4
i32.const 40
i32.load
i32.lt_u
select
i32.load
i32.const 2
i32.ne
if
i32.const 0
i32.const 192
i32.const 10
i32.const 8
i32.const 0
call $~lib/env/abort
unreachable
@ -63,13 +77,19 @@
i32.store
i32.const 36
i32.load
i32.const -1
i32.const 0
i32.const 40
i32.load
i32.lt_u
select
i32.load
i32.const 2
i32.ne
if
i32.const 0
i32.const 192
i32.const 12
i32.const 10
i32.const 0
call $~lib/env/abort
unreachable
@ -81,33 +101,47 @@
if
i32.const 0
i32.const 192
i32.const 14
i32.const 12
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 84
i32.load
i32.const -1
i32.const 0
i32.const 88
i32.load
i32.lt_u
select
i64.load
i64.const 3
i64.ne
if
i32.const 0
i32.const 192
i32.const 15
i32.const 13
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 84
i32.load
i64.load offset=8
i32.const 8
i32.add
i32.const -1
i32.const 8
i32.const 88
i32.load
i32.lt_u
select
i64.load
i64.const 4
i64.ne
if
i32.const 0
i32.const 192
i32.const 16
i32.const 14
i32.const 0
call $~lib/env/abort
unreachable
@ -118,13 +152,19 @@
i64.store
i32.const 84
i32.load
i32.const -1
i32.const 0
i32.const 88
i32.load
i32.lt_u
select
i64.load
i64.const 4
i64.ne
if
i32.const 0
i32.const 192
i32.const 18
i32.const 16
i32.const 0
call $~lib/env/abort
unreachable
@ -136,33 +176,47 @@
if
i32.const 0
i32.const 192
i32.const 20
i32.const 18
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 124
i32.load
i32.const -1
i32.const 0
i32.const 128
i32.load
i32.lt_u
select
f32.load
f32.const 1.5
f32.ne
if
i32.const 0
i32.const 192
i32.const 21
i32.const 19
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 124
i32.load
f32.load offset=4
i32.const 4
i32.add
i32.const -1
i32.const 4
i32.const 128
i32.load
i32.lt_u
select
f32.load
f32.const 2.5
f32.ne
if
i32.const 0
i32.const 192
i32.const 22
i32.const 20
i32.const 0
call $~lib/env/abort
unreachable
@ -173,13 +227,19 @@
f32.store
i32.const 124
i32.load
i32.const -1
i32.const 0
i32.const 128
i32.load
i32.lt_u
select
f32.load
f32.const 2.5
f32.ne
if
i32.const 0
i32.const 192
i32.const 24
i32.const 22
i32.const 0
call $~lib/env/abort
unreachable
@ -191,33 +251,47 @@
if
i32.const 0
i32.const 192
i32.const 26
i32.const 24
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 172
i32.load
i32.const -1
i32.const 0
i32.const 176
i32.load
i32.lt_u
select
f64.load
f64.const 1.25
f64.ne
if
i32.const 0
i32.const 192
i32.const 27
i32.const 25
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 172
i32.load
f64.load offset=8
i32.const 8
i32.add
i32.const -1
i32.const 8
i32.const 176
i32.load
i32.lt_u
select
f64.load
f64.const 2.25
f64.ne
if
i32.const 0
i32.const 192
i32.const 28
i32.const 26
i32.const 0
call $~lib/env/abort
unreachable
@ -228,13 +302,19 @@
f64.store
i32.const 172
i32.load
i32.const -1
i32.const 0
i32.const 176
i32.load
i32.lt_u
select
f64.load
f64.const 2.25
f64.ne
if
i32.const 0
i32.const 192
i32.const 30
i32.const 28
i32.const 0
call $~lib/env/abort
unreachable

View File

@ -1,5 +1,3 @@
import "allocator/arena"; // needed just because std/Array#[]= calls __grow conditionally
const i: i32[] = [1, 2];
const I: i64[] = [3, 4];
const f: f32[] = [1.5, 2.5];

View File

@ -5,13 +5,13 @@
(import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32)))
(memory $0 1)
(data (i32.const 8) "\01\00\00\00\08\00\00\00\01\00\00\00\02\00\00\00")
(data (i32.const 24) "\02\00\00\00\10\00\00\00\10\00\00\00\10\00\00\00\18\00\00\00\02\00\00\00")
(data (i32.const 24) "\02\00\00\00\10\00\00\00\10\00\00\00\10\00\00\00\08\00\00\00\02\00\00\00")
(data (i32.const 48) "\01\00\00\00\10\00\00\00\03\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00")
(data (i32.const 72) "\03\00\00\00\10\00\00\008\00\00\008\00\00\00H\00\00\00\02\00\00\00")
(data (i32.const 72) "\03\00\00\00\10\00\00\008\00\00\008\00\00\00\10\00\00\00\02\00\00\00")
(data (i32.const 96) "\01\00\00\00\08\00\00\00\00\00\c0?\00\00 @")
(data (i32.const 112) "\04\00\00\00\10\00\00\00h\00\00\00h\00\00\00p\00\00\00\02\00\00\00")
(data (i32.const 112) "\04\00\00\00\10\00\00\00h\00\00\00h\00\00\00\08\00\00\00\02\00\00\00")
(data (i32.const 136) "\01\00\00\00\10\00\00\00\00\00\00\00\00\00\f4?\00\00\00\00\00\00\02@")
(data (i32.const 160) "\05\00\00\00\10\00\00\00\90\00\00\00\90\00\00\00\a0\00\00\00\02\00\00\00")
(data (i32.const 160) "\05\00\00\00\10\00\00\00\90\00\00\00\90\00\00\00\10\00\00\00\02\00\00\00")
(data (i32.const 184) "\06\00\00\00&\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s\00")
(table $0 1 funcref)
(elem (i32.const 0) $null)
@ -43,11 +43,65 @@
i32.load offset=12
)
(func $start:std/static-array (; 5 ;) (type $FUNCSIG$v)
(local $0 i32)
(local $1 i32)
global.get $std/static-array/i
call $~lib/array/Array<i32>#get:length
i32.const 2
i32.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 6
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/i
local.tee $0
i32.load offset=4
i32.const 0
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i32.load
i32.const 1
i32.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 7
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/i
local.tee $0
i32.load offset=4
i32.const 1
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i32.load
i32.const 2
i32.eq
i32.eqz
if
i32.const 0
i32.const 192
@ -58,21 +112,23 @@
end
global.get $std/static-array/i
i32.load offset=4
i32.load
i32.const 1
i32.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 9
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 2
i32.store
global.get $std/static-array/i
local.tee $0
i32.load offset=4
i32.load offset=4
i32.const 0
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i32.load
i32.const 2
i32.eq
i32.eqz
@ -84,24 +140,6 @@
call $~lib/env/abort
unreachable
end
global.get $std/static-array/i
i32.load offset=4
i32.const 2
i32.store
global.get $std/static-array/i
i32.load offset=4
i32.load
i32.const 2
i32.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 12
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/I
call $~lib/array/Array<i64>#get:length
i32.const 2
@ -110,13 +148,25 @@
if
i32.const 0
i32.const 192
i32.const 14
i32.const 12
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/I
local.tee $0
i32.load offset=4
i32.const 0
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i64.load
i64.const 3
i64.eq
@ -124,21 +174,33 @@
if
i32.const 0
i32.const 192
i32.const 15
i32.const 13
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/I
local.tee $0
i32.load offset=4
i64.load offset=8
i32.const 1
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i64.load
i64.const 4
i64.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 16
i32.const 14
i32.const 0
call $~lib/env/abort
unreachable
@ -148,7 +210,19 @@
i64.const 4
i64.store
global.get $std/static-array/I
local.tee $0
i32.load offset=4
i32.const 0
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
i64.load
i64.const 4
i64.eq
@ -156,7 +230,7 @@
if
i32.const 0
i32.const 192
i32.const 18
i32.const 16
i32.const 0
call $~lib/env/abort
unreachable
@ -169,13 +243,25 @@
if
i32.const 0
i32.const 192
i32.const 20
i32.const 18
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/f
local.tee $0
i32.load offset=4
i32.const 0
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f32.load
f32.const 1.5
f32.eq
@ -183,21 +269,33 @@
if
i32.const 0
i32.const 192
i32.const 21
i32.const 19
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/f
local.tee $0
i32.load offset=4
f32.load offset=4
i32.const 1
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f32.load
f32.const 2.5
f32.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 22
i32.const 20
i32.const 0
call $~lib/env/abort
unreachable
@ -207,7 +305,19 @@
f32.const 2.5
f32.store
global.get $std/static-array/f
local.tee $0
i32.load offset=4
i32.const 0
i32.const 2
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f32.load
f32.const 2.5
f32.eq
@ -215,7 +325,7 @@
if
i32.const 0
i32.const 192
i32.const 24
i32.const 22
i32.const 0
call $~lib/env/abort
unreachable
@ -228,13 +338,25 @@
if
i32.const 0
i32.const 192
i32.const 26
i32.const 24
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/F
local.tee $0
i32.load offset=4
i32.const 0
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f64.load
f64.const 1.25
f64.eq
@ -242,14 +364,56 @@
if
i32.const 0
i32.const 192
i32.const 27
i32.const 25
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/F
local.tee $0
i32.load offset=4
i32.const 1
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f64.load
f64.const 2.25
f64.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 26
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/static-array/F
i32.load offset=4
f64.load offset=8
f64.const 2.25
f64.store
global.get $std/static-array/F
local.tee $0
i32.load offset=4
i32.const 0
i32.const 3
i32.shl
local.tee $1
i32.add
i32.const -1
local.get $1
local.get $0
i32.load offset=8
i32.lt_u
select
f64.load
f64.const 2.25
f64.eq
i32.eqz
@ -261,24 +425,6 @@
call $~lib/env/abort
unreachable
end
global.get $std/static-array/F
i32.load offset=4
f64.const 2.25
f64.store
global.get $std/static-array/F
i32.load offset=4
f64.load
f64.const 2.25
f64.eq
i32.eqz
if
i32.const 0
i32.const 192
i32.const 30
i32.const 0
call $~lib/env/abort
unreachable
end
)
(func $start (; 6 ;) (type $FUNCSIG$v)
call $start:std/static-array

View File

@ -309,7 +309,7 @@
if
i32.const 0
i32.const 136
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -323,7 +323,7 @@
if
i32.const 0
i32.const 136
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable
@ -3088,7 +3088,7 @@
if
i32.const 0
i32.const 136
i32.const 223
i32.const 226
i32.const 57
call $~lib/env/abort
unreachable
@ -3240,7 +3240,7 @@
i32.store offset=4
local.get $0
)
(func $~lib/array/Array<String>#resize (; 35 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(func $~lib/array/ensureLength (; 35 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(local $2 i32)
(local $3 i32)
local.get $1
@ -3260,20 +3260,19 @@
if
i32.const 0
i32.const 1440
i32.const 37
i32.const 41
i32.const 12
i32.const 59
call $~lib/env/abort
unreachable
end
local.get $2
local.tee $3
local.get $2
local.get $1
i32.const 2
i32.shl
local.tee $2
local.tee $3
call $~lib/runtime/doReallocate
local.tee $1
local.get $3
i32.ne
if
local.get $0
@ -3284,7 +3283,7 @@
i32.store offset=4
local.get $0
local.get $1
local.get $2
local.get $3
i32.add
i32.store offset=8
end
@ -3293,7 +3292,7 @@
(func $~lib/array/Array<String>#__set (; 36 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
local.get $0
i32.const 1
call $~lib/array/Array<String>#resize
call $~lib/array/ensureLength
local.get $0
i32.load offset=4
local.get $1
@ -3318,7 +3317,7 @@
if
i32.const 0
i32.const 136
i32.const 196
i32.const 199
i32.const 2
call $~lib/env/abort
unreachable
@ -3338,7 +3337,7 @@
i32.const 1
i32.add
local.tee $2
call $~lib/array/Array<String>#resize
call $~lib/array/ensureLength
local.get $0
local.get $2
i32.store offset=12
@ -3467,10 +3466,10 @@
local.get $5
i32.add
local.get $1
i32.const 1
call $~lib/runtime/doRegister
i32.store
local.get $1
i32.const 1
call $~lib/runtime/doRegister
local.get $3
call $~lib/runtime/doLink
local.get $4

View File

@ -366,7 +366,7 @@
if
i32.const 0
i32.const 136
i32.const 188
i32.const 191
i32.const 2
call $~lib/env/abort
unreachable
@ -381,7 +381,7 @@
if
i32.const 0
i32.const 136
i32.const 189
i32.const 192
i32.const 2
call $~lib/env/abort
unreachable
@ -3807,7 +3807,7 @@
if
i32.const 0
i32.const 136
i32.const 223
i32.const 226
i32.const 57
call $~lib/env/abort
unreachable
@ -3989,62 +3989,64 @@
i32.store offset=4
local.get $0
)
(func $~lib/array/Array<String>#resize (; 41 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(local $2 i32)
(func $~lib/array/ensureLength (; 41 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
(local $7 i32)
local.get $0
i32.load
local.set $2
local.get $2
call $~lib/arraybuffer/ArrayBuffer#get:byteLength
i32.const 2
i32.shr_u
local.set $3
local.get $1
local.get $3
call $~lib/arraybuffer/ArrayBuffer#get:byteLength
local.get $2
i32.shr_u
local.set $4
local.get $1
local.get $4
i32.gt_u
if
local.get $1
i32.const 268435454
global.get $~lib/runtime/MAX_BYTELENGTH
local.get $2
i32.shr_u
i32.gt_u
if
i32.const 0
i32.const 1440
i32.const 37
i32.const 41
i32.const 12
i32.const 59
call $~lib/env/abort
unreachable
end
local.get $1
i32.const 2
local.get $2
i32.shl
local.set $4
local.set $5
block $~lib/runtime/REALLOCATE|inlined.0 (result i32)
local.get $2
local.set $5
local.get $4
local.get $3
local.set $6
local.get $5
local.set $7
local.get $6
local.get $7
call $~lib/runtime/doReallocate
end
local.set $6
local.get $6
local.get $2
local.set $7
local.get $7
local.get $3
i32.ne
if
local.get $0
local.get $6
local.get $7
i32.store
local.get $0
local.get $6
local.get $7
i32.store offset=4
local.get $0
local.get $6
local.get $4
local.get $7
local.get $5
i32.add
i32.store offset=8
end
@ -4055,7 +4057,8 @@
local.get $1
i32.const 1
i32.add
call $~lib/array/Array<String>#resize
i32.const 2
call $~lib/array/ensureLength
local.get $0
i32.load offset=4
local.get $1
@ -4087,7 +4090,7 @@
if
i32.const 0
i32.const 136
i32.const 196
i32.const 199
i32.const 2
call $~lib/env/abort
unreachable
@ -4099,7 +4102,7 @@
local.get $1
call $~lib/runtime/assertRegistered
)
(func $~lib/runtime/LINK<usize,Array<String>> (; 45 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
(func $~lib/runtime/LINK<String,Array<String>> (; 45 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32)
local.get $0
local.get $1
call $~lib/runtime/doLink
@ -4113,7 +4116,8 @@
local.set $2
local.get $0
local.get $2
call $~lib/array/Array<String>#resize
i32.const 2
call $~lib/array/ensureLength
local.get $0
local.get $2
i32.store offset=12
@ -4249,6 +4253,8 @@
i32.const 2
i32.shl
i32.add
local.get $8
i32.store
block $~lib/runtime/REGISTER<String>|inlined.7 (result i32)
local.get $8
local.set $9
@ -4256,10 +4262,8 @@
i32.const 1
call $~lib/runtime/doRegister
end
i32.store
local.get $8
local.get $3
call $~lib/runtime/LINK<usize,Array<String>>
call $~lib/runtime/LINK<String,Array<String>>
end
local.get $7
i32.const 1

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff