From 623597c23aabc9508de88c90b79bbcd77f11fede Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Wed, 11 Apr 2018 23:35:19 +0200 Subject: [PATCH] Make the transition to ArrayBuffer backed Arrays (#70) * Traverse base classes when resolving overloads * Implement preliminary TypedArray accessors * Extract decorator flags from common flags to make space * Add '**' overload * Implement basic explicit inlining * Support inlining of instance methods * Reduce number of required locals when inlining * Implement inlining of operator overloads * Fix issues when inlining generic functions --- src/ast.ts | 46 +- src/builtins.ts | 6 +- src/compiler.ts | 836 ++-- src/diagnosticMessages.generated.ts | 12 +- src/diagnosticMessages.json | 6 +- src/diagnostics.ts | 12 +- src/extra/ast.ts | 22 +- src/module.ts | 39 + src/parser.ts | 20 +- src/program.ts | 654 +-- src/tokenizer.ts | 4 +- src/types.ts | 18 +- std/assembly.d.ts | 6 +- std/assembly/array.ts | 355 +- std/assembly/arraybuffer.ts | 9 + std/assembly/internal/array.ts | 54 +- std/assembly/internal/arraybuffer.ts | 38 +- std/assembly/internal/typedarray.ts | 49 +- std/assembly/typedarray.ts | 40 + tests/allocators/index.js | 2 +- tests/compiler/if.optimized.wat | 10 +- tests/compiler/if.untouched.wat | 10 +- tests/compiler/inlining.optimized.wat | 188 +- tests/compiler/inlining.ts | 66 + tests/compiler/inlining.untouched.wat | 386 +- tests/compiler/std/array-access.optimized.wat | 45 +- tests/compiler/std/array-access.untouched.wat | 243 +- tests/compiler/std/array.optimized.wat | 2923 +++++++------ tests/compiler/std/array.ts | 266 +- tests/compiler/std/array.untouched.wat | 3828 ++++++++++------- tests/compiler/std/arraybuffer.optimized.wat | 43 +- tests/compiler/std/arraybuffer.untouched.wat | 43 +- tests/compiler/std/math.optimized.wat | 10 +- tests/compiler/std/math.untouched.wat | 10 +- .../std/operator-overloading.optimized.wat | 1807 +++++++- tests/compiler/std/operator-overloading.ts | 41 +- .../std/operator-overloading.untouched.wat | 2067 ++++++++- tests/compiler/std/static-array.optimized.wat | 1205 ++++-- tests/compiler/std/static-array.untouched.wat | 1529 ++++--- tests/compiler/std/string.optimized.wat | 10 +- tests/compiler/std/string.untouched.wat | 10 +- tests/compiler/std/typedarray.optimized.wat | 496 ++- tests/compiler/std/typedarray.ts | 17 + tests/compiler/std/typedarray.untouched.wat | 706 ++- 44 files changed, 13242 insertions(+), 4945 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index ea05df69..e16be6bb 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -198,32 +198,9 @@ export abstract class Node { stmt.range = range; stmt.name = expression; expression.parent = stmt; stmt.arguments = args; if (args) setParent(args, stmt); - if (expression.kind == NodeKind.IDENTIFIER) { - switch ((expression).text) { - case "global": { - stmt.decoratorKind = DecoratorKind.GLOBAL; - break; - } - case "operator": { - stmt.decoratorKind = DecoratorKind.OPERATOR; - break; - } - case "unmanaged": { - stmt.decoratorKind = DecoratorKind.UNMANAGED; - break; - } - case "offset": { - stmt.decoratorKind = DecoratorKind.OFFSET; - break; - } - default: { - stmt.decoratorKind = DecoratorKind.CUSTOM; - break; - } - } - } else { - stmt.decoratorKind = DecoratorKind.CUSTOM; - } + stmt.decoratorKind = expression.kind == NodeKind.IDENTIFIER + ? stringToDecoratorKind((expression).text) + : DecoratorKind.CUSTOM; return stmt; } @@ -1075,7 +1052,22 @@ export enum DecoratorKind { GLOBAL, OPERATOR, UNMANAGED, - OFFSET + SEALED, + INLINE, + PRECOMPUTE +} + +/** Returns the decorator kind represented by the specified string. */ +export function stringToDecoratorKind(str: string): DecoratorKind { + switch (str) { + case "global": return DecoratorKind.GLOBAL; + case "operator": return DecoratorKind.OPERATOR; + case "unmanaged": return DecoratorKind.UNMANAGED; + case "sealed": return DecoratorKind.SEALED; + case "inline": return DecoratorKind.INLINE; + case "precompute": return DecoratorKind.PRECOMPUTE; + default: return DecoratorKind.CUSTOM; + } } /** Represents a decorator. */ diff --git a/src/builtins.ts b/src/builtins.ts index 892cbaa6..f90f816e 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -43,7 +43,8 @@ import { Global, FunctionPrototype, Class, - Field + Field, + OperatorKind } from "./program"; /** Compiles a get of a built-in global. */ @@ -146,7 +147,7 @@ export function compileCall( compiler.currentType = Type.bool; if (!type) return module.createUnreachable(); let classType = type.classReference; - return classType != null && classType.prototype.fnIndexedGet != null + return classType != null && classType.lookupOverload(OperatorKind.INDEXED_GET) != null ? module.createI32(1) : module.createI32(0); } @@ -1738,6 +1739,7 @@ export function compileCall( DiagnosticCode.Expected_0_type_arguments_but_got_1, reportNode.range, "1", typeArguments ? typeArguments.length.toString(10) : "0" ); + return module.createUnreachable(); } let byteSize = (typeArguments)[0].byteSize; let alignLog2: i32; diff --git a/src/compiler.ts b/src/compiler.ts index 19b1964d..0c7f8d74 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6,7 +6,8 @@ import { compileCall as compileBuiltinCall, compileGetConstant as compileBuiltinGetConstant, - compileAllocate as compileBuiltinAllocate + compileAllocate as compileBuiltinAllocate, + compileAbort } from "./builtins"; import { @@ -47,6 +48,8 @@ import { CommonFlags, ConstantValueKind, Flow, + OperatorKind, + DecoratorFlags, PATH_DELIMITER, INNER_DELIMITER @@ -376,6 +379,7 @@ export class Compiler extends DiagnosticEmitter { } break; } + case NodeKind.INTERFACEDECLARATION: break; case NodeKind.ENUMDECLARATION: { if (noTreeShaking || (isEntry && statement.is(CommonFlags.EXPORT))) { this.compileEnumDeclaration(statement); @@ -1533,19 +1537,33 @@ export class Compiler extends DiagnosticEmitter { } compileReturnStatement(statement: ReturnStatement): ExpressionRef { + var module = this.module; var currentFunction = this.currentFunction; var expression: ExpressionRef = 0; + var flow = currentFunction.flow; + + // Remember that this flow returns + flow.set(FlowFlags.RETURNS); + + // When inlining, break to the end of the inlined function's block + if (flow.is(FlowFlags.INLINE_CONTEXT)) { + if (statement.value) { + expression = this.compileExpression( + statement.value, + assert(flow.returnType) + ); + } + return module.createBreak(assert(flow.returnLabel), 0, expression); + } + + // Otherwise return as usual if (statement.value) { expression = this.compileExpression( statement.value, - currentFunction.signature.returnType + flow.returnType ); } - - // Remember that this flow returns - currentFunction.flow.set(FlowFlags.RETURNS); - - return this.module.createReturn(expression); + return module.createReturn(expression); } compileSwitchStatement(statement: SwitchStatement): ExpressionRef { @@ -1654,7 +1672,7 @@ export class Compiler extends DiagnosticEmitter { flow.set(FlowFlags.RETURNS); // TODO: requires exception-handling spec. - return this.module.createUnreachable(); + return compileAbort(this, null, statement); } compileTryStatement(statement: TryStatement): ExpressionRef { @@ -1696,6 +1714,7 @@ export class Compiler extends DiagnosticEmitter { // other variables become locals var initializers = new Array(); + var flow = this.currentFunction.flow; for (let i = 0; i < numDeclarations; ++i) { let declaration = declarations[i]; let name = declaration.name.text; @@ -1704,7 +1723,7 @@ export class Compiler extends DiagnosticEmitter { if (declaration.type) { type = program.resolveType( // reports declaration.type, - currentFunction.contextualTypeArguments + flow.contextualTypeArguments ); if (!type) continue; if (declaration.initializer) { @@ -1792,8 +1811,12 @@ export class Compiler extends DiagnosticEmitter { } } if (!isInlined) { - if (declaration.isAny(CommonFlags.LET | CommonFlags.CONST)) { // here: not top-level - currentFunction.flow.addScopedLocal(type, name, declaration); // reports + let flow = currentFunction.flow; + if ( + declaration.isAny(CommonFlags.LET | CommonFlags.CONST) || + flow.is(FlowFlags.INLINE_CONTEXT) + ) { // here: not top-level + flow.addScopedLocal(type, name, declaration); // reports } else { currentFunction.addLocal(type, name, declaration); // reports } @@ -1991,6 +2014,7 @@ export class Compiler extends DiagnosticEmitter { case NodeKind.FALSE: case NodeKind.NULL: case NodeKind.THIS: + case NodeKind.SUPER: case NodeKind.TRUE: { expr = this.compileIdentifierExpression( expression, @@ -2289,7 +2313,7 @@ export class Compiler extends DiagnosticEmitter { compileAssertionExpression(expression: AssertionExpression, contextualType: Type): ExpressionRef { var toType = this.program.resolveType( // reports expression.toType, - this.currentFunction.contextualTypeArguments + this.currentFunction.flow.contextualTypeArguments ); if (!toType) return this.module.createUnreachable(); return this.compileExpression(expression.expression, toType, ConversionKind.EXPLICIT); @@ -2326,6 +2350,17 @@ export class Compiler extends DiagnosticEmitter { case Token.LESSTHAN: { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.LT); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { @@ -2367,16 +2402,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.LtU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnLessThan; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.LtU64 @@ -2414,6 +2440,17 @@ export class Compiler extends DiagnosticEmitter { case Token.GREATERTHAN: { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.GT); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { @@ -2455,16 +2492,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.GtU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnGreaterThan; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.GtU64 @@ -2502,6 +2530,17 @@ export class Compiler extends DiagnosticEmitter { case Token.LESSTHAN_EQUALS: { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.LE); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { @@ -2543,16 +2582,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.LeU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnLessThanEquals; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.LeU64 @@ -2590,6 +2620,17 @@ export class Compiler extends DiagnosticEmitter { case Token.GREATERTHAN_EQUALS: { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.GE); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, true)) { @@ -2631,16 +2672,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.GeU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnGreaterThanEquals; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.GeU64 @@ -2685,6 +2717,18 @@ export class Compiler extends DiagnosticEmitter { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + if (operator == Token.EQUALS_EQUALS) { // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.EQ); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { @@ -2709,18 +2753,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.EqI32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload if operator is "==" - if (operator == Token.EQUALS_EQUALS && this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnEquals; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - assert(this.currentType == Type.bool); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -2761,6 +2794,18 @@ export class Compiler extends DiagnosticEmitter { case Token.EXCLAMATION_EQUALS: { leftExpr = this.compileExpressionRetainType(left, contextualType); leftType = this.currentType; + + if (operator == Token.EXCLAMATION_EQUALS) { // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.NE); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + } + rightExpr = this.compileExpressionRetainType(right, leftType); rightType = this.currentType; if (commonType = Type.commonCompatible(leftType, rightType, false)) { @@ -2785,17 +2830,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.NeI32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: {// check operator overload if operator is "!=" - if (operator == Token.EXCLAMATION_EQUALS && this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnNotEquals; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -2841,15 +2876,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.ADD); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -2879,17 +2925,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.AddI32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnConcat; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -2932,15 +2968,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.SUB); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -2970,17 +3017,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.SubI32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnSubtract; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3023,15 +3060,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.MUL); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3061,17 +3109,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.MulI32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnMultiply; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3114,6 +3152,18 @@ export class Compiler extends DiagnosticEmitter { contextualType, true // must be wrapped ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.POW); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + let instance: Function | null; // Mathf.pow if lhs is f32 (result is f32) @@ -3196,15 +3246,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, true // TODO: when can division remain unwrapped? does it overflow? ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.DIV); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3251,16 +3312,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.DivU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnDivide; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.DivU64 @@ -3301,15 +3353,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, true // TODO: when can remainder remain unwrapped? does it overflow? ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.REM); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3356,16 +3419,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.RemU32, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnFractional; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through + case TypeKind.USIZE: { expr = module.createBinary( this.options.isWasm64 ? BinaryOp.RemU64 @@ -3642,15 +3696,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overloadd + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.AND); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3684,17 +3749,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.AndI64, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnBitwiseAnd; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3724,15 +3779,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.OR); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3766,17 +3832,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.OrI64, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnBitwiseOr; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3806,15 +3862,26 @@ export class Compiler extends DiagnosticEmitter { contextualType, false // retains low bits of small integers ); + leftType = this.currentType; + + // check operator overload + let classReference = leftType.classReference; + if (classReference) { + let overload = classReference.lookupOverload(OperatorKind.XOR); + if (overload) { + expr = this.compileBinaryOverload(overload, left, right, expression); + break; + } + } + if (compound) { rightExpr = this.compileExpression( right, - this.currentType, + leftType, ConversionKind.IMPLICIT, false // ^ ); } else { - leftType = this.currentType; rightExpr = this.compileExpressionRetainType( right, leftType, @@ -3848,17 +3915,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.createBinary(BinaryOp.XorI64, leftExpr, rightExpr); break; } - case TypeKind.USIZE: { // check operator overload - if (this.currentType.is(TypeFlags.REFERENCE)) { - let classInstance = assert(this.currentType.classReference); - let operatorName = classInstance.prototype.fnBitwiseXor; - if (operatorName != null) { - expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr); - break; - } - } - // fall-through - } + case TypeKind.USIZE: case TypeKind.ISIZE: { expr = module.createBinary( this.options.isWasm64 @@ -3995,18 +4052,55 @@ export class Compiler extends DiagnosticEmitter { : expr; } - compileOperatorOverload( - classInstance: Class, - operatorName: string, - leftExpr: ExpressionRef, - rightExpr: ExpressionRef + compileUnaryOverload( + operatorInstance: Function, + value: Expression, + reportNode: Node ): ExpressionRef { - var classPrototype = classInstance.prototype; - var operatorPrototype = assert(assert(classPrototype.members).get(operatorName)); - assert(operatorPrototype.kind == ElementKind.FUNCTION_PROTOTYPE); - var operatorInstance = (operatorPrototype).resolve(); - if (!operatorInstance) return this.module.createUnreachable(); - return this.makeCallDirect(operatorInstance, [ leftExpr, rightExpr ]); + // checks and recompiles the argument according to its actual annotated type + var argumentExpressions: Expression[]; + var thisArg: ExpressionRef = 0; + if (operatorInstance.is(CommonFlags.INSTANCE)) { + let classElement = assert(operatorInstance.memberOf); + assert(classElement.kind == ElementKind.CLASS); + thisArg = this.compileExpression(value, (classElement).type); + argumentExpressions = []; + } else { + argumentExpressions = [ value ]; + } + return this.compileCallDirect( + operatorInstance, + argumentExpressions, + reportNode, + thisArg, + operatorInstance.hasDecorator(DecoratorFlags.INLINE) + ); + } + + compileBinaryOverload( + operatorInstance: Function, + left: Expression, + right: Expression, + reportNode: Node + ): ExpressionRef { + // checks and recompiles the arguments according to their actual annotated types + var argumentExpressions: Expression[]; + var thisArg: ExpressionRef = 0; + if (operatorInstance.is(CommonFlags.INSTANCE)) { + let classElement = assert(operatorInstance.memberOf); + assert(classElement.kind == ElementKind.CLASS); + thisArg = this.compileExpression(left, (classElement).type); + argumentExpressions = [ right ]; + } else { + argumentExpressions = [ left, right ]; + } + return this.compileCallDirect( + operatorInstance, + argumentExpressions, + reportNode, + thisArg, + operatorInstance.hasDecorator(DecoratorFlags.INLINE) + ); } compileAssignment(expression: Expression, valueExpression: Expression, contextualType: Type): ExpressionRef { @@ -4047,18 +4141,16 @@ export class Compiler extends DiagnosticEmitter { } case ElementKind.CLASS: { if (program.resolvedElementExpression) { // indexed access - let indexedGetPrototype = (target).getIndexedGet(); - if (indexedGetPrototype) { - let indexedGetInstance = indexedGetPrototype.resolve(); // reports - if (!indexedGetInstance) return this.module.createUnreachable(); - elementType = indexedGetInstance.signature.returnType; - break; + let indexedGet = (target).lookupOverload(OperatorKind.INDEXED_GET); + if (!indexedGet) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + expression.range, (target).internalName + ); + return this.module.createUnreachable(); } - this.error( - DiagnosticCode.Index_signature_is_missing_in_type_0, - expression.range, (target).toString() - ); - return this.module.createUnreachable(); + elementType = indexedGet.signature.returnType; + break; } // fall-through } @@ -4238,61 +4330,56 @@ export class Compiler extends DiagnosticEmitter { case ElementKind.CLASS: { let elementExpression = this.program.resolvedElementExpression; if (elementExpression) { - let indexedGetPrototype = (target).getIndexedGet(); - if (indexedGetPrototype) { - let indexedGetInstance = indexedGetPrototype.resolve(); // reports - if (!indexedGetInstance) return module.createUnreachable(); - let indexedSetPrototype = (target).getIndexedSet(); - if (!indexedSetPrototype) { - this.error( - DiagnosticCode.Index_signature_in_type_0_only_permits_reading, - expression.range, target.internalName - ); - this.currentType = tee ? indexedGetInstance.signature.returnType : Type.void; - return module.createUnreachable(); - } - let indexedSetInstance = indexedSetPrototype.resolve(); // reports - if (!indexedSetInstance) return module.createUnreachable(); - let targetType = (target).type; - let thisExpression = assert(this.program.resolvedThisExpression); - let thisExpr = this.compileExpressionRetainType( - thisExpression, - this.options.usizeType - ); - let elementExpr = this.compileExpression( - elementExpression, - Type.i32 - ); - if (tee) { - let tempLocalTarget = this.currentFunction.getTempLocal(targetType); - let tempLocalElement = this.currentFunction.getAndFreeTempLocal(this.currentType); - let returnType = indexedGetInstance.signature.returnType; - this.currentFunction.freeTempLocal(tempLocalTarget); - return module.createBlock(null, [ - this.makeCallDirect(indexedSetInstance, [ - module.createTeeLocal(tempLocalTarget.index, thisExpr), - module.createTeeLocal(tempLocalElement.index, elementExpr), - valueWithCorrectType - ]), - this.makeCallDirect(indexedGetInstance, [ - module.createGetLocal(tempLocalTarget.index, tempLocalTarget.type.toNativeType()), - module.createGetLocal(tempLocalElement.index, tempLocalElement.type.toNativeType()) - ]) - ], returnType.toNativeType()); - } else { - return this.makeCallDirect(indexedSetInstance, [ - thisExpr, - elementExpr, - valueWithCorrectType - ]); - } - } else { + let indexedGet = (target).lookupOverload(OperatorKind.INDEXED_GET); + if (!indexedGet) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, expression.range, target.internalName ); return module.createUnreachable(); } + let indexedSet = (target).lookupOverload(OperatorKind.INDEXED_SET); + if (!indexedSet) { + this.error( + DiagnosticCode.Index_signature_in_type_0_only_permits_reading, + expression.range, target.internalName + ); + this.currentType = tee ? indexedGet.signature.returnType : Type.void; + return module.createUnreachable(); + } + let targetType = (target).type; + let thisExpression = assert(this.program.resolvedThisExpression); + let thisExpr = this.compileExpressionRetainType( + thisExpression, + this.options.usizeType + ); + let elementExpr = this.compileExpression( + elementExpression, + Type.i32 + ); + if (tee) { + let tempLocalTarget = this.currentFunction.getTempLocal(targetType); + let tempLocalElement = this.currentFunction.getAndFreeTempLocal(this.currentType); + let returnType = indexedGet.signature.returnType; + this.currentFunction.freeTempLocal(tempLocalTarget); + return module.createBlock(null, [ + this.makeCallDirect(indexedSet, [ + module.createTeeLocal(tempLocalTarget.index, thisExpr), + module.createTeeLocal(tempLocalElement.index, elementExpr), + valueWithCorrectType + ]), + this.makeCallDirect(indexedGet, [ + module.createGetLocal(tempLocalTarget.index, tempLocalTarget.type.toNativeType()), + module.createGetLocal(tempLocalElement.index, tempLocalElement.type.toNativeType()) + ]) + ], returnType.toNativeType()); + } else { + return this.makeCallDirect(indexedSet, [ + thisExpr, + elementExpr, + valueWithCorrectType + ]); + } } // fall-through } @@ -4325,7 +4412,7 @@ export class Compiler extends DiagnosticEmitter { prototype, prototype.resolveBuiltinTypeArguments( expression.typeArguments, - currentFunction.contextualTypeArguments + currentFunction.flow.contextualTypeArguments ), expression.arguments, contextualType, @@ -4340,25 +4427,28 @@ export class Compiler extends DiagnosticEmitter { } return expr; - // otherwise compile to a call + // otherwise compile to a call (and maybe inline) } else { let instance = prototype.resolveUsingTypeArguments( // reports expression.typeArguments, - currentFunction.contextualTypeArguments, + currentFunction.flow.contextualTypeArguments, expression ); if (!instance) return module.createUnreachable(); + let thisExpr: ExpressionRef = 0; if (instance.is(CommonFlags.INSTANCE)) { - let thisExpression = assert(this.program.resolvedThisExpression); - let thisExpr = this.compileExpressionRetainType( - thisExpression, + thisExpr = this.compileExpressionRetainType( + assert(this.program.resolvedThisExpression), this.options.usizeType ); - return this.compileCallDirect(instance, expression.arguments, expression, thisExpr); - } else { - // if static, resolvedThisExpression is the ClassPrototype - return this.compileCallDirect(instance, expression.arguments, expression); } + return this.compileCallDirect( + instance, + expression.arguments, + expression, + thisExpr, + instance.hasDecorator(DecoratorFlags.INLINE) + ); } } @@ -4497,7 +4587,8 @@ export class Compiler extends DiagnosticEmitter { instance: Function, argumentExpressions: Expression[], reportNode: Node, - thisArg: ExpressionRef = 0 + thisArg: ExpressionRef = 0, + inline: bool = false ): ExpressionRef { var numArguments = argumentExpressions.length; var signature = instance.signature; @@ -4511,6 +4602,13 @@ export class Compiler extends DiagnosticEmitter { return this.module.createUnreachable(); } + // Inline if explicitly requested + if (inline) { + assert(!instance.is(CommonFlags.TRAMPOLINE)); // doesn't make sense + return this.compileCallInlineUnchecked(instance, argumentExpressions, reportNode, thisArg); + } + + // Otherwise compile to just a call var numArgumentsInclThis = thisArg ? numArguments + 1 : numArguments; var operands = new Array(numArgumentsInclThis); var index = 0; @@ -4529,6 +4627,102 @@ export class Compiler extends DiagnosticEmitter { return this.makeCallDirect(instance, operands); } + // Depends on being pre-checked in compileCallDirect + private compileCallInlineUnchecked( + instance: Function, + argumentExpressions: Expression[], + reportNode: Node, + thisArg: ExpressionRef = 0 + ): ExpressionRef { + var numArguments = argumentExpressions.length; + var signature = instance.signature; + var currentFunction = this.currentFunction; + var module = this.module; + var declaration = instance.prototype.declaration; + + // Create an empty child flow with its own scope and mark it for inlining + var previousFlow = currentFunction.flow; + var returnLabel = instance.internalName + "|inlined." + (instance.nextInlineId++).toString(10); + var returnType = instance.signature.returnType; + var flow = Flow.create(currentFunction); + flow.set(FlowFlags.INLINE_CONTEXT); + flow.returnLabel = returnLabel; + flow.returnType = returnType; + flow.contextualTypeArguments = instance.contextualTypeArguments; + + // Convert provided call arguments to temporary locals. It is important that these are compiled + // here, with their respective locals being blocked. There is no 'makeCallInline'. + var body = []; + if (thisArg) { + let classElement = assert(instance.memberOf); + assert(classElement.kind == ElementKind.CLASS); + let thisLocal = flow.addScopedLocal((classElement).type, "this"); + body.push( + module.createSetLocal(thisLocal.index, thisArg) + ); + } + var parameterTypes = signature.parameterTypes; + for (let i = 0; i < numArguments; ++i) { + let argumentLocal = flow.addScopedLocal(parameterTypes[i], signature.getParameterName(i)); + body.push( + module.createSetLocal(argumentLocal.index, + this.compileExpression( + argumentExpressions[i], + parameterTypes[i] + ) + ) + ); + } + + // Compile optional parameter initializers in the scope of the inlined flow + currentFunction.flow = flow; + var numParameters = signature.parameterTypes.length; + for (let i = numArguments; i < numParameters; ++i) { + let argumentLocal = flow.addScopedLocal(parameterTypes[i], signature.getParameterName(i)); + body.push( + module.createSetLocal(argumentLocal.index, + this.compileExpression( + assert(declaration.signature.parameterTypes[i].initializer), + parameterTypes[i] + ) + ) + ); + } + + // Compile the called function's body in the scope of the inlined flow + var bodyStatement = assert(declaration.body); + if (bodyStatement.kind == NodeKind.BLOCK) { // it's ok to unwrap the block here + let statements = (bodyStatement).statements; + for (let i = 0, k = statements.length; i < k; ++i) { + body.push(this.compileStatement(statements[i])); + } + } else { + body.push(this.compileStatement(bodyStatement)); + } + + // Free any new scoped locals and reset to the original flow + var scopedLocals = flow.scopedLocals; + if (scopedLocals) { + for (let scopedLocal of scopedLocals.values()) { + currentFunction.freeTempLocal(scopedLocal); + } + flow.scopedLocals = null; + } + flow.finalize(); + this.currentFunction.flow = previousFlow; + this.currentType = returnType; + + // Check that all branches return + if (returnType != Type.void && !flow.is(FlowFlags.RETURNS)) { + this.error( + DiagnosticCode.A_function_whose_declared_type_is_not_void_must_return_a_value, + declaration.signature.returnType.range + ); + return module.createUnreachable(); + } + return module.createBlock(returnLabel, body, returnType.toNativeType()); + } + /** Gets the trampoline for the specified function. */ ensureTrampoline(original: Function): Function { // A trampoline is a function that takes a fixed amount of operands with some of them possibly @@ -4580,9 +4774,14 @@ export class Compiler extends DiagnosticEmitter { var trampolineSignature = new Signature(originalParameterTypes, commonReturnType, commonThisType); var trampolineName = originalName + "|trampoline"; trampolineSignature.requiredParameters = maxArguments; - trampoline = new Function(original.prototype, trampolineName, trampolineSignature, original.memberOf); + trampoline = new Function( + original.prototype, + trampolineName, + trampolineSignature, + original.memberOf, + original.contextualTypeArguments + ); trampoline.set(original.flags | CommonFlags.TRAMPOLINE | CommonFlags.COMPILED); - trampoline.contextualTypeArguments = original.contextualTypeArguments; original.trampoline = trampoline; // compile initializers of omitted arguments in scope of the trampoline function @@ -4805,18 +5004,16 @@ export class Compiler extends DiagnosticEmitter { if (!target) return this.module.createUnreachable(); switch (target.kind) { case ElementKind.CLASS: { - let indexedGetPrototype = (target).getIndexedGet(); - if (!indexedGetPrototype) { + let indexedGet = (target).lookupOverload(OperatorKind.INDEXED_GET); + if (!indexedGet) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, expression.expression.range, (target).internalName ); return this.module.createUnreachable(); } - let indexedGetInstance = indexedGetPrototype.resolve(); // reports - if (!indexedGetInstance) return this.module.createUnreachable(); let thisArg = this.compileExpression(expression.expression, (target).type); - return this.compileCallDirect(indexedGetInstance, [ + return this.compileCallDirect(indexedGet, [ expression.elementExpression ], expression, thisArg); } @@ -4839,13 +5036,16 @@ export class Compiler extends DiagnosticEmitter { this.program, simpleName, currentFunction.internalName + INNER_DELIMITER + simpleName, - declaration + declaration, + null, + DecoratorFlags.NONE ); + var flow = currentFunction.flow; var instance = this.compileFunctionUsingTypeArguments( prototype, [], - currentFunction.contextualTypeArguments, - currentFunction.flow, + flow.contextualTypeArguments, + flow, declaration ); if (!instance) return this.module.createUnreachable(); @@ -4890,12 +5090,19 @@ export class Compiler extends DiagnosticEmitter { } case NodeKind.THIS: { let currentFunction = this.currentFunction; + let flow = currentFunction.flow; + if (flow.is(FlowFlags.INLINE_CONTEXT)) { + let scopedThis = flow.getScopedLocal("this"); + if (scopedThis) { + this.currentType = scopedThis.type; + return module.createGetLocal(scopedThis.index, scopedThis.type.toNativeType()); + } + } if (currentFunction.is(CommonFlags.INSTANCE)) { let parent = assert(currentFunction.memberOf); assert(parent.kind == ElementKind.CLASS); let thisType = (parent).type; if (currentFunction.is(CommonFlags.CONSTRUCTOR)) { - let flow = currentFunction.flow; if (!flow.is(FlowFlags.ALLOCATES)) { flow.set(FlowFlags.ALLOCATES); // must be conditional because `this` could have been provided by a derived class @@ -4917,6 +5124,18 @@ export class Compiler extends DiagnosticEmitter { } case NodeKind.SUPER: { let currentFunction = this.currentFunction; + let flow = currentFunction.flow; + if (flow.is(FlowFlags.INLINE_CONTEXT)) { + let scopedThis = flow.getScopedLocal("this"); + if (scopedThis) { + let scopedThisClass = assert(scopedThis.type.classReference); + let base = scopedThisClass.base; + if (base) { + this.currentType = base.type; + return module.createGetLocal(scopedThis.index, base.type.toNativeType()); + } + } + } if (currentFunction.is(CommonFlags.INSTANCE)) { let parent = assert(currentFunction.memberOf); assert(parent.kind == ElementKind.CLASS); @@ -4988,7 +5207,7 @@ export class Compiler extends DiagnosticEmitter { case ElementKind.FUNCTION_PROTOTYPE: { let instance = (target).resolve( null, - this.currentFunction.contextualTypeArguments + this.currentFunction.flow.contextualTypeArguments ); if (!(instance && this.compileFunction(instance))) return module.createUnreachable(); let index = this.ensureFunctionTableEntry(instance); @@ -5182,29 +5401,29 @@ export class Compiler extends DiagnosticEmitter { var arrayType = (arrayPrototype).resolve([ elementType ]); if (!arrayType) return module.createUnreachable(); - var elementSize = expressions.length; + var elementCount = expressions.length; var nativeType = elementType.toNativeType(); var values: usize; - var memorySize: usize; + var byteLength: usize; switch (nativeType) { case NativeType.I32: { - values = changetype(new Int32Array(elementSize)); - memorySize = elementSize * 4; + values = changetype(new Int32Array(elementCount)); + byteLength = elementCount * 4; break; } case NativeType.I64: { - values = changetype(new Array(elementSize)); - memorySize = elementSize * 8; + values = changetype(new Array(elementCount)); + byteLength = elementCount * 8; break; } case NativeType.F32: { - values = changetype(new Float32Array(elementSize)); - memorySize = elementSize * 4; + values = changetype(new Float32Array(elementCount)); + byteLength = elementCount * 4; break; } case NativeType.F64: { - values = changetype(new Float64Array(elementSize)); - memorySize = elementSize * 8; + values = changetype(new Float64Array(elementCount)); + byteLength = elementCount * 8; break; } default: { @@ -5218,9 +5437,9 @@ export class Compiler extends DiagnosticEmitter { } // precompute value expressions - var exprs = new Array(elementSize); + var exprs = new Array(elementCount); var expr: BinaryenExpressionRef; - for (let i = 0; i < elementSize; ++i) { + for (let i = 0; i < elementCount; ++i) { exprs[i] = expressions[i] ? this.compileExpression(expressions[i], elementType) : elementType.toNativeZero(module); @@ -5260,50 +5479,58 @@ export class Compiler extends DiagnosticEmitter { } var usizeTypeSize = this.options.usizeType.byteSize; - var headerSize = usizeTypeSize + 4 + 4; // memory + capacity + length if (isStatic) { - let buffer = new Uint8Array(headerSize + memorySize); - let segment = this.addMemorySegment(buffer); + // Create a combined static memory segment composed of: + // Array struct + ArrayBuffer struct + aligned ArrayBuffer data - // make header + let arraySize = usizeTypeSize + 4; // buffer_ & length_ + let bufferHeaderSize = (4 + 7) & ~7; // aligned byteLength (8) + let bufferTotalSize = 1 << (32 - clz(byteLength + bufferHeaderSize - 1)); // see internals + let data = new Uint8Array(arraySize + bufferTotalSize); + let segment = this.addMemorySegment(data); let offset = 0; + + // write Array struct if (usizeTypeSize == 8) { - writeI64(i64_add(segment.offset, i64_new(headerSize)), buffer, 0); // memory + writeI64(i64_add(segment.offset, i64_new(arraySize)), data, offset); // buffer_ @ segment[arSize] + offset += 8; } else { assert(i64_high(segment.offset) == 0); - writeI32(i64_low(segment.offset) + headerSize, buffer, 0); // memory + writeI32(i64_low(segment.offset) + arraySize, data, offset); // buffer_ @ segment[arSize] + offset += 4; } - offset += usizeTypeSize; - writeI32(elementSize, buffer, offset); // capacity + writeI32(elementCount, data, offset); // length_ offset += 4; - writeI32(elementSize, buffer, offset); // length - offset += 4; - assert(offset == headerSize); + assert(offset == arraySize); - // make memory + // write ArrayBuffer struct + writeI32(byteLength, data, offset); + offset += bufferHeaderSize; // incl. alignment + + // write ArrayBuffer data switch (nativeType) { case NativeType.I32: { - for (let i = 0; i < elementSize; ++i) { - writeI32(changetype(values)[i], buffer, offset); offset += 4; + for (let i = 0; i < elementCount; ++i) { + writeI32(changetype(values)[i], data, offset); offset += 4; } break; } case NativeType.I64: { - for (let i = 0; i < elementSize; ++i) { - writeI64(changetype(values)[i], buffer, offset); offset += 8; + for (let i = 0; i < elementCount; ++i) { + writeI64(changetype(values)[i], data, offset); offset += 8; } break; } case NativeType.F32: { - for (let i = 0; i < elementSize; ++i) { - writeF32(changetype(values)[i], buffer, offset); offset += 4; + for (let i = 0; i < elementCount; ++i) { + writeF32(changetype(values)[i], data, offset); offset += 4; } break; } case NativeType.F64: { - for (let i = 0; i < elementSize; ++i) { - writeF64(changetype(values)[i], buffer, offset); offset += 8; + for (let i = 0; i < elementCount; ++i) { + writeF64(changetype(values)[i], data, offset); offset += 8; } break; } @@ -5316,7 +5543,8 @@ export class Compiler extends DiagnosticEmitter { return module.createUnreachable(); } } - assert(offset == headerSize + memorySize); + assert(offset <= arraySize + bufferTotalSize); + this.currentType = arrayType.type; return usizeTypeSize == 8 ? module.createI64( diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index afa45d8e..07010fe9 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -16,11 +16,13 @@ export enum DiagnosticCode { Basic_type_0_cannot_be_nullable = 204, Cannot_export_a_mutable_global = 205, Compiling_constant_with_non_constant_initializer_as_mutable = 206, - Structs_cannot_extend_classes_and_vice_versa = 207, - Structs_cannot_implement_interfaces = 208, + Unmanaged_classes_cannot_extend_managed_classes_and_vice_versa = 207, + Unmanaged_classes_cannot_implement_interfaces = 208, Invalid_regular_expression_flags = 209, Implementation_0_must_match_the_signature_1 = 210, Class_0_is_sealed_and_cannot_be_extended = 211, + Decorator_0_is_not_valid_here = 212, + Duplicate_decorator = 213, Unterminated_string_literal = 1002, Identifier_expected = 1003, _0_expected = 1005, @@ -122,11 +124,13 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 204: return "Basic type '{0}' cannot be nullable."; case 205: return "Cannot export a mutable global."; case 206: return "Compiling constant with non-constant initializer as mutable."; - case 207: return "Structs cannot extend classes and vice-versa."; - case 208: return "Structs cannot implement interfaces."; + case 207: return "Unmanaged classes cannot extend managed classes and vice-versa."; + case 208: return "Unmanaged classes cannot implement interfaces."; case 209: return "Invalid regular expression flags."; case 210: return "Implementation '{0}' must match the signature '{1}'."; case 211: return "Class '{0}' is sealed and cannot be extended."; + case 212: return "Decorator '{0}' is not valid here."; + case 213: return "Duplicate decorator."; case 1002: return "Unterminated string literal."; case 1003: return "Identifier expected."; case 1005: return "'{0}' expected."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index f971c62d..97dbe98b 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -8,11 +8,13 @@ "Basic type '{0}' cannot be nullable.": 204, "Cannot export a mutable global.": 205, "Compiling constant with non-constant initializer as mutable.": 206, - "Structs cannot extend classes and vice-versa.": 207, - "Structs cannot implement interfaces.": 208, + "Unmanaged classes cannot extend managed classes and vice-versa.": 207, + "Unmanaged classes cannot implement interfaces.": 208, "Invalid regular expression flags.": 209, "Implementation '{0}' must match the signature '{1}'.": 210, "Class '{0}' is sealed and cannot be extended.": 211, + "Decorator '{0}' is not valid here.": 212, + "Duplicate decorator.": 213, "Unterminated string literal.": 1002, "Identifier expected.": 1003, diff --git a/src/diagnostics.ts b/src/diagnostics.ts index a1d70e1a..309799ba 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -206,12 +206,8 @@ export function formatDiagnosticContext(range: Range, useColors: bool = false): var len = text.length; var start = range.start; var end = range.end; - while (start > 0 && !isLineBreak(text.charCodeAt(start - 1))) { - start--; - } - while (end < len && !isLineBreak(text.charCodeAt(end))) { - end++; - } + while (start > 0 && !isLineBreak(text.charCodeAt(start - 1))) start--; + while (end < len && !isLineBreak(text.charCodeAt(end))) end++; var sb: string[] = [ "\n ", text.substring(start, end), @@ -225,9 +221,7 @@ export function formatDiagnosticContext(range: Range, useColors: bool = false): if (range.start == range.end) { sb.push("^"); } else { - while (start++ < range.end) { - sb.push("~"); - } + while (start++ < range.end) sb.push("~"); } if (useColors) sb.push(COLOR_RESET); return sb.join(""); diff --git a/src/extra/ast.ts b/src/extra/ast.ts index c54738cf..51e175f1 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -75,7 +75,8 @@ import { ParameterNode, ParameterKind, ExportMember, - SwitchCase + SwitchCase, + DeclarationStatement } from "../ast"; import { @@ -912,7 +913,6 @@ export class ASTBuilder { } visitFieldDeclaration(node: FieldDeclaration): void { - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -961,7 +961,6 @@ export class ASTBuilder { visitFunctionDeclaration(node: FunctionDeclaration): void { var sb = this.sb; - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -1098,7 +1097,6 @@ export class ASTBuilder { } visitInterfaceDeclaration(node: InterfaceDeclaration): void { - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -1138,7 +1136,6 @@ export class ASTBuilder { } visitMethodDeclaration(node: MethodDeclaration): void { - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -1155,7 +1152,6 @@ export class ASTBuilder { } visitNamespaceDeclaration(node: NamespaceDeclaration): void { - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -1315,7 +1311,6 @@ export class ASTBuilder { } visitVariableStatement(node: VariableStatement): void { - this.serializeBuiltinDecorators(node); var decorators = node.decorators; if (decorators) { for (let i = 0, k = decorators.length; i < k; ++i) { @@ -1398,19 +1393,6 @@ export class ASTBuilder { } } - serializeBuiltinDecorators(node: Node): void { - var sb = this.sb; - var indentLevel = this.indentLevel; - if (node.is(CommonFlags.GLOBAL)) { - sb.push("@global\n"); - indent(sb, indentLevel); - } - if (node.is(CommonFlags.UNMANAGED)) { - sb.push("@unmanaged\n"); - indent(sb, indentLevel); - } - } - serializeExternalModifiers(node: Node): void { var sb = this.sb; if (node.is(CommonFlags.EXPORT)) { diff --git a/src/module.ts b/src/module.ts index 93814164..b00407ee 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1099,6 +1099,45 @@ export class Relooper { } } +// export function hasSideEffects(expr: ExpressionRef): bool { +// switch (_BinaryenExpressionGetId(expr)) { +// case ExpressionId.GetLocal: +// case ExpressionId.GetGlobal: +// case ExpressionId.Const: +// case ExpressionId.Nop: +// case ExpressionId.Unreachable: { +// return false; +// } +// case ExpressionId.Block: { +// for (let i = 0, k = _BinaryenBlockGetNumChildren(expr); i < k; ++i) { +// if (hasSideEffects(_BinaryenBlockGetChild(expr, i))) return true; +// } +// return false; +// } +// case ExpressionId.If: { +// return hasSideEffects(_BinaryenIfGetCondition(expr)) +// || hasSideEffects(_BinaryenIfGetIfTrue(expr)) +// || hasSideEffects(_BinaryenIfGetIfFalse(expr)); +// } +// case ExpressionId.Unary: { +// return hasSideEffects(_BinaryenUnaryGetValue(expr)); +// } +// case ExpressionId.Binary: { +// return hasSideEffects(_BinaryenBinaryGetLeft(expr)) +// || hasSideEffects(_BinaryenBinaryGetRight(expr)); +// } +// case ExpressionId.Drop: { +// return hasSideEffects(_BinaryenDropGetValue(expr)); +// } +// case ExpressionId.Select: { +// return hasSideEffects(_BinaryenSelectGetIfTrue(expr)) +// || hasSideEffects(_BinaryenSelectGetIfFalse(expr)) +// || hasSideEffects(_BinaryenSelectGetCondition(expr)); +// } +// } +// return true; +// } + // helpers // can't do stack allocation here: STACKTOP is a global in WASM but a hidden variable in asm.js diff --git a/src/parser.ts b/src/parser.ts index 3b59e439..c11d2183 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -27,7 +27,6 @@ import { } from "./util"; import { - Node, NodeKind, Source, @@ -162,22 +161,9 @@ export class Parser extends DiagnosticEmitter { while (tn.skip(Token.AT)) { if (startPos < 0) startPos = tn.tokenPos; let decorator = this.parseDecorator(tn); - if (!decorator) break; - let name = decorator.name; - if (name.kind == NodeKind.IDENTIFIER) { - let text = (name).text; - if (text == "global") { - flags |= CommonFlags.GLOBAL; - continue; - } - if (text == "unmananged") { - flags |= CommonFlags.UNMANAGED; - continue; - } - if (text == "sealed") { - flags |= CommonFlags.SEALED; - continue; - } + if (!decorator) { + this.skipStatement(tn); + continue; } if (!decorators) decorators = []; decorators.push(decorator); diff --git a/src/program.ts b/src/program.ts index a985e42a..8bacbdd3 100644 --- a/src/program.ts +++ b/src/program.ts @@ -64,7 +64,8 @@ import { ParameterKind, SignatureNode, - VariableDeclaration + VariableDeclaration, + stringToDecoratorKind } from "./ast"; import { @@ -113,6 +114,51 @@ class TypeAlias { type: CommonTypeNode; } +/** Represents the kind of an operator overload. */ +export enum OperatorKind { + INVALID, + INDEXED_GET, + INDEXED_SET, + ADD, + SUB, + MUL, + DIV, + REM, + POW, + AND, + OR, + XOR, + EQ, + NE, + GT, + GE, + LT, + LE +} + +function operatorKindFromString(str: string): OperatorKind { + switch (str) { + case "[]" : return OperatorKind.INDEXED_GET; + case "[]=": return OperatorKind.INDEXED_SET; + case "+" : return OperatorKind.ADD; + case "-" : return OperatorKind.SUB; + case "*" : return OperatorKind.MUL; + case "/" : return OperatorKind.DIV; + case "%" : return OperatorKind.REM; + case "**" : return OperatorKind.POW; + case "&" : return OperatorKind.AND; + case "|" : return OperatorKind.OR; + case "^" : return OperatorKind.XOR; + case "==" : return OperatorKind.EQ; + case "!=" : return OperatorKind.NE; + case ">" : return OperatorKind.GT; + case ">=" : return OperatorKind.GE; + case "<" : return OperatorKind.LT; + case "<=" : return OperatorKind.LE; + } + return OperatorKind.INVALID; +} + const noTypesYet = new Map(); /** Represents an AssemblyScript program. */ @@ -136,6 +182,8 @@ export class Program extends DiagnosticEmitter { moduleLevelExports: Map = new Map(); /** Array prototype reference. */ arrayPrototype: ClassPrototype | null = null; + /** ArrayBufferView prototype reference. */ + arrayBufferViewPrototype: InterfacePrototype | null = null; /** String instance reference. */ stringInstance: Class | null = null; @@ -194,7 +242,8 @@ export class Program extends DiagnosticEmitter { var queuedExports = new Map(); var queuedImports = new Array(); - var queuedDerivedClasses = new Array(); + var queuedExtends = new Array(); + var queuedImplements = new Array(); // build initial lookup maps of internal names to declarations for (let i = 0, k = this.sources.length; i < k; ++i) { @@ -204,7 +253,7 @@ export class Program extends DiagnosticEmitter { let statement = statements[j]; switch (statement.kind) { case NodeKind.CLASSDECLARATION: { - this.initializeClass(statement, queuedDerivedClasses); + this.initializeClass(statement, queuedExtends, queuedImplements); break; } case NodeKind.ENUMDECLARATION: { @@ -228,7 +277,7 @@ export class Program extends DiagnosticEmitter { break; } case NodeKind.NAMESPACEDECLARATION: { - this.initializeNamespace(statement, queuedDerivedClasses); + this.initializeNamespace(statement, queuedExtends, queuedImplements); break; } case NodeKind.TYPEDECLARATION: { @@ -313,13 +362,15 @@ export class Program extends DiagnosticEmitter { } // resolve base prototypes of derived classes - for (let i = 0, k = queuedDerivedClasses.length; i < k; ++i) { - let derivedDeclaration = queuedDerivedClasses[i].declaration; + for (let i = 0, k = queuedExtends.length; i < k; ++i) { + let derivedPrototype = queuedExtends[i]; + let derivedDeclaration = derivedPrototype.declaration; let derivedType = assert(derivedDeclaration.extendsType); - let derived = this.resolveIdentifier(derivedType.name, null); // reports - if (!derived) continue; - if (derived.kind == ElementKind.CLASS_PROTOTYPE) { - queuedDerivedClasses[i].basePrototype = derived; + let baseElement = this.resolveIdentifier(derivedType.name, null); // reports + if (!baseElement) continue; + if (baseElement.kind == ElementKind.CLASS_PROTOTYPE) { + let basePrototype = baseElement; + derivedPrototype.basePrototype = basePrototype; } else { this.error( DiagnosticCode.A_class_may_only_extend_another_class, @@ -337,14 +388,21 @@ export class Program extends DiagnosticEmitter { } } - // register array + // register 'Array' var arrayPrototype = this.elementsLookup.get("Array"); if (arrayPrototype) { assert(arrayPrototype.kind == ElementKind.CLASS_PROTOTYPE); this.arrayPrototype = arrayPrototype; } - // register string + // register 'ArrayBufferView' + var arrayBufferViewPrototype = this.elementsLookup.get("ArrayBufferView"); + if (arrayBufferViewPrototype) { + assert(arrayBufferViewPrototype.kind == ElementKind.INTERFACE_PROTOTYPE); + this.arrayBufferViewPrototype = arrayBufferViewPrototype; + } + + // register 'String' var stringPrototype = this.elementsLookup.get("String"); if (stringPrototype) { assert(stringPrototype.kind == ElementKind.CLASS_PROTOTYPE); @@ -383,6 +441,34 @@ export class Program extends DiagnosticEmitter { } while (true); } + private filterDecorators(decorators: DecoratorNode[], acceptedFlags: DecoratorFlags): DecoratorFlags { + var presentFlags = DecoratorFlags.NONE; + for (let i = 0, k = decorators.length; i < k; ++i) { + let decorator = decorators[i]; + if (decorator.name.kind == NodeKind.IDENTIFIER) { + let name = (decorator.name).text; + let kind = stringToDecoratorKind(name); + let flag = decoratorKindToFlag(kind); + if (flag) { + if (!(acceptedFlags & flag)) { + this.error( + DiagnosticCode.Decorator_0_is_not_valid_here, + decorator.range, name + ); + } else if (presentFlags & flag) { + this.error( + DiagnosticCode.Duplicate_decorator, + decorator.range, name + ); + } else { + presentFlags |= flag; + } + } + } + } + return presentFlags; + } + /** Processes global options, if present. */ private checkGlobalOptions( element: Element, @@ -390,7 +476,7 @@ export class Program extends DiagnosticEmitter { ): void { var parentNode = declaration.parent; if ( - element.is(CommonFlags.GLOBAL) || + (element.hasDecorator(DecoratorFlags.GLOBAL)) || ( declaration.range.source.isLibrary && element.is(CommonFlags.EXPORT) && @@ -409,7 +495,6 @@ export class Program extends DiagnosticEmitter { declaration.name.range, element.internalName ); } else { - element.set(CommonFlags.GLOBAL); this.elementsLookup.set(simpleName, element); if (element.is(CommonFlags.BUILTIN)) { element.internalName = simpleName; @@ -420,7 +505,8 @@ export class Program extends DiagnosticEmitter { private initializeClass( declaration: ClassDeclaration, - queuedDerivedClasses: ClassPrototype[], + queuedExtends: ClassPrototype[], + queuedImplements: ClassPrototype[], namespace: Element | null = null ): void { var internalName = declaration.fileLevelInternalName; @@ -431,12 +517,21 @@ export class Program extends DiagnosticEmitter { ); return; } + + var decorators = declaration.decorators; var simpleName = declaration.name.text; var prototype = new ClassPrototype( this, simpleName, internalName, - declaration + declaration, + decorators + ? this.filterDecorators(decorators, + DecoratorFlags.GLOBAL | + DecoratorFlags.SEALED | + DecoratorFlags.UNMANAGED + ) + : DecoratorFlags.NONE ); prototype.namespace = namespace; this.elementsLookup.set(internalName, prototype); @@ -444,30 +539,25 @@ export class Program extends DiagnosticEmitter { var implementsTypes = declaration.implementsTypes; if (implementsTypes) { let numImplementsTypes = implementsTypes.length; - if (prototype.is(CommonFlags.UNMANAGED)) { + if (prototype.hasDecorator(DecoratorFlags.UNMANAGED)) { if (numImplementsTypes) { this.error( - DiagnosticCode.Structs_cannot_implement_interfaces, + DiagnosticCode.Unmanaged_classes_cannot_implement_interfaces, Range.join( declaration.name.range, implementsTypes[numImplementsTypes - 1].range ) ); } + + // remember classes that implement interfaces } else if (numImplementsTypes) { - for (let i = 0; i < numImplementsTypes; ++i) { - this.error( - DiagnosticCode.Operation_not_supported, - implementsTypes[i].range - ); - } + queuedImplements.push(prototype); } } // remember classes that extend another one - if (declaration.extendsType) { - queuedDerivedClasses.push(prototype); - } + if (declaration.extendsType) queuedExtends.push(prototype); // add as namespace member if applicable if (namespace) { @@ -606,6 +696,14 @@ export class Program extends DiagnosticEmitter { var internalName = declaration.fileLevelInternalName; var prototype: FunctionPrototype | null = null; + var decorators = declaration.decorators; + var decoratorFlags = DecoratorFlags.NONE; + if (decorators) { + decoratorFlags = this.filterDecorators(decorators, + DecoratorFlags.INLINE + ); + } + // static methods become global functions if (declaration.is(CommonFlags.STATIC)) { assert(declaration.name.kind != NodeKind.CONSTRUCTOR); @@ -633,7 +731,8 @@ export class Program extends DiagnosticEmitter { simpleName, internalName, declaration, - classPrototype + classPrototype, + decoratorFlags ); classPrototype.members.set(simpleName, prototype); this.elementsLookup.set(internalName, prototype); @@ -659,7 +758,8 @@ export class Program extends DiagnosticEmitter { simpleName, internalName, declaration, - classPrototype + classPrototype, + decoratorFlags ); // if (classPrototype.isUnmanaged && instancePrototype.isAbstract) { // this.error( Unmanaged classes cannot declare abstract methods. ); @@ -682,10 +782,10 @@ export class Program extends DiagnosticEmitter { } } - this.checkOperators(declaration.decorators, prototype, classPrototype); + this.checkOperatorOverloads(declaration.decorators, prototype, classPrototype); } - private checkOperators( + private checkOperatorOverloads( decorators: DecoratorNode[] | null, prototype: FunctionPrototype, classPrototype: ClassPrototype @@ -698,13 +798,6 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = decorators.length; i < k; ++i) { let decorator = decorators[i]; if (decorator.decoratorKind == DecoratorKind.OPERATOR) { - if (!prototype) { - this.error( - DiagnosticCode.Operation_not_supported, - decorator.range - ); - continue; - } let numArgs = decorator.arguments && decorator.arguments.length || 0; if (numArgs == 1) { let firstArg = (decorator.arguments)[0]; @@ -712,76 +805,22 @@ export class Program extends DiagnosticEmitter { firstArg.kind == NodeKind.LITERAL && (firstArg).literalKind == LiteralKind.STRING ) { - switch ((firstArg).value) { - case "[]": { - classPrototype.fnIndexedGet = prototype.simpleName; - break; - } - case "[]=": { - classPrototype.fnIndexedSet = prototype.simpleName; - break; - } - case "+": { - classPrototype.fnConcat = prototype.simpleName; - break; - } - case "-": { - classPrototype.fnSubtract = prototype.simpleName; - break; - } - case "*": { - classPrototype.fnMultiply = prototype.simpleName; - break; - } - case "/": { - classPrototype.fnDivide = prototype.simpleName; - break; - } - case "%": { - classPrototype.fnFractional = prototype.simpleName; - break; - } - case "&": { - classPrototype.fnBitwiseAnd = prototype.simpleName; - break; - } - case "|": { - classPrototype.fnBitwiseOr = prototype.simpleName; - break; - } - case "^": { - classPrototype.fnBitwiseXor = prototype.simpleName; - break; - } - case "==": { - classPrototype.fnEquals = prototype.simpleName; - break; - } - case "!=": { - classPrototype.fnNotEquals = prototype.simpleName; - break; - } - case ">": { - classPrototype.fnGreaterThan = prototype.simpleName; - break; - } - case ">=": { - classPrototype.fnGreaterThanEquals = prototype.simpleName; - break; - } - case "<": { - classPrototype.fnLessThan = prototype.simpleName; - break; - } - case "<=": { - classPrototype.fnLessThanEquals = prototype.simpleName; - break; - } - default: { + let kind = operatorKindFromString((firstArg).value); + if (kind == OperatorKind.INVALID) { + this.error( + DiagnosticCode.Operation_not_supported, + firstArg.range + ); + } else { + let overloads = classPrototype.overloadPrototypes; + if (overloads.has(kind)) { this.error( - DiagnosticCode.Operation_not_supported, + DiagnosticCode.Duplicate_function_implementation, firstArg.range ); + } else { + prototype.operatorKind = kind; + overloads.set(kind, prototype); } } } else { @@ -796,12 +835,6 @@ export class Program extends DiagnosticEmitter { decorator.range, "1", numArgs.toString(0) ); } - } else if (decorator.decoratorKind != DecoratorKind.CUSTOM) { - // methods support built-in @operator only - this.error( - DiagnosticCode.Operation_not_supported, - decorator.range - ); } } } @@ -840,6 +873,14 @@ export class Program extends DiagnosticEmitter { isNew = true; } + var decorators = declaration.decorators; + var decoratorFlags = DecoratorFlags.NONE; + if (decorators) { + decoratorFlags = this.filterDecorators(decorators, + DecoratorFlags.INLINE + ); + } + var baseName = (isGetter ? GETTER_PREFIX : SETTER_PREFIX) + simpleName; // static accessors become global functions @@ -857,7 +898,8 @@ export class Program extends DiagnosticEmitter { baseName, staticName, declaration, - null + null, + decoratorFlags ); if (isGetter) { (propertyElement).getterPrototype = staticPrototype; @@ -904,7 +946,8 @@ export class Program extends DiagnosticEmitter { baseName, instanceName, declaration, - classPrototype + classPrototype, + decoratorFlags ); if (isGetter) { (propertyElement).getterPrototype = instancePrototype; @@ -1155,12 +1198,19 @@ export class Program extends DiagnosticEmitter { return; } var simpleName = declaration.name.text; + var decorators = declaration.decorators; var prototype = new FunctionPrototype( this, simpleName, internalName, declaration, - null + null, + decorators + ? this.filterDecorators(decorators, + DecoratorFlags.GLOBAL | + DecoratorFlags.INLINE + ) + : DecoratorFlags.NONE ); prototype.namespace = namespace; this.elementsLookup.set(internalName, prototype); @@ -1297,7 +1347,17 @@ export class Program extends DiagnosticEmitter { ); return; } - var prototype = new InterfacePrototype(this, declaration.name.text, internalName, declaration); + + var decorators = declaration.decorators; + var prototype = new InterfacePrototype( + this, + declaration.name.text, + internalName, + declaration, + decorators + ? this.filterDecorators(decorators, DecoratorFlags.GLOBAL) + : DecoratorFlags.NONE + ); prototype.namespace = namespace; this.elementsLookup.set(internalName, prototype); @@ -1367,7 +1427,8 @@ export class Program extends DiagnosticEmitter { private initializeNamespace( declaration: NamespaceDeclaration, - queuedExtendingClasses: ClassPrototype[], + queuedExtends: ClassPrototype[], + queuedImplements: ClassPrototype[], parentNamespace: Element | null = null ): void { var internalName = declaration.fileLevelInternalName; @@ -1426,7 +1487,7 @@ export class Program extends DiagnosticEmitter { for (let i = 0, k = members.length; i < k; ++i) { switch (members[i].kind) { case NodeKind.CLASSDECLARATION: { - this.initializeClass(members[i], queuedExtendingClasses, namespace); + this.initializeClass(members[i], queuedExtends, queuedImplements, namespace); break; } case NodeKind.ENUMDECLARATION: { @@ -1442,7 +1503,7 @@ export class Program extends DiagnosticEmitter { break; } case NodeKind.NAMESPACEDECLARATION: { - this.initializeNamespace(members[i], queuedExtendingClasses, namespace); + this.initializeNamespace(members[i], queuedExtends, queuedImplements, namespace); break; } case NodeKind.TYPEDECLARATION: { @@ -1853,19 +1914,21 @@ export class Program extends DiagnosticEmitter { case ElementKind.CLASS: { let elementExpression = this.resolvedElementExpression; if (elementExpression) { - let indexedGetPrototype = (target).getIndexedGet(); - if (indexedGetPrototype) { - let indexedGetInstance = indexedGetPrototype.resolve(); // reports - if (!indexedGetInstance) return null; - let classReference = indexedGetInstance.signature.returnType.classReference; - if (!classReference) { - this.error( - DiagnosticCode.Property_0_does_not_exist_on_type_1, - propertyAccess.property.range, propertyName, (target).type.toString() - ); - return null; - } - target = classReference; + let indexedGet = (target).lookupOverload(OperatorKind.INDEXED_GET); + if (!indexedGet) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + elementExpression.range, (target).internalName + ); + return null; + } + let returnType = indexedGet.signature.returnType; + if (!(target = returnType.classReference)) { + this.error( + DiagnosticCode.Property_0_does_not_exist_on_type_1, + propertyAccess.property.range, propertyName, returnType.toString() + ); + return null; } } break; @@ -1942,16 +2005,19 @@ export class Program extends DiagnosticEmitter { break; } case ElementKind.CLASS: { // element access on element access - let indexedGetPrototype = (target).getIndexedGet(); - if (indexedGetPrototype) { - let indexedGetInstance = indexedGetPrototype.resolve(); // reports - if (!indexedGetInstance) return null; - let returnType = indexedGetInstance.signature.returnType; - if (target = returnType.classReference) { - this.resolvedThisExpression = targetExpression; - this.resolvedElementExpression = elementAccess.elementExpression; - return target; - } + let indexedGet = (target).lookupOverload(OperatorKind.INDEXED_GET); + if (!indexedGet) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + elementAccess.range, (target).internalName + ); + return null; + } + let returnType = indexedGet.signature.returnType; + if (target = returnType.classReference) { + this.resolvedThisExpression = targetExpression; + this.resolvedElementExpression = elementAccess.elementExpression; + return target; } break; } @@ -1987,6 +2053,14 @@ export class Program extends DiagnosticEmitter { throw new Error("not implemented"); } case NodeKind.THIS: { // -> Class / ClassPrototype + if (contextualFunction.flow.is(FlowFlags.INLINE_CONTEXT)) { + let explicitLocal = contextualFunction.flow.getScopedLocal("this"); + if (explicitLocal) { + this.resolvedThisExpression = null; + this.resolvedElementExpression = null; + return explicitLocal; + } + } let parent = contextualFunction.memberOf; if (parent) { this.resolvedThisExpression = null; @@ -2000,6 +2074,14 @@ export class Program extends DiagnosticEmitter { return null; } case NodeKind.SUPER: { // -> Class + if (contextualFunction.flow.is(FlowFlags.INLINE_CONTEXT)) { + let explicitLocal = contextualFunction.flow.getScopedLocal("super"); + if (explicitLocal) { + this.resolvedThisExpression = null; + this.resolvedElementExpression = null; + return explicitLocal; + } + } let parent = contextualFunction.memberOf; if (parent && parent.kind == ElementKind.CLASS && (parent = (parent).base)) { this.resolvedThisExpression = null; @@ -2045,7 +2127,7 @@ export class Program extends DiagnosticEmitter { if (target.kind == ElementKind.FUNCTION_PROTOTYPE) { let instance = (target).resolveUsingTypeArguments( // reports (expression).typeArguments, - contextualFunction.contextualTypeArguments, + contextualFunction.flow.contextualTypeArguments, expression ); if (!instance) return null; @@ -2153,46 +2235,60 @@ export enum CommonFlags { /** Has a `set` modifier. */ SET = 1 << 12, - // Internal decorators - - /** Is global. */ - GLOBAL = 1 << 13, - /** Is built-in. */ - BUILTIN = 1 << 14, - /** Is unmanaged. */ - UNMANAGED = 1 << 15, - /** Is sealed. */ - SEALED = 1 << 16, - - // Extended modifiers usually derived from basic modifiers or internal decorators + // Extended modifiers usually derived from basic modifiers /** Is ambient, that is either declared or nested in a declared element. */ - AMBIENT = 1 << 17, + AMBIENT = 1 << 13, /** Is generic. */ - GENERIC = 1 << 18, + GENERIC = 1 << 14, /** Is part of a generic context. */ - GENERIC_CONTEXT = 1 << 19, + GENERIC_CONTEXT = 1 << 15, /** Is an instance member. */ - INSTANCE = 1 << 20, + INSTANCE = 1 << 16, /** Is a constructor. */ - CONSTRUCTOR = 1 << 21, + CONSTRUCTOR = 1 << 17, /** Is an arrow function. */ - ARROW = 1 << 22, + ARROW = 1 << 18, /** Is a module export. */ - MODULE_EXPORT = 1 << 23, + MODULE_EXPORT = 1 << 19, /** Is a module import. */ - MODULE_IMPORT = 1 << 24, + MODULE_IMPORT = 1 << 20, // Compilation states + /** Is a builtin. */ + BUILTIN = 1 << 21, /** Is compiled. */ - COMPILED = 1 << 25, + COMPILED = 1 << 22, /** Has a constant value and is therefore inlined. */ - INLINED = 1 << 26, + INLINED = 1 << 23, /** Is scoped. */ - SCOPED = 1 << 27, + SCOPED = 1 << 24, /** Is a trampoline. */ - TRAMPOLINE = 1 << 28 + TRAMPOLINE = 1 << 25 +} + +export enum DecoratorFlags { + /** No flags set. */ + NONE = 0, + /** Is a program global. */ + GLOBAL = 1 << 0, + /** Is an unmanaged class. */ + UNMANAGED = 1 << 2, + /** Is a sealed class. */ + SEALED = 1 << 3, + /** Is always inlined. */ + INLINE = 1 << 4 +} + +export function decoratorKindToFlag(kind: DecoratorKind): DecoratorFlags { + switch (kind) { + case DecoratorKind.GLOBAL: return DecoratorFlags.GLOBAL; + case DecoratorKind.UNMANAGED: return DecoratorFlags.UNMANAGED; + case DecoratorKind.SEALED: return DecoratorFlags.SEALED; + case DecoratorKind.INLINE: return DecoratorFlags.INLINE; + default: return DecoratorFlags.NONE; + } } /** Base class of all program elements. */ @@ -2208,6 +2304,8 @@ export abstract class Element { internalName: string; /** Common flags indicating specific traits. */ flags: CommonFlags = CommonFlags.NONE; + /** Decorator flags indicating annotated traits. */ + decoratorFlags: DecoratorFlags = DecoratorFlags.NONE; /** Namespaced member elements. */ members: Map | null = null; /** Parent namespace, if applicable. */ @@ -2226,6 +2324,8 @@ export abstract class Element { isAny(flags: CommonFlags): bool { return (this.flags & flags) != 0; } /** Sets a specific flag or flags. */ set(flag: CommonFlags): void { this.flags |= flag; } + /** Tests if this element has a specific decorator flag or flags. */ + hasDecorator(flag: DecoratorFlags): bool { return (this.decoratorFlags & flag) == flag; } } /** A namespace. */ @@ -2417,6 +2517,8 @@ export class FunctionPrototype extends Element { instances: Map = new Map(); /** Class type arguments, if a partially resolved method of a generic class. Not set otherwise. */ classTypeArguments: Type[] | null = null; + /** Operator kind, if an overload. */ + operatorKind: OperatorKind = OperatorKind.INVALID; /** Constructs a new function prototype. */ constructor( @@ -2424,12 +2526,14 @@ export class FunctionPrototype extends Element { simpleName: string, internalName: string, declaration: FunctionDeclaration, - classPrototype: ClassPrototype | null = null + classPrototype: ClassPrototype | null = null, + decoratorFlags: DecoratorFlags = DecoratorFlags.NONE ) { super(program, simpleName, internalName); this.declaration = declaration; this.flags = declaration.flags; this.classPrototype = classPrototype; + this.decoratorFlags = decoratorFlags; } /** Resolves this prototype to an instance using the specified concrete type arguments. */ @@ -2445,7 +2549,7 @@ export class FunctionPrototype extends Element { var isInstance = this.is(CommonFlags.INSTANCE); var classPrototype = this.classPrototype; - // inherit contextual type arguments as provided. might be be overridden. + // inherit contextual type arguments as provided. might be overridden. var inheritedTypeArguments = contextualTypeArguments; contextualTypeArguments = new Map(); if (inheritedTypeArguments) { @@ -2497,7 +2601,8 @@ export class FunctionPrototype extends Element { if (isInstance) { classInstance = assert(classPrototype).resolve(classTypeArguments, contextualTypeArguments); // reports if (!classInstance) return null; - thisType = classInstance.type; + thisType = classInstance.type.asThis(); + contextualTypeArguments.set("this", thisType); } // resolve signature node @@ -2536,8 +2641,15 @@ export class FunctionPrototype extends Element { var internalName = this.internalName; if (instanceKey.length) internalName += "<" + instanceKey + ">"; - instance = new Function(this, internalName, signature, classInstance ? classInstance : classPrototype); - instance.contextualTypeArguments = contextualTypeArguments; + instance = new Function( + this, + internalName, + signature, + classInstance + ? classInstance + : classPrototype, + contextualTypeArguments + ); this.instances.set(instanceKey, instance); return instance; } @@ -2556,9 +2668,11 @@ export class FunctionPrototype extends Element { simpleName, classPrototype.internalName + "<" + partialKey + ">" + INSTANCE_DELIMITER + simpleName, this.declaration, - classPrototype + classPrototype, + this.decoratorFlags ); partialPrototype.flags = this.flags; + partialPrototype.operatorKind = this.operatorKind; partialPrototype.classTypeArguments = classTypeArguments; return partialPrototype; } @@ -2643,19 +2757,23 @@ export class Function extends Element { private nextBreakId: i32 = 0; private breakStack: i32[] | null = null; + nextInlineId: i32 = 0; /** Constructs a new concrete function. */ constructor( prototype: FunctionPrototype, internalName: string, signature: Signature, - memberOf: Element | null = null + memberOf: Element | null = null, + contextualTypeArguments: Map | null = null ) { super(prototype.program, prototype.simpleName, internalName); this.prototype = prototype; this.signature = signature; this.memberOf = memberOf; this.flags = prototype.flags; + this.decoratorFlags = prototype.decoratorFlags; + this.contextualTypeArguments = contextualTypeArguments; if (!(prototype.is(CommonFlags.AMBIENT | CommonFlags.BUILTIN) || prototype.is(CommonFlags.DECLARE))) { let localIndex = 0; if (memberOf && memberOf.kind == ElementKind.CLASS) { @@ -2669,13 +2787,13 @@ export class Function extends Element { assert(signature.thisType) ) ); - let contextualTypeArguments = (memberOf).contextualTypeArguments; - if (contextualTypeArguments) { - if (!this.contextualTypeArguments) { - this.contextualTypeArguments = new Map(); - } - for (let [inheritedName, inheritedType] of contextualTypeArguments) { - this.contextualTypeArguments.set(inheritedName, inheritedType); + let inheritedTypeArguments = (memberOf).contextualTypeArguments; + if (inheritedTypeArguments) { + if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map(); + for (let [inheritedName, inheritedType] of inheritedTypeArguments) { + if (!this.contextualTypeArguments.has(inheritedName)) { + this.contextualTypeArguments.set(inheritedName, inheritedType); + } } } } else { @@ -2759,6 +2877,8 @@ export class Function extends Element { /** Frees the temporary local for reuse. */ freeTempLocal(local: Local): void { + if (local.is(CommonFlags.INLINED)) return; + assert(local.index >= 0); var temps: Local[]; assert(local.type != null); // internal error switch ((local.type).toNativeType()) { @@ -2780,6 +2900,7 @@ export class Function extends Element { } default: throw new Error("concrete type expected"); } + assert(local.index >= 0); temps.push(local); } @@ -2975,49 +3096,20 @@ export class ClassPrototype extends Element { basePrototype: ClassPrototype | null = null; // set in Program#initialize /** Constructor prototype. */ constructorPrototype: FunctionPrototype | null = null; - - /** Overloaded indexed get method, if any. */ - fnIndexedGet: string | null = null; - /** Overloaded indexed set method, if any. */ - fnIndexedSet: string | null = null; - /** Overloaded concatenation method, if any. */ - fnConcat: string | null = null; - /** Overloaded subtraction method, if any. */ - fnSubtract: string | null = null; - /** Overloaded multiply method, if any. */ - fnMultiply: string | null = null; - /** Overloaded divide method, if any. */ - fnDivide: string | null = null; - /** Overloaded fractional method, if any. */ - fnFractional: string | null = null; - /** Overloaded bitwise and method, if any. */ - fnBitwiseAnd: string | null = null; - /** Overloaded bitwise or method, if any. */ - fnBitwiseOr: string | null = null; - /** Overloaded bitwise xor method, if any. */ - fnBitwiseXor: string | null = null; - /** Overloaded equality comparison method, if any. */ - fnEquals: string | null = null; - /** Overloaded non-equality comparison method, if any. */ - fnNotEquals: string | null = null; - /** Overloaded greater comparison method, if any. */ - fnGreaterThan: string | null = null; - /** Overloaded greater or equal comparison method, if any. */ - fnGreaterThanEquals: string | null = null; - /** Overloaded less comparison method, if any. */ - fnLessThan: string | null = null; - /** Overloaded less or equal comparison method, if any. */ - fnLessThanEquals: string | null = null; + /** Operator overload prototypes. */ + overloadPrototypes: Map = new Map(); constructor( program: Program, simpleName: string, internalName: string, - declaration: ClassDeclaration + declaration: ClassDeclaration, + decoratorFlags: DecoratorFlags ) { super(program, simpleName, internalName); this.declaration = declaration; this.flags = declaration.flags; + this.decoratorFlags = decoratorFlags; } /** Resolves this prototype to an instance using the specified concrete type arguments. */ @@ -3050,16 +3142,16 @@ export class ClassPrototype extends Element { ); return null; } - if (baseClass.is(CommonFlags.SEALED)) { + if (baseClass.hasDecorator(DecoratorFlags.SEALED)) { this.program.error( DiagnosticCode.Class_0_is_sealed_and_cannot_be_extended, declaration.extendsType.range, baseClass.internalName ); return null; } - if (baseClass.prototype.is(CommonFlags.UNMANAGED) != this.is(CommonFlags.UNMANAGED)) { + if (baseClass.hasDecorator(DecoratorFlags.UNMANAGED) != this.hasDecorator(DecoratorFlags.UNMANAGED)) { this.program.error( - DiagnosticCode.Structs_cannot_extend_classes_and_vice_versa, + DiagnosticCode.Unmanaged_classes_cannot_extend_managed_classes_and_vice_versa, Range.join(declaration.name.range, declaration.extendsType.range) ); return null; @@ -3100,15 +3192,19 @@ export class ClassPrototype extends Element { } } + // Resolve constructor if (this.constructorPrototype) { let partialConstructor = this.constructorPrototype.resolvePartial(typeArguments); // reports if (partialConstructor) instance.constructorInstance = partialConstructor.resolve(); // reports } + // Resolve instance members if (this.instanceMembers) { for (let member of this.instanceMembers.values()) { switch (member.kind) { - case ElementKind.FIELD_PROTOTYPE: { // fields are layed out in advance + + // Lay out fields in advance + case ElementKind.FIELD_PROTOTYPE: { if (!instance.members) instance.members = new Map(); let fieldDeclaration = (member).declaration; if (!fieldDeclaration.type) { @@ -3147,16 +3243,20 @@ export class ClassPrototype extends Element { } break; } - case ElementKind.FUNCTION_PROTOTYPE: { // instance methods remain partially resolved prototypes until compiled + + // Partially resolve methods as these might have type arguments on their own + case ElementKind.FUNCTION_PROTOTYPE: { if (!instance.members) instance.members = new Map(); - let methodPrototype = (member).resolvePartial(typeArguments); // reports - if (methodPrototype) { - methodPrototype.internalName = internalName + INSTANCE_DELIMITER + methodPrototype.simpleName; - instance.members.set(member.simpleName, methodPrototype); + let partialPrototype = (member).resolvePartial(typeArguments); // reports + if (partialPrototype) { + partialPrototype.internalName = internalName + INSTANCE_DELIMITER + partialPrototype.simpleName; + instance.members.set(member.simpleName, partialPrototype); } break; } - case ElementKind.PROPERTY: { // instance properties are cloned with partially resolved getters and setters + + // Clone properties and partially resolve the wrapped accessors for consistence with other methods + case ElementKind.PROPERTY: { if (!instance.members) instance.members = new Map(); let getterPrototype = assert((member).getterPrototype); let setterPrototype = (member).setterPrototype; @@ -3187,6 +3287,24 @@ export class ClassPrototype extends Element { } } } + + // Fully resolve operator overloads (don't have type parameters on their own) + for (let [kind, prototype] of this.overloadPrototypes) { + assert(kind != OperatorKind.INVALID); + let operatorInstance: Function | null; + if (prototype.is(CommonFlags.INSTANCE)) { + let operatorPartial = prototype.resolvePartial(typeArguments); // reports + if (!operatorPartial) continue; + operatorInstance = operatorPartial.resolve(); // reports + } else { + operatorInstance = prototype.resolve(); // reports + } + if (!operatorInstance) continue; + let overloads = instance.overloads; + if (!overloads) instance.overloads = overloads = new Map(); + overloads.set(kind, operatorInstance); + } + instance.currentMemoryOffset = memoryOffset; // offsetof() is the class' byte size in memory return instance; } @@ -3237,6 +3355,8 @@ export class Class extends Element { currentMemoryOffset: u32 = 0; /** Constructor instance. */ constructorInstance: Function | null = null; + /** Operator overloads. */ + overloads: Map | null = null; /** Constructs a new class. */ constructor( @@ -3249,15 +3369,17 @@ export class Class extends Element { super(prototype.program, simpleName, internalName); this.prototype = prototype; this.flags = prototype.flags; + this.decoratorFlags = prototype.decoratorFlags; this.typeArguments = typeArguments; this.type = prototype.program.options.usizeType.asClass(this); this.base = base; // inherit static members and contextual type arguments from base class if (base) { - if (base.contextualTypeArguments) { + let inheritedTypeArguments = base.contextualTypeArguments; + if (inheritedTypeArguments) { if (!this.contextualTypeArguments) this.contextualTypeArguments = new Map(); - for (let [baseName, baseType] of base.contextualTypeArguments) { + for (let [baseName, baseType] of inheritedTypeArguments) { this.contextualTypeArguments.set(baseName, baseType); } } @@ -3287,30 +3409,22 @@ export class Class extends Element { /** Tests if a value of this class type is assignable to a target of the specified class type. */ isAssignableTo(target: Class): bool { var current: Class | null = this; - do { - if (current == target) { - return true; - } - } while (current = current.base); + do if (current == target) return true; + while (current = current.base); return false; } - getIndexedGet(): FunctionPrototype | null { - var members = this.members; - var name = this.prototype.fnIndexedGet; - if (!members || name == null) return null; - var element = members.get(name); - if (!element || element.kind != ElementKind.FUNCTION_PROTOTYPE) return null; - return element; - } - - getIndexedSet(): FunctionPrototype | null { - var members = this.members; - var name = this.prototype.fnIndexedSet; - if (!members || name == null) return null; - var element = members.get(name); - if (!element || element.kind != ElementKind.FUNCTION_PROTOTYPE) return null; - return element; + /** Looks up the operator overload of the specified kind. */ + lookupOverload(kind: OperatorKind): Function | null { + var instance: Class | null = this; + do { + let overloads = instance.overloads; + if (overloads) { + let overload = overloads.get(kind); + if (overload) return overload; + } + } while (instance = instance.base); + return null; } toString(): string { @@ -3331,9 +3445,10 @@ export class InterfacePrototype extends ClassPrototype { program: Program, simpleName: string, internalName: string, - declaration: InterfaceDeclaration + declaration: InterfaceDeclaration, + decoratorFlags: DecoratorFlags ) { - super(program, simpleName, internalName, declaration); + super(program, simpleName, internalName, declaration, decoratorFlags); } } @@ -3384,7 +3499,10 @@ export const enum FlowFlags { /** This branch conditionally continues in a child branch. */ CONDITIONALLY_CONTINUES = 1 << 8, /** This branch conditionally allocates in a child branch. Constructors only. */ - CONDITIONALLY_ALLOCATES = 1 << 9 + CONDITIONALLY_ALLOCATES = 1 << 9, + + /** This branch is part of inlining a function. */ + INLINE_CONTEXT = 1 << 10 } /** A control flow evaluator. */ @@ -3400,6 +3518,12 @@ export class Flow { continueLabel: string | null; /** The label we break to when encountering a break statement. */ breakLabel: string | null; + /** The label we break to when encountering a return statement, when inlining. */ + returnLabel: string | null; + /** The current return type. */ + returnType: Type; + /** The current contextual type arguments. */ + contextualTypeArguments: Map | null; /** Scoped local variables. */ scopedLocals: Map | null = null; /** Scoped global variables. */ @@ -3413,6 +3537,9 @@ export class Flow { parentFlow.currentFunction = currentFunction; parentFlow.continueLabel = null; parentFlow.breakLabel = null; + parentFlow.returnLabel = null; + parentFlow.returnType = currentFunction.signature.returnType; + parentFlow.contextualTypeArguments = currentFunction.contextualTypeArguments; return parentFlow; } @@ -3433,6 +3560,9 @@ export class Flow { branch.currentFunction = this.currentFunction; branch.continueLabel = this.continueLabel; branch.breakLabel = this.breakLabel; + branch.returnLabel = this.returnLabel; + branch.returnType = this.returnType; + branch.contextualTypeArguments = this.contextualTypeArguments; return branch; } @@ -3469,17 +3599,23 @@ export class Flow { } /** Adds a new scoped local of the specified name. */ - addScopedLocal(type: Type, name: string, declaration: VariableDeclaration): void { + addScopedLocal(type: Type, name: string, declaration?: VariableDeclaration): Local { var scopedLocal = this.currentFunction.getTempLocal(type); if (!this.scopedLocals) this.scopedLocals = new Map(); - else if (this.scopedLocals.has(name)) { - this.currentFunction.program.error( - DiagnosticCode.Duplicate_identifier_0, - declaration.name.range - ); - return; + else { + let existingLocal = this.scopedLocals.get(name); + if (existingLocal) { + if (declaration) { + this.currentFunction.program.error( + DiagnosticCode.Duplicate_identifier_0, + declaration.name.range + ); + } else assert(false); + return existingLocal; + } } this.scopedLocals.set(name, scopedLocal); + return scopedLocal; } /** Gets the local of the specified name in the current scope. */ @@ -3517,8 +3653,10 @@ export class Flow { /** Finalizes this flow. Must be the topmost parent flow of the function. */ finalize(): void { - assert(this.parent == null, "must be the topmost parent flow"); + assert(this.parent == null); // must be the topmost parent flow this.continueLabel = null; this.breakLabel = null; + this.returnLabel = null; + this.contextualTypeArguments = null; } } diff --git a/src/tokenizer.ts b/src/tokenizer.ts index 147af83a..097c100e 100644 --- a/src/tokenizer.ts +++ b/src/tokenizer.ts @@ -166,7 +166,7 @@ export enum Token { ENDOFFILE } -export function tokenFomKeyword(text: string): Token { +export function tokenFromKeyword(text: string): Token { switch (text) { case "abstract": return Token.ABSTRACT; case "as": return Token.AS; @@ -805,7 +805,7 @@ export class Tokenizer extends DiagnosticEmitter { } } let keywordText = text.substring(posBefore, this.pos); - let keywordToken = tokenFomKeyword(keywordText); + let keywordToken = tokenFromKeyword(keywordText); if ( keywordToken != Token.INVALID && !(preferIdentifier && tokenIsAlsoIdentifier(keywordToken)) diff --git a/src/types.ts b/src/types.ts index 9825bbc0..b9c21cd3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -80,7 +80,9 @@ export const enum TypeFlags { /** Is a reference type. */ REFERENCE = 1 << 8, /** Is a nullable type. */ - NULLABLE = 1 << 9 + NULLABLE = 1 << 9, + /** Is the special 'this' type. */ + THIS = 1 << 10 } /** Represents a resolved type. */ @@ -102,6 +104,8 @@ export class Type { nullableType: Type | null = null; /** Respective non-nullable type, if nullable. */ nonNullableType: Type; + /** Respective special 'this' type. */ + thisType: Type | null = null; /** Constructs a new resolved type. */ constructor(kind: TypeKind, flags: TypeFlags, size: i32) { @@ -157,6 +161,18 @@ export class Type { return this.nullableType; } + /** Composes the respective 'this' type of this type. */ + asThis(): Type { + var thisType = this.thisType; + if (thisType) return thisType; + thisType = new Type(this.kind, this.flags | TypeFlags.THIS, this.size); + thisType.classReference = this.classReference; + thisType.nullableType = this.nullableType; + thisType.nonNullableType = this.nonNullableType; + this.thisType = thisType; + return thisType; + } + /** Tests if a value of this type is assignable to a target of the specified type. */ isAssignableTo(target: Type, signednessIsImportant: bool = false): bool { var currentClass: Class | null; diff --git a/std/assembly.d.ts b/std/assembly.d.ts index 2333959d..42553d20 100644 --- a/std/assembly.d.ts +++ b/std/assembly.d.ts @@ -298,6 +298,8 @@ declare abstract class TypedArray implements ArrayBufferView { readonly byteLength: i32; /** The length (in elements). */ readonly length: i32; + /** Returns a new TypedArray of this type on the same ArrayBuffer from begin inclusive to end exclusive. */ + subarray(begin?: i32, end?: i32): this; } /** An array of twos-complement 8-bit signed integers. */ @@ -534,5 +536,5 @@ declare function unmanaged(target: Function): any; /** Annotates a class as being sealed / non-derivable. */ declare function sealed(target: Function): any; -/** Annotates a class field with an explicit offset. */ -declare function offset(offset: usize): any; +/** Annotates a method or function as always inlined. */ +declare function inline(target: any, propertyKey: any, descriptor: any): any; diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 7d6ac8b5..f9a3430f 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -1,3 +1,12 @@ +import { + MAX_BLENGTH, + HEADER_SIZE as HEADER_SIZE_AB, + allocUnsafe, + reallocUnsafe, + loadUnsafe, + storeUnsafe +} from "./internal/arraybuffer"; + import { defaultComparator, insertionSort, @@ -6,147 +15,130 @@ import { export class Array { - __memory: usize; - __capacity: i32; // capped to [0, 0x7fffffff] - __length: i32; // capped to [0, __capacity] + /* @internal */ buffer_: ArrayBuffer; + /* @internal */ length_: i32; - private __grow(newCapacity: i32): void { - var oldMemory = this.__memory; - var oldCapacity = this.__capacity; - assert(newCapacity > oldCapacity); - var newMemory = allocate_memory(newCapacity * sizeof()); - if (oldMemory) { - move_memory(newMemory, oldMemory, oldCapacity * sizeof()); - free_memory(oldMemory); - } - this.__memory = newMemory; - this.__capacity = newCapacity; + constructor(length: i32 = 0) { + const MAX_LENGTH = MAX_BLENGTH >>> alignof(); + if (length > MAX_LENGTH) throw new RangeError("Invalid array length"); + this.buffer_ = allocUnsafe(length << alignof()); + this.length_ = length; } - constructor(capacity: i32 = 0) { - if (capacity < 0) throw new RangeError("Invalid array length"); - this.__memory = capacity - ? allocate_memory(capacity * sizeof()) - : 0; - this.__capacity = capacity; - this.__length = capacity; + get length(): i32 { + return this.length_; + } + + set length(length: i32) { + var buffer = this.buffer_; + var capacity = buffer.byteLength >>> alignof(); + if (length > capacity) { + const MAX_LENGTH = MAX_BLENGTH >>> alignof(); + if (length > MAX_LENGTH) throw new RangeError("Invalid array length"); + buffer = reallocUnsafe(buffer, length << alignof()); + this.buffer_ = buffer; + } + this.length_ = length; } every(callbackfn: (element: T, index: i32, array: Array) => bool): bool { - var toIndex: i32 = this.__length; - var i: i32 = 0; - while (i < toIndex && i < this.__length) { - if (!callbackfn(load(this.__memory + i * sizeof()), i, this)) { - return false; - } - i += 1; + var buffer = this.buffer_; + for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) { + if (!callbackfn(loadUnsafe(buffer, index), index, this)) return false; } return true; } findIndex(predicate: (element: T, index: i32, array: Array) => bool): i32 { - var toIndex: i32 = this.__length; - var i: i32 = 0; - while (i < toIndex && i < this.__length) { - if (predicate(load(this.__memory + i * sizeof()), i, this)) { - return i; - } - i += 1; + var buffer = this.buffer_; + for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) { + if (predicate(loadUnsafe(buffer, index), index, this)) return index; } return -1; } - get length(): i32 { - return this.__length; - } - - set length(length: i32) { - if (length < 0) throw new RangeError("Invalid array length"); - if (length > this.__capacity) this.__grow(max(length, this.__capacity << 1)); - this.__length = length; - } - @operator("[]") private __get(index: i32): T { - if (index >= this.__capacity) throw new Error("Index out of bounds"); - return load(this.__memory + index * sizeof()); + var buffer = this.buffer_; + var capacity = buffer.byteLength >>> alignof(); + if (index >= capacity) throw new Error("Index out of bounds"); + // return load(changetype(buffer) + (index << alignof()), HEADER_SIZE_AB); + return loadUnsafe(buffer, index); } @operator("[]=") private __set(index: i32, value: T): void { - if (index < 0) throw new Error("Index out of bounds"); - var capacity = this.__capacity; - if (index >= capacity) this.__grow(max(index + 1, capacity << 1)); - store(this.__memory + index * sizeof(), value); + var buffer = this.buffer_; + var capacity = buffer.byteLength >>> alignof(); + if (index >= capacity) { + const MAX_LENGTH = MAX_BLENGTH >>> alignof(); + if (index >= MAX_LENGTH) throw new Error("Invalid array length"); + buffer = reallocUnsafe(buffer, (index + 1) << alignof()); + this.buffer_ = buffer; + this.length_ = index + 1; + } + // store(changetype(buffer) + (index << alignof()), value, HEADER_SIZE_AB); + storeUnsafe(buffer, index, value); } includes(searchElement: T, fromIndex: i32 = 0): bool { - var length = this.__length; + var length = this.length_; if (length == 0 || fromIndex >= length) return false; - if (fromIndex < 0) { - fromIndex = length + fromIndex; - if (fromIndex < 0) { - fromIndex = 0; - } - } + if (fromIndex < 0) fromIndex = max(length + fromIndex, 0); + var buffer = this.buffer_; while (fromIndex < length) { - if (load(this.__memory + fromIndex * sizeof()) == searchElement) return true; + if (loadUnsafe(buffer, fromIndex) == searchElement) return true; ++fromIndex; } return false; } indexOf(searchElement: T, fromIndex: i32 = 0): i32 { - var length = this.__length; - if (length == 0 || fromIndex >= length) { - return -1; - } - if (fromIndex < 0) { - fromIndex = length + fromIndex; - if (fromIndex < 0) { - fromIndex = 0; - } - } - var memory = this.__memory; + var length = this.length_; + if (length == 0 || fromIndex >= length) return -1; + if (fromIndex < 0) fromIndex = max(length + fromIndex, 0); + var buffer = this.buffer_; while (fromIndex < length) { - if (load(memory + fromIndex * sizeof()) == searchElement) return fromIndex; + if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex; ++fromIndex; } return -1; } - lastIndexOf(searchElement: T, fromIndex: i32 = this.__length): i32 { - var length = this.__length; + lastIndexOf(searchElement: T, fromIndex: i32 = this.length_): i32 { + var length = this.length_; if (length == 0) return -1; - if (fromIndex < 0) { - fromIndex = length + fromIndex; - } else if (fromIndex >= length) { - fromIndex = length - 1; - } - var memory = this.__memory; - while (fromIndex >= 0) { - if (load(memory + fromIndex * sizeof()) == searchElement) return fromIndex; + if (fromIndex < 0) fromIndex = length + fromIndex; // no need to clamp + else if (fromIndex >= length) fromIndex = length - 1; + var buffer = this.buffer_; + while (fromIndex >= 0) { // ^ + if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex; --fromIndex; } return -1; } push(element: T): i32 { - var capacity = this.__capacity; - var length = this.__length; - if (length == capacity) { - this.__grow(capacity ? capacity << 1 : 1); + var length = this.length_; + var buffer = this.buffer_; + var capacity = buffer.byteLength >>> alignof(); + var newLength = length + 1; // safe only if length is checked + if (length >= capacity) { + const MAX_LENGTH = MAX_BLENGTH >>> alignof(); + if (length >= MAX_LENGTH) throw new Error("Invalid array length"); + buffer = reallocUnsafe(buffer, newLength << alignof()); + this.buffer_ = buffer; } - store(this.__memory + length * sizeof(), element); - this.__length = ++length; - return length; + this.length_ = newLength; + storeUnsafe(buffer, length, element); + return newLength; } pop(): T { - var length = this.__length; + var length = this.length_; if (length < 1) throw new RangeError("Array is empty"); - var element = load(this.__memory + --length * sizeof()); - this.__length = length; + var element = loadUnsafe(this.buffer_, --length); + this.length_ = length; return element; } @@ -154,158 +146,119 @@ export class Array { callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U ): U { - var accumulator: U = initialValue; - var toIndex: i32 = this.__length; - var i: i32 = 0; - while (i < toIndex && i < /* might change */ this.__length) { - accumulator = callbackfn(accumulator, load(this.__memory + i * sizeof()), i, this); - i += 1; + var accum = initialValue; + var buffer = this.buffer_; + for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) { + accum = callbackfn(accum, loadUnsafe(buffer, index), index, this); } - return accumulator; + return accum; } shift(): T { - var length = this.__length; + var length = this.length_; if (length < 1) throw new RangeError("Array is empty"); - var memory = this.__memory; - var capacity = this.__capacity; - var element = load(memory); + var buffer = this.buffer_; + var element = loadUnsafe(buffer, 0); + var lastIndex = length - 1; move_memory( - memory, - memory + sizeof(), - (capacity - 1) * sizeof() + changetype(buffer) + HEADER_SIZE_AB, + changetype(buffer) + HEADER_SIZE_AB + sizeof(), + lastIndex << alignof() ); - set_memory( - memory + (capacity - 1) * sizeof(), - 0, - sizeof() - ); - this.__length = length - 1; + storeUnsafe(buffer, lastIndex, isReference() ? null : 0); + this.length_ = lastIndex; return element; } some(callbackfn: (element: T, index: i32, array: Array) => bool): bool { - var toIndex: i32 = this.__length; - var i: i32 = 0; - while (i < toIndex && i < /* might change */ this.__length) { - if (callbackfn(load(this.__memory + i * sizeof()), i, this)) return true; - i += 1; + var buffer = this.buffer_; + for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) { + if (callbackfn(loadUnsafe(buffer, index), index, this)) return true; } return false; } unshift(element: T): i32 { - var memory = this.__memory; - var capacity = this.__capacity; - var length = this.__length; - if (this.__length == capacity) { - // inlined __grow (avoids moving twice) - let newCapacity: i32 = capacity ? capacity << 1 : 1; - assert(newCapacity > capacity); - let newMemory = allocate_memory(newCapacity * sizeof()); - if (memory) { - move_memory( - newMemory + sizeof(), - memory, - capacity * sizeof() - ); - free_memory(memory); - } - this.__memory = newMemory; - this.__capacity = newCapacity; - memory = newMemory; - } else { - move_memory( - memory + sizeof(), - memory, - capacity * sizeof() - ); + var buffer = this.buffer_; + var capacity = buffer.byteLength >>> alignof(); + var length = this.length_; + var newLength = length + 1; // safe only if length is checked + if (length >= capacity) { + const MAX_LENGTH = MAX_BLENGTH >>> alignof(); + if (length >= MAX_LENGTH) throw new Error("Invalid array length"); + buffer = reallocUnsafe(buffer, newLength << alignof()); + capacity = buffer.byteLength >>> alignof(); + this.buffer_ = buffer; } - store(memory, element); - this.__length = ++length; - return length; + move_memory( + changetype(buffer) + HEADER_SIZE_AB + sizeof(), + changetype(buffer) + HEADER_SIZE_AB, + (capacity - 1) << alignof() + ); + storeUnsafe(buffer, 0, element); + this.length_ = newLength; + return newLength; } slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Array { - var length = this.__length; - if (begin < 0) { - begin = length + begin; - if (begin < 0) { - begin = 0; - } - } else if (begin > length) { - begin = length; - } - if (end < 0) { - end = length + end; - } else if (end > length) { - end = length; - } - if (end < begin) { - end = begin; - } - var capacity = end - begin; - assert(capacity >= 0); - var sliced = new Array(capacity); - if (capacity) { + var length = this.length_; + if (begin < 0) begin = max(length + begin, 0); + else if (begin > length) begin = length; + if (end < 0) end = length + end; // no need to clamp + else if (end > length) end = length; + if (end < begin) end = begin; // ^ + var newLength = end - begin; + assert(newLength >= 0); + var sliced = new Array(newLength); + if (newLength) { move_memory( - sliced.__memory, - this.__memory + begin * sizeof(), - capacity * sizeof() + changetype(sliced.buffer_) + HEADER_SIZE_AB, + changetype(this.buffer_) + HEADER_SIZE_AB + (begin << alignof()), + newLength << alignof() ); } return sliced; } splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): void { - if (deleteCount < 1) { - return; - } - var length = this.__length; - if (start < 0) { - start = length + start; - if (start < 0) { - start = 0; - } else if (start >= length) { - return; - } - } else if (start >= length) { - return; - } + if (deleteCount < 1) return; + var length = this.length_; + if (start < 0) start = max(length + start, 0); + if (start >= length) return; deleteCount = min(deleteCount, length - start); - var memory = this.__memory; + var buffer = this.buffer_; move_memory( - memory + start * sizeof(), - memory + (start + deleteCount) * sizeof(), - deleteCount * sizeof() + changetype(buffer) + HEADER_SIZE_AB + (start << alignof()), + changetype(buffer) + HEADER_SIZE_AB + ((start + deleteCount) << alignof()), + deleteCount << alignof() ); - this.__length = length - deleteCount; + this.length_ = length - deleteCount; } reverse(): Array { - var memory = this.__memory; - for (let front: usize = 0, back: usize = this.__length - 1; front < back; ++front, --back) { - let temp = load(memory + front * sizeof()); - store(memory + front * sizeof(), load(memory + back * sizeof())); - store(memory + back * sizeof(), temp); + var buffer = this.buffer_; + for (let front = 0, back = this.length_ - 1; front < back; ++front, --back) { + let temp = loadUnsafe(buffer, front); + storeUnsafe(buffer, front, loadUnsafe(buffer, back)); + storeUnsafe(buffer, back, temp); } return this; } sort(comparator: (a: T, b: T) => i32 = defaultComparator()): Array { - var len = this.length; - if (len <= 1) return this; - if (len == 2) { - let memory = this.__memory; - let a = load(memory, sizeof()); // var a = arr[1]; - let b = load(memory, 0); // var b = arr[0]; + var length = this.length_; + if (length <= 1) return this; + var buffer = this.buffer_; + if (length == 2) { + let a = loadUnsafe(buffer, 1); // a = arr[1] + let b = loadUnsafe(buffer, 0); // b = arr[0] if (comparator(a, b) < 0) { - store(memory, b, sizeof()); // arr[1] = b; - store(memory, a, 0); // arr[0] = a; + storeUnsafe(buffer, 1, b); // arr[1] = b; + storeUnsafe(buffer, 0, a); // arr[0] = a; } return this; } - return len <= 256 + return length < 256 ? insertionSort(this, comparator) : weakHeapSort(this, comparator); } diff --git a/std/assembly/arraybuffer.ts b/std/assembly/arraybuffer.ts index 94355cd1..c4078b5d 100644 --- a/std/assembly/arraybuffer.ts +++ b/std/assembly/arraybuffer.ts @@ -28,3 +28,12 @@ export class ArrayBuffer { return buffer; } } + +export declare interface FastArray {} + +export declare interface ArrayBufferView { + readonly buffer: ArrayBuffer; + readonly byteOffset: i32; + readonly byteLength: i32; + readonly length: i32; +} diff --git a/std/assembly/internal/array.ts b/std/assembly/internal/array.ts index 0ac52498..cc87a03a 100644 --- a/std/assembly/internal/array.ts +++ b/std/assembly/internal/array.ts @@ -1,4 +1,11 @@ -import { Array } from "../array"; +import { + loadUnsafe, + storeUnsafe +} from "./arraybuffer"; + +import { + Array +} from "../array"; /** Obtains the default comparator for the specified type. */ export function defaultComparator(): (a: T, b: T) => i32 { @@ -7,26 +14,23 @@ export function defaultComparator(): (a: T, b: T) => i32 { /** Sorts an Array with the 'Insertion Sort' algorithm. */ export function insertionSort(arr: Array, comparator: (a: T, b: T) => i32): Array { - const shiftT = alignof(); - - var memory = arr.__memory; - for (let i: i32 = 0, len: i32 = arr.length; i < len; i++) { - let a = load(memory + (i << shiftT)); // a = arr[i] + var buffer = arr.buffer_; + for (let i: i32 = 0, length: i32 = arr.length; i < length; i++) { + let a = loadUnsafe(buffer, i); // a = arr[i] let j = i - 1; while (j >= 0) { - let b = load(memory + (j << shiftT)); // b = arr[j] + let b = loadUnsafe(buffer, j); // b = arr[j] if (comparator(a, b) < 0) { - store(memory + ((j-- + 1) << shiftT), b); // arr[j + 1] = b + storeUnsafe(buffer, j-- + 1, b); // arr[j + 1] = b } else break; } - store(memory + ((j + 1) << shiftT), a); // arr[j + 1] = a + storeUnsafe(buffer, j + 1, a); // arr[j + 1] = a } return arr; } /** Sorts an Array with the 'Weak Heap Sort' algorithm. */ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): Array { - const shiftT = alignof(); const shift32 = alignof(); var length = arr.length; @@ -36,43 +40,43 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): // see: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.1863&rep=rep1&type=pdf - var memory = arr.__memory; + var buffer = arr.buffer_; for (let i = length - 1; i > 0; i--) { let j = i; while ((j & 1) == (load(bitset + (j >> 6 << shift32)) >> (j >> 1 & 31) & 1)) j >>= 1; let p = j >> 1; - let a = load(memory + (p << shiftT)); // a = arr[p] - let b = load(memory + (i << shiftT)); // b = arr[i] + let a = loadUnsafe(buffer, p); // a = arr[p] + let b = loadUnsafe(buffer, i); // b = arr[i] if (comparator(a, b) < 0) { store( bitset + (i >> 5 << shift32), load(bitset + (i >> 5 << shift32)) ^ (1 << (i & 31)) ); - store(memory + (i << shiftT), a); // arr[i] = a - store(memory + (p << shiftT), b); // arr[p] = b + storeUnsafe(buffer, i, a); // arr[i] = a + storeUnsafe(buffer, p, b); // arr[p] = b } } for (let i = length - 1; i >= 2; i--) { - let a = load(memory, 0); // a = arr[0] - store(memory, load(memory + (i << shiftT)), 0); // arr[0] = arr[1] - store(memory + (i << shiftT), a); // arr[1] = a + let a = loadUnsafe(buffer, 0); // a = arr[0] + storeUnsafe(buffer, 0, loadUnsafe(buffer, i)); // arr[0] = arr[i] + storeUnsafe(buffer, i, a); // arr[i] = a let x = 1, y: i32; while ((y = (x << 1) + ((load(bitset + (x >> 5 << shift32)) >> (x & 31)) & 1)) < i) x = y; while (x > 0) { - a = load(memory, 0); // a = arr[0] - let b = load(memory + (x << shiftT)); // b = arr[x] + a = loadUnsafe(buffer, 0); // a = arr[0] + let b = loadUnsafe(buffer, x); // b = arr[x] if (comparator(a, b) < 0) { store( bitset + (x >> 5 << shift32), load(bitset + (x >> 5 << shift32)) ^ (1 << (x & 31)) ); - store(memory + (x << shiftT), a); // arr[x] = a - store(memory, b, 0); // arr[0] = b + storeUnsafe(buffer, x, a); // arr[x] = a + storeUnsafe(buffer, 0, b); // arr[0] = b } x >>= 1; } @@ -80,8 +84,8 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): free_memory(bitset); - var t = load(memory, sizeof()); // t = arr[1] - store(memory, load(memory, 0), sizeof()); // arr[1] = arr[0] - store(memory, t, 0); // arr[0] = t + var t = loadUnsafe(buffer, 1); // t = arr[1] + storeUnsafe(buffer, 1, loadUnsafe(buffer, 0)); // arr[1] = arr[0] + storeUnsafe(buffer, 0, t); // arr[0] = t return arr; } diff --git a/std/assembly/internal/arraybuffer.ts b/std/assembly/internal/arraybuffer.ts index a978ea03..61db943d 100644 --- a/std/assembly/internal/arraybuffer.ts +++ b/std/assembly/internal/arraybuffer.ts @@ -30,11 +30,10 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf var oldByteLength = buffer.byteLength; if (newByteLength > oldByteLength) { assert(newByteLength <= MAX_BLENGTH); - let oldSize = computeSize(oldByteLength); - if ((oldSize - HEADER_SIZE) <= newByteLength) { // fast path: zero out additional space + if (newByteLength <= (computeSize(oldByteLength) - HEADER_SIZE)) { // fast path: zero out additional space store(changetype(buffer), newByteLength, offsetof("byteLength")); set_memory( - changetype(buffer) + HEADER_SIZE + oldByteLength, + changetype(buffer) + HEADER_SIZE + oldByteLength, 0, (newByteLength - oldByteLength) ); @@ -43,7 +42,12 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf move_memory( changetype(newBuffer) + HEADER_SIZE, changetype(buffer) + HEADER_SIZE, - newByteLength + oldByteLength + ); + set_memory( + changetype(newBuffer) + HEADER_SIZE + oldByteLength, + 0, + (newByteLength - oldByteLength) ); return newBuffer; } @@ -55,10 +59,22 @@ export function reallocUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuf return buffer; } -/** Common typed array interface. Not a global object. */ -// export declare interface ArrayBufferView { -// readonly buffer: ArrayBuffer; -// readonly byteOffset: i32; -// readonly byteLength: i32; -// readonly length: i32; -// } +@inline +export function loadUnsafe(buffer: ArrayBuffer, index: i32): T { + return load(changetype(buffer) + (index << alignof()), HEADER_SIZE); +} + +@inline +export function storeUnsafe(buffer: ArrayBuffer, index: i32, value: T): void { + store(changetype(buffer) + (index << alignof()), value, HEADER_SIZE); +} + +@inline +export function loadUnsafeWithOffset(buffer: ArrayBuffer, index: i32, byteOffset: i32): T { + return load(changetype(buffer) + byteOffset + (index << alignof()), HEADER_SIZE); +} + +@inline +export function storeUnsafeWithOffset(buffer: ArrayBuffer, index: i32, value: T, byteOffset: i32): void { + store(changetype(buffer) + byteOffset + (index << alignof()), value, HEADER_SIZE); +} diff --git a/std/assembly/internal/typedarray.ts b/std/assembly/internal/typedarray.ts index 79840f0f..2123fed2 100644 --- a/std/assembly/internal/typedarray.ts +++ b/std/assembly/internal/typedarray.ts @@ -1,12 +1,17 @@ import { - HEADER_SIZE, + HEADER_SIZE as HEADER_SIZE_AB, MAX_BLENGTH, - allocUnsafe - // ArrayBufferView + allocUnsafe, + loadUnsafeWithOffset, + storeUnsafeWithOffset } from "./arraybuffer"; +import { + ArrayBufferView +} from "../arraybuffer"; + /** Typed array base class. Not a global object. */ -export abstract class TypedArray /* implements ArrayBufferView */ { +export abstract class TypedArray implements ArrayBufferView { readonly buffer: ArrayBuffer; readonly byteOffset: i32; @@ -17,21 +22,45 @@ export abstract class TypedArray /* implements ArrayBufferView */ { if (length > MAX_LENGTH) throw new RangeError("Invalid typed array length"); var byteLength = length << alignof(); var buffer = allocUnsafe(byteLength); - set_memory(changetype(buffer) + HEADER_SIZE, 0, byteLength); + set_memory(changetype(buffer) + HEADER_SIZE_AB, 0, byteLength); this.buffer = buffer; this.byteOffset = 0; this.byteLength = byteLength; } get length(): i32 { - return this.byteLength >> alignof(); + return (this.byteLength - this.byteOffset) >> alignof(); } - // @operator("[]") - maybe injected through ArrayBufferView? + @operator("[]") + private __get(index: i32): T { + var byteOffset = this.byteOffset; + var elementLength = (this.byteLength - byteOffset) >>> alignof(); + if (index >= elementLength) throw new Error("Index out of bounds"); + return loadUnsafeWithOffset(this.buffer, index, byteOffset); + } - // @operator("[]=") - maybe injected through ArrayBufferView? + @operator("[]=") + private __set(index: i32, value: T): void { + var byteOffset = this.byteOffset; + var elementLength = (this.byteLength - byteOffset) >>> alignof(); + if (index >= elementLength) throw new Error("Index out of bounds"); + storeUnsafeWithOffset(this.buffer, index, value, byteOffset); + } - // copyWithin(target: i32, start: i32, end: i32 = 0x7fffffff): TypedArray + // copyWithin(target: i32, start: i32, end: i32 = this.length): this - // subarray(begin: i32 = 0, end: i32 = 0x7fffffff): TypedArray + @inline + subarray(begin: i32 = 0, end: i32 = 0x7fffffff): TypedArray { + var length = this.length; + if (begin < 0) begin = max(length + begin, 0); + else begin = min(begin, length); + if (end < 0) end = max(length + end, begin); + else end = max(min(end, length), begin); + var slice = allocate_memory(offsetof()); + store(slice, this.buffer, offsetof("buffer")); + store(slice, begin << alignof(), offsetof("byteOffset")); + store(slice, end << alignof(), offsetof("byteLength")); + return changetype(slice); + } } diff --git a/std/assembly/typedarray.ts b/std/assembly/typedarray.ts index d8617d02..f93ff414 100644 --- a/std/assembly/typedarray.ts +++ b/std/assembly/typedarray.ts @@ -4,40 +4,80 @@ import { export class Int8Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Int8Array { + return changetype(super.subarray(begin, end)); + } } export class Uint8Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Uint8Array { + return changetype(super.subarray(begin, end)); + } } export class Int16Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Int16Array { + return changetype(super.subarray(begin, end)); + } } export class Uint16Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Uint16Array { + return changetype(super.subarray(begin, end)); + } } export class Int32Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Int32Array { + return changetype(super.subarray(begin, end)); + } } export class Uint32Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Uint32Array { + return changetype(super.subarray(begin, end)); + } } export class Int64Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Int64Array { + return changetype(super.subarray(begin, end)); + } } export class Uint64Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Uint64Array { + return changetype(super.subarray(begin, end)); + } } export class Float32Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Float32Array { + return changetype(super.subarray(begin, end)); + } } export class Float64Array extends TypedArray { static readonly BYTES_PER_ELEMENT: usize = sizeof(); + + subarray(begin: i32 = 0, end: i32 = this.length): Float64Array { + return changetype(super.subarray(begin, end)); + } } diff --git a/tests/allocators/index.js b/tests/allocators/index.js index d2a93379..0f99baa8 100644 --- a/tests/allocators/index.js +++ b/tests/allocators/index.js @@ -20,7 +20,7 @@ function test(file) { return String.fromCharCode.apply(String, str); } - require("./runner")(exports, 50, 20000); + require("./runner")(exports, 20, 20000); console.log("mem final: " + exports.memory.buffer.byteLength); console.log(); diff --git a/tests/compiler/if.optimized.wat b/tests/compiler/if.optimized.wat index 20d4f564..39652ba7 100644 --- a/tests/compiler/if.optimized.wat +++ b/tests/compiler/if.optimized.wat @@ -33,7 +33,15 @@ (return (i32.const 1) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 37) + (i32.const 4) + ) + (unreachable) + ) ) ) (func $start (; 4 ;) (type $v) diff --git a/tests/compiler/if.untouched.wat b/tests/compiler/if.untouched.wat index 2ed5859e..3cc169c0 100644 --- a/tests/compiler/if.untouched.wat +++ b/tests/compiler/if.untouched.wat @@ -57,7 +57,15 @@ (return (i32.const 1) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 37) + (i32.const 4) + ) + (unreachable) + ) ) ) (func $start (; 5 ;) (type $v) diff --git a/tests/compiler/inlining.optimized.wat b/tests/compiler/inlining.optimized.wat index 449913c1..6b5fe82c 100644 --- a/tests/compiler/inlining.optimized.wat +++ b/tests/compiler/inlining.optimized.wat @@ -2,16 +2,199 @@ (type $i (func (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) + (type $ii (func (param i32) (result i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (global $argumentCount (mut i32) (i32.const 0)) + (table 1 1 anyfunc) + (elem (i32.const 0) $inlining/test_funcs~anonymous|0) (memory $0 1) (data (i32.const 4) "\0b\00\00\00i\00n\00l\00i\00n\00i\00n\00g\00.\00t\00s") (export "test" (func $inlining/test)) (export "memory" (memory $0)) + (export "table" (table $0)) (start $start) (func $inlining/test (; 1 ;) (type $i) (result i32) (i32.const 3) ) - (func $start (; 2 ;) (type $v) + (func $inlining/test_funcs~anonymous|0 (; 2 ;) (type $ii) (param $0 i32) (result i32) + (get_local $0) + ) + (func $inlining/test_funcs (; 3 ;) (type $v) + (local $0 i32) + (if + (i32.ne + (block $inlining/func_ii|inlined.0 (result i32) + (drop + (br_if $inlining/func_ii|inlined.0 + (i32.const 1) + (i32.eq + (tee_local $0 + (i32.const 42) + ) + (i32.const 42) + ) + ) + ) + (select + (i32.const 2) + (i32.const 3) + (i32.lt_s + (get_local $0) + (i32.const 42) + ) + ) + ) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 60) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (block $inlining/func_ii|inlined.1 (result i32) + (drop + (br_if $inlining/func_ii|inlined.1 + (i32.const 1) + (i32.eq + (tee_local $0 + (i32.const 41) + ) + (i32.const 42) + ) + ) + ) + (select + (i32.const 2) + (i32.const 3) + (i32.lt_s + (get_local $0) + (i32.const 42) + ) + ) + ) + (i32.const 2) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 61) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (block $inlining/func_ii|inlined.2 (result i32) + (drop + (br_if $inlining/func_ii|inlined.2 + (i32.const 1) + (i32.eq + (tee_local $0 + (i32.const 43) + ) + (i32.const 42) + ) + ) + ) + (select + (i32.const 2) + (i32.const 3) + (i32.lt_s + (get_local $0) + (i32.const 42) + ) + ) + ) + (i32.const 3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 62) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (tee_local $0 + (i32.add + (tee_local $0 + (i32.const 2) + ) + (i32.const 1) + ) + ) + (i32.const 3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.ne + (tee_local $0 + (i32.add + (tee_local $0 + (i32.const 3) + ) + (i32.const 1) + ) + ) + (i32.const 4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 66) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (block (result i32) + (set_global $argumentCount + (i32.const 1) + ) + (i32.ne + (call_indirect (type $ii) + (i32.const 2) + (i32.const 0) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 68) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (func $start (; 4 ;) (type $v) (if (i32.ne (call $inlining/test) @@ -21,11 +204,12 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 8) + (i32.const 10) (i32.const 0) ) (unreachable) ) ) + (call $inlining/test_funcs) ) ) diff --git a/tests/compiler/inlining.ts b/tests/compiler/inlining.ts index c3bf37c2..9a46fcf5 100644 --- a/tests/compiler/inlining.ts +++ b/tests/compiler/inlining.ts @@ -1,3 +1,5 @@ +// Constant inlining + const constantGlobal = 1; export function test(): i32 { @@ -6,3 +8,67 @@ export function test(): i32 { } assert(test() == 3); + +// Function inlining + +@inline +function func_ii(a: i32): i32 { + if (a == 42) return 1; + return a < 42 ? 2 : 3; +} + +@inline +function func_ii_opt(a: i32 = 0): i32 { + return a; +} + +@inline +function func_ii_loc(a: i32): i32 { + var b = a; + var e: i32; + if (true) { + let c = b; + let d = c; + e = d + 1; + } + return e; +} + +@inline +function func_iv(a: i32): void { +} + +@inline +function func_fe(): (a: i32) => i32 { + return (a: i32): i32 => a; +} + + +class Foo { + @inline + static method_static(a: i32, b: i32 = 2): i32 { + return a + b; + } + @inline + method_this(a: i32, b: i32 = 3): Foo { + return this; + } +} + +function test_funcs(): void { + var a: f32 = -1, b: f64 = -2; + assert(func_ii(42) == 1); + assert(func_ii(41) == 2); + assert(func_ii(43) == 3); + assert(func_ii_opt() == 0); + assert(func_ii_opt(1) == 1); + assert(func_ii_loc(2) == 3); + assert(func_ii_loc(3) == 4); + func_iv(0); + assert(func_fe()(2) == 2); + assert(Foo.method_static(42) == 44); + var foo = changetype(123); + assert(changetype(foo.method_this(43)) == 123); +} + +test_funcs(); diff --git a/tests/compiler/inlining.untouched.wat b/tests/compiler/inlining.untouched.wat index 0e24a6e8..8cd61249 100644 --- a/tests/compiler/inlining.untouched.wat +++ b/tests/compiler/inlining.untouched.wat @@ -2,13 +2,18 @@ (type $i (func (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) + (type $ii (func (param i32) (result i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $inlining/constantGlobal i32 (i32.const 1)) + (global $argumentCount (mut i32) (i32.const 0)) (global $HEAP_BASE i32 (i32.const 32)) + (table 1 1 anyfunc) + (elem (i32.const 0) $inlining/test_funcs~anonymous|0) (memory $0 1) (data (i32.const 4) "\0b\00\00\00i\00n\00l\00i\00n\00i\00n\00g\00.\00t\00s\00") (export "test" (func $inlining/test)) (export "memory" (memory $0)) + (export "table" (table $0)) (start $start) (func $inlining/test (; 1 ;) (type $i) (result i32) (nop) @@ -19,7 +24,383 @@ ) ) ) - (func $start (; 2 ;) (type $v) + (func $inlining/test_funcs~anonymous|0 (; 2 ;) (type $ii) (param $0 i32) (result i32) + (get_local $0) + ) + (func $inlining/test_funcs (; 3 ;) (type $v) + (local $0 f32) + (local $1 f64) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (block + (set_local $0 + (f32.const -1) + ) + (set_local $1 + (f64.const -2) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii|inlined.0 (result i32) + (set_local $2 + (i32.const 42) + ) + (if + (i32.eq + (get_local $2) + (i32.const 42) + ) + (br $inlining/func_ii|inlined.0 + (i32.const 1) + ) + ) + (br $inlining/func_ii|inlined.0 + (if (result i32) + (i32.lt_s + (get_local $2) + (i32.const 42) + ) + (i32.const 2) + (i32.const 3) + ) + ) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 60) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii|inlined.1 (result i32) + (set_local $2 + (i32.const 41) + ) + (if + (i32.eq + (get_local $2) + (i32.const 42) + ) + (br $inlining/func_ii|inlined.1 + (i32.const 1) + ) + ) + (br $inlining/func_ii|inlined.1 + (if (result i32) + (i32.lt_s + (get_local $2) + (i32.const 42) + ) + (i32.const 2) + (i32.const 3) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 61) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii|inlined.2 (result i32) + (set_local $2 + (i32.const 43) + ) + (if + (i32.eq + (get_local $2) + (i32.const 42) + ) + (br $inlining/func_ii|inlined.2 + (i32.const 1) + ) + ) + (br $inlining/func_ii|inlined.2 + (if (result i32) + (i32.lt_s + (get_local $2) + (i32.const 42) + ) + (i32.const 2) + (i32.const 3) + ) + ) + ) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 62) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii_opt|inlined.0 (result i32) + (set_local $2 + (i32.const 0) + ) + (br $inlining/func_ii_opt|inlined.0 + (get_local $2) + ) + ) + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 63) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii_opt|inlined.1 (result i32) + (set_local $2 + (i32.const 1) + ) + (br $inlining/func_ii_opt|inlined.1 + (get_local $2) + ) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii_loc|inlined.0 (result i32) + (set_local $2 + (i32.const 2) + ) + (set_local $3 + (get_local $2) + ) + (nop) + (if + (i32.const 1) + (block + (set_local $5 + (get_local $3) + ) + (set_local $6 + (get_local $5) + ) + (set_local $4 + (i32.add + (get_local $6) + (i32.const 1) + ) + ) + ) + ) + (br $inlining/func_ii_loc|inlined.0 + (get_local $4) + ) + ) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 65) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/func_ii_loc|inlined.1 (result i32) + (set_local $4 + (i32.const 3) + ) + (set_local $3 + (get_local $4) + ) + (nop) + (if + (i32.const 1) + (block + (set_local $6 + (get_local $3) + ) + (set_local $5 + (get_local $6) + ) + (set_local $2 + (i32.add + (get_local $5) + (i32.const 1) + ) + ) + ) + ) + (br $inlining/func_ii_loc|inlined.1 + (get_local $2) + ) + ) + (i32.const 4) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 66) + (i32.const 2) + ) + (unreachable) + ) + ) + (block $inlining/func_iv|inlined.0 + (set_local $2 + (i32.const 0) + ) + ) + (if + (i32.eqz + (i32.eq + (block (result i32) + (set_global $argumentCount + (i32.const 1) + ) + (call_indirect (type $ii) + (i32.const 2) + (block $inlining/func_fe|inlined.0 (result i32) + (br $inlining/func_fe|inlined.0 + (i32.const 0) + ) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 68) + (i32.const 2) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/Foo.method_static|inlined.0 (result i32) + (set_local $2 + (i32.const 42) + ) + (set_local $3 + (i32.const 2) + ) + (br $inlining/Foo.method_static|inlined.0 + (i32.add + (get_local $2) + (get_local $3) + ) + ) + ) + (i32.const 44) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 69) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $7 + (i32.const 123) + ) + (if + (i32.eqz + (i32.eq + (block $inlining/Foo#method_this|inlined.0 (result i32) + (set_local $3 + (get_local $7) + ) + (set_local $2 + (i32.const 43) + ) + (set_local $4 + (i32.const 3) + ) + (br $inlining/Foo#method_this|inlined.0 + (get_local $3) + ) + ) + (i32.const 123) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 71) + (i32.const 2) + ) + (unreachable) + ) + ) + ) + (func $start (; 4 ;) (type $v) (if (i32.eqz (i32.eq @@ -31,11 +412,12 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 8) + (i32.const 10) (i32.const 0) ) (unreachable) ) ) + (call $inlining/test_funcs) ) ) diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index c206cc2a..037310b6 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -1,13 +1,14 @@ (module (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) - (type $iiii (func (param i32 i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $argumentCount (mut i32) (i32.const 0)) (memory $0 1) - (data (i32.const 8) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s") - (data (i32.const 40) "\04\00\00\00n\00u\00l\00l") + (data (i32.const 4) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 40) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s") + (data (i32.const 72) "\04\00\00\00n\00u\00l\00l") (export "i32ArrayArrayElementAccess" (func $std/array-access/i32ArrayArrayElementAccess)) (export "stringArrayPropertyAccess" (func $std/array-access/stringArrayPropertyAccess)) (export "stringArrayMethodCall" (func $std/array-access/stringArrayMethodCall)) @@ -15,20 +16,34 @@ (export "stringArrayArrayMethodCall" (func $std/array-access/stringArrayArrayMethodCall)) (export "memory" (memory $0)) (func $~lib/array/Array>#__get (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) ) ) - (unreachable) - ) - (i32.load - (i32.add - (i32.load - (get_local $0) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) ) + (unreachable) + ) + ) + (i32.load offset=8 + (i32.add + (get_local $2) (i32.shl (get_local $1) (i32.const 2) @@ -124,7 +139,7 @@ (block (call $abort (i32.const 0) - (i32.const 8) + (i32.const 40) (i32.const 234) (i32.const 4) ) @@ -136,7 +151,7 @@ (get_local $1) ) (set_local $1 - (i32.const 40) + (i32.const 72) ) ) (if @@ -234,7 +249,7 @@ (get_local $0) (i32.const 0) ) - (i32.const 4) + (i32.const 36) (i32.const 0) ) ) @@ -261,7 +276,7 @@ ) (i32.const 1) ) - (i32.const 4) + (i32.const 36) (i32.const 0) ) ) diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index 9a2b8ca4..211da89b 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -2,16 +2,21 @@ (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $i (func (result i32))) - (type $iiii (func (param i32 i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (global $~lib/internal/allocator/AL_BITS i32 (i32.const 3)) + (global $~lib/internal/allocator/AL_SIZE i32 (i32.const 8)) + (global $~lib/internal/allocator/AL_MASK i32 (i32.const 7)) + (global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8)) (global $~lib/internal/string/HEADER_SIZE i32 (i32.const 4)) (global $argumentCount (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 52)) + (global $HEAP_BASE i32 (i32.const 84)) (memory $0 1) - (data (i32.const 4) "\00\00\00\00") - (data (i32.const 8) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00") - (data (i32.const 40) "\04\00\00\00n\00u\00l\00l\00") + (data (i32.const 4) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 36) "\00\00\00\00") + (data (i32.const 40) "\0e\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00") + (data (i32.const 72) "\04\00\00\00n\00u\00l\00l\00") (export "i32ArrayArrayElementAccess" (func $std/array-access/i32ArrayArrayElementAccess)) (export "stringArrayPropertyAccess" (func $std/array-access/stringArrayPropertyAccess)) (export "stringArrayMethodCall" (func $std/array-access/stringArrayMethodCall)) @@ -19,48 +24,110 @@ (export "stringArrayArrayMethodCall" (func $std/array-access/stringArrayArrayMethodCall)) (export "memory" (memory $0)) (func $~lib/array/Array>#__get (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) + ) + (unreachable) ) - (unreachable) ) (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe>|inlined.0 (result i32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe>|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) ) ) (func $~lib/array/Array#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) + ) + (unreachable) ) - (unreachable) ) (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result i32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) @@ -78,24 +145,55 @@ ) ) (func $~lib/array/Array#__get (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) + ) + (unreachable) ) - (unreachable) ) (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result i32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) @@ -194,7 +292,7 @@ (block (call $abort (i32.const 0) - (i32.const 8) + (i32.const 40) (i32.const 234) (i32.const 4) ) @@ -207,7 +305,7 @@ (i32.const 0) ) (set_local $1 - (i32.const 40) + (i32.const 72) ) ) (set_local $3 @@ -319,31 +417,62 @@ (get_local $0) (i32.const 0) ) - (i32.const 4) + (i32.const 36) (i32.const 0) ) ) ) ) (func $~lib/array/Array>#__get (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) + ) + (unreachable) ) - (unreachable) ) (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe>|inlined.0 (result i32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe>|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) @@ -376,7 +505,7 @@ ) (i32.const 1) ) - (i32.const 4) + (i32.const 36) (i32.const 0) ) ) diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 06c9fe50..612802e2 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -1,121 +1,77 @@ (module (type $i (func (result i32))) - (type $F (func (result f64))) - (type $Iv (func (param i64))) - (type $iiiiv (func (param i32 i32 i32 i32))) - (type $II (func (param i64) (result i64))) - (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) - (type $iiv (func (param i32 i32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) - (type $iv (func (param i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $iiiii (func (param i32 i32 i32 i32) (result i32))) + (type $F (func (result f64))) + (type $Iv (func (param i64))) + (type $II (func (param i64) (result i64))) + (type $iv (func (param i32))) + (type $iiv (func (param i32 i32))) (type $v (func)) - (import "JSMath" "random" (func $~lib/math/JSMath.random (result f64))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (import "JSMath" "random" (func $~lib/math/JSMath.random (result f64))) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $~lib/math/random_seeded (mut i32) (i32.const 0)) - (global $~lib/math/random_state0 (mut i64) (i64.const 0)) - (global $~lib/math/random_state1 (mut i64) (i64.const 0)) + (global $argumentCount (mut i32) (i32.const 0)) (global $std/array/arr (mut i32) (i32.const 0)) (global $std/array/i (mut i32) (i32.const 0)) - (global $argumentCount (mut i32) (i32.const 0)) (global $std/array/includes (mut i32) (i32.const 0)) (global $std/array/every (mut i32) (i32.const 0)) (global $std/array/some (mut i32) (i32.const 0)) (global $std/array/boolVal (mut i32) (i32.const 0)) - (global $std/array/revesed0 (mut i32) (i32.const 96)) - (global $std/array/revesed1 (mut i32) (i32.const 112)) - (global $std/array/revesed2 (mut i32) (i32.const 128)) - (global $std/array/revesed4 (mut i32) (i32.const 152)) - (global $std/array/expected4 (mut i32) (i32.const 184)) - (global $std/array/revesed64 (mut i32) (i32.const 0)) - (global $std/array/revesed128 (mut i32) (i32.const 0)) - (global $std/array/revesed1024 (mut i32) (i32.const 0)) - (global $std/array/revesed10000 (mut i32) (i32.const 0)) + (global $~lib/math/random_seeded (mut i32) (i32.const 0)) + (global $~lib/math/random_state0 (mut i64) (i64.const 0)) + (global $~lib/math/random_state1 (mut i64) (i64.const 0)) + (global $std/array/reversed0 (mut i32) (i32.const 152)) + (global $std/array/reversed1 (mut i32) (i32.const 168)) + (global $std/array/reversed2 (mut i32) (i32.const 192)) + (global $std/array/reversed4 (mut i32) (i32.const 216)) + (global $std/array/expected4 (mut i32) (i32.const 256)) + (global $std/array/reversed64 (mut i32) (i32.const 0)) + (global $std/array/reversed128 (mut i32) (i32.const 0)) + (global $std/array/reversed1024 (mut i32) (i32.const 0)) + (global $std/array/reversed10000 (mut i32) (i32.const 0)) (global $std/array/randomized512 (mut i32) (i32.const 0)) (global $std/array/randomized64 (mut i32) (i32.const 0)) (global $std/array/randomized257 (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 252)) + (global $HEAP_BASE i32 (i32.const 344)) (table 28 28 anyfunc) - (elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~anonymous|2 $start~anonymous|3 $start~anonymous|2 $start~anonymous|5 $start~anonymous|6 $start~anonymous|7 $start~anonymous|8 $start~anonymous|9 $start~anonymous|10 $start~anonymous|11 $start~anonymous|12 $start~anonymous|13 $start~anonymous|14 $start~anonymous|15 $start~anonymous|16 $start~anonymous|16 $start~anonymous|18 $start~anonymous|19 $start~anonymous|20 $start~anonymous|16 $start~anonymous|22 $std/array/createDefaultComparator~anonymous|23 $start~anonymous|24 $start~anonymous|25 $start~anonymous|24 $start~anonymous|25) + (elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~anonymous|2 $start~anonymous|3 $start~anonymous|2 $start~anonymous|5 $start~anonymous|6 $start~anonymous|7 $start~anonymous|8 $start~anonymous|9 $start~anonymous|10 $start~anonymous|11 $start~anonymous|12 $start~anonymous|13 $start~anonymous|14 $start~anonymous|15 $start~anonymous|16 $start~anonymous|16 $start~anonymous|18 $start~anonymous|19 $start~anonymous|20 $start~anonymous|16 $start~anonymous|22 $~lib/internal/array/defaultComparator~anonymous|23 $start~anonymous|24 $start~anonymous|25 $start~anonymous|24 $start~anonymous|25) (memory $0 1) - (data (i32.const 4) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s") - (data (i32.const 32) "\0c\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 60) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 96) "l") - (data (i32.const 112) "|\00\00\00\01\00\00\00\01\00\00\00\01") - (data (i32.const 128) "\8c\00\00\00\02\00\00\00\02\00\00\00\02\00\00\00\01") - (data (i32.const 152) "\a4\00\00\00\04\00\00\00\04\00\00\00\03\00\00\00\02\00\00\00\01") - (data (i32.const 184) "\c4\00\00\00\04\00\00\00\04\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03") - (data (i32.const 216) "\e4\00\00\00\01\00\00\00\01\00\00\00\01") - (data (i32.const 232) "\f4\00\00\00\02\00\00\00\02\00\00\00\01\00\00\00\02") + (data (i32.const 4) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 36) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 96) "\0c\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 124) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s") + (data (i32.const 152) "\a0") + (data (i32.const 168) "\b0\00\00\00\01\00\00\00\04\00\00\00\00\00\00\00\01") + (data (i32.const 192) "\c8\00\00\00\02\00\00\00\08\00\00\00\00\00\00\00\02\00\00\00\01") + (data (i32.const 216) "\e0\00\00\00\04\00\00\00\10\00\00\00\00\00\00\00\03\00\00\00\02\00\00\00\01") + (data (i32.const 256) "\08\01\00\00\04\00\00\00\10") + (data (i32.const 276) "\01\00\00\00\02\00\00\00\03") + (data (i32.const 296) "0\01\00\00\01\00\00\00\04\00\00\00\00\00\00\00\01") + (data (i32.const 320) "H\01\00\00\02\00\00\00\08\00\00\00\00\00\00\00\01\00\00\00\02") (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/math/murmurHash3 (; 2 ;) (type $II) (param $0 i64) (result i64) - (i64.xor - (tee_local $0 - (i64.mul - (i64.xor - (tee_local $0 - (i64.mul - (i64.xor - (get_local $0) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - (i64.const -49064778989728563) - ) - ) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - (i64.const -4265267296055464877) - ) - ) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - ) - (func $~lib/math/NativeMath.seedRandom (; 3 ;) (type $Iv) (param $0 i64) - (if - (i64.eqz - (get_local $0) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 993) - (i32.const 4) - ) - (unreachable) - ) - ) - (set_global $~lib/math/random_seeded + (func $~lib/internal/arraybuffer/computeSize (; 2 ;) (type $ii) (param $0 i32) (result i32) + (i32.shl (i32.const 1) - ) - (set_global $~lib/math/random_state0 - (call $~lib/math/murmurHash3 - (get_local $0) - ) - ) - (set_global $~lib/math/random_state1 - (call $~lib/math/murmurHash3 - (get_global $~lib/math/random_state0) + (i32.sub + (i32.const 32) + (i32.clz + (i32.add + (get_local $0) + (i32.const 7) + ) + ) ) ) ) - (func $~lib/allocator/arena/allocate_memory (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/allocate_memory (; 3 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -204,12 +160,455 @@ ) (i32.const 0) ) - (func $~lib/array/Array#get:length (; 5 ;) (type $ii) (param $0 i32) (result i32) - (i32.load offset=8 + (func $~lib/internal/arraybuffer/allocUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (if + (i32.gt_u + (get_local $0) + (i32.const 1073741816) + ) + (block + (call $abort + (i32.const 0) + (i32.const 36) + (i32.const 22) + (i32.const 2) + ) + (unreachable) + ) + ) + (i32.store + (tee_local $1 + (call $~lib/allocator/arena/allocate_memory + (call $~lib/internal/arraybuffer/computeSize + (get_local $0) + ) + ) + ) + (get_local $0) + ) + (get_local $1) + ) + (func $~lib/array/Array#constructor (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (if + (i32.gt_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 23) + (i32.const 39) + ) + (unreachable) + ) + ) + (i32.store + (if (result i32) + (get_local $0) + (get_local $0) + (block (result i32) + (i32.store + (tee_local $2 + (call $~lib/allocator/arena/allocate_memory + (i32.const 8) + ) + ) + (i32.const 0) + ) + (i32.store offset=4 + (get_local $2) + (i32.const 0) + ) + (tee_local $0 + (get_local $2) + ) + ) + ) + (call $~lib/internal/arraybuffer/allocUnsafe + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $1) + ) + (get_local $0) + ) + (func $~lib/array/Array#constructor|trampoline (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (block $1of1 + (block $0of1 + (block $oob + (br_table $0of1 $1of1 $oob + (get_global $argumentCount) + ) + ) + (unreachable) + ) + (set_local $1 + (i32.const 0) + ) + ) + (call $~lib/array/Array#constructor + (get_local $0) + (get_local $1) + ) + ) + (func $~lib/array/Array#get:length (; 7 ;) (type $ii) (param $0 i32) (result i32) + (i32.load offset=4 (get_local $0) ) ) - (func $~lib/memory/copy_memory (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $std/array/internalCapacity (; 8 ;) (type $ii) (param $0 i32) (result i32) + (i32.shr_s + (i32.load + (i32.load + (get_local $0) + ) + ) + (i32.const 2) + ) + ) + (func $~lib/memory/set_memory (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i64) + (local $4 i32) + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (tee_local $0 + (i32.add + (get_local $0) + (tee_local $4 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + ) + ) + (tee_local $1 + (i32.mul + (get_local $1) + (i32.const 16843009) + ) + ) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (tee_local $2 + (i32.and + (i32.sub + (get_local $2) + (get_local $4) + ) + (i32.const -4) + ) + ) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $1) + ) + (set_local $0 + (i32.add + (get_local $0) + (tee_local $4 + (i32.add + (i32.and + (get_local $0) + (i32.const 4) + ) + (i32.const 24) + ) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) + ) + (set_local $3 + (i64.or + (i64.extend_u/i32 + (get_local $1) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $1) + ) + (i64.const 32) + ) + ) + ) + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (i64.store + (get_local $0) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $3) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (func $~lib/memory/copy_memory (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (loop $continue|0 @@ -1785,7 +2184,7 @@ ) ) ) - (func $~lib/memory/move_memory (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/move_memory (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (if (i32.eq @@ -2075,159 +2474,264 @@ ) ) ) - (func $~lib/allocator/arena/free_memory (; 8 ;) (type $iv) (param $0 i32) - (nop) + (func $~lib/internal/arraybuffer/reallocUnsafe (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (if + (i32.gt_s + (get_local $1) + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (block + (if + (i32.gt_s + (get_local $1) + (i32.const 1073741816) + ) + (block + (call $abort + (i32.const 0) + (i32.const 36) + (i32.const 32) + (i32.const 4) + ) + (unreachable) + ) + ) + (if + (i32.le_s + (get_local $1) + (i32.sub + (call $~lib/internal/arraybuffer/computeSize + (get_local $2) + ) + (i32.const 8) + ) + ) + (block + (i32.store + (get_local $0) + (get_local $1) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + ) + (block + (call $~lib/memory/move_memory + (i32.add + (tee_local $3 + (call $~lib/internal/arraybuffer/allocUnsafe + (get_local $1) + ) + ) + (i32.const 8) + ) + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $3) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + (return + (get_local $3) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $1) + (get_local $2) + ) + (block + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 36) + (i32.const 56) + (i32.const 4) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (get_local $1) + ) + ) + ) + ) + (get_local $0) ) - (func $~lib/array/Array#__grow (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/array/Array#push (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) - (set_local $2 - (i32.load - (get_local $0) - ) - ) - (if - (i32.le_s - (get_local $1) - (tee_local $4 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 60) - (i32.const 16) - (i32.const 4) - ) - (unreachable) - ) - ) (set_local $3 - (call $~lib/allocator/arena/allocate_memory - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $3) - (get_local $2) - (i32.shl - (get_local $4) - (i32.const 2) - ) - ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) - ) - ) - (i32.store - (get_local $0) - (get_local $3) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) - ) - (func $~lib/array/Array#push (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (if - (i32.eq + (i32.add (tee_local $2 - (i32.load offset=8 - (get_local $0) - ) - ) - (tee_local $3 (i32.load offset=4 (get_local $0) ) ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 1) - (get_local $3) - ) - ) - ) - (i32.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.shl - (get_local $2) - (i32.const 2) - ) - ) - (get_local $1) - ) - (i32.store offset=8 - (get_local $0) - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) - ) - ) - (get_local $2) - ) - (func $~lib/array/Array#__get (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - ) - ) - (func $~lib/array/Array#pop (; 12 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - (if - (i32.lt_s - (tee_local $1 - (i32.load offset=8 - (get_local $0) - ) - ) (i32.const 1) ) - (unreachable) + ) + (if + (i32.ge_u + (get_local $2) + (i32.shr_u + (i32.load + (tee_local $4 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (if + (i32.ge_u + (get_local $2) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 128) + (i32.const 42) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (tee_local $4 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $4) + (i32.shl + (get_local $3) + (i32.const 2) + ) + ) + ) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $3) + ) + (i32.store offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $2) + (i32.const 2) + ) + ) + (get_local $1) + ) + (get_local $3) + ) + (func $~lib/array/Array#__get (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 64) + (i32.const 37) + ) + (unreachable) + ) + ) + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + ) + (func $~lib/array/Array#pop (; 15 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (if + (i32.lt_s + (tee_local $1 + (i32.load offset=4 + (get_local $0) + ) + ) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 139) + (i32.const 20) + ) + (unreachable) + ) ) (set_local $2 - (i32.load + (i32.load offset=8 (i32.add (i32.load (get_local $0) @@ -2244,530 +2748,182 @@ ) ) ) - (i32.store offset=8 + (i32.store offset=4 (get_local $0) (get_local $1) ) (get_local $2) ) - (func $~lib/array/Array#unshift (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#unshift (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (local $6 i32) - (set_local $2 - (i32.load - (get_local $0) - ) - ) - (set_local $4 - (i32.load offset=8 - (get_local $0) + (set_local $3 + (i32.add + (tee_local $4 + (i32.load offset=4 + (get_local $0) + ) + ) + (i32.const 1) ) ) (if - (i32.eq - (i32.load offset=8 - (get_local $0) - ) - (tee_local $3 - (i32.load offset=4 - (get_local $0) + (i32.ge_u + (get_local $4) + (tee_local $5 + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) ) ) ) (block (if - (i32.le_s - (tee_local $6 - (select - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 1) - (get_local $3) - ) - ) - (get_local $3) + (i32.ge_u + (get_local $4) + (i32.const 268435454) ) (block (call $abort (i32.const 0) - (i32.const 60) - (i32.const 204) - (i32.const 6) + (i32.const 4) + (i32.const 188) + (i32.const 42) ) (unreachable) ) ) (set_local $5 - (call $~lib/allocator/arena/allocate_memory - (i32.shl - (get_local $6) - (i32.const 2) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (i32.add - (get_local $5) - (i32.const 4) - ) - (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) + (i32.shr_u + (i32.load + (tee_local $2 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) + ) ) ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) + (i32.const 2) ) ) (i32.store (get_local $0) - (get_local $5) - ) - (i32.store offset=4 - (get_local $0) - (get_local $6) - ) - (set_local $2 - (get_local $5) - ) - ) - (call $~lib/memory/move_memory - (i32.add (get_local $2) - (i32.const 4) - ) - (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) - ) - ) - ) - (i32.store - (get_local $2) - (get_local $1) - ) - (i32.store offset=8 - (get_local $0) - (tee_local $4 - (i32.add - (get_local $4) - (i32.const 1) - ) - ) - ) - (get_local $4) - ) - (func $~lib/memory/set_memory (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i64) - (local $4 i32) - (if - (i32.eqz - (get_local $2) - ) - (return) - ) - (i32.store8 - (get_local $0) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 1) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 2) - ) - (return) - ) - (i32.store8 - (i32.add - (get_local $0) - (i32.const 1) - ) - (get_local $1) - ) - (i32.store8 - (i32.add - (get_local $0) - (i32.const 2) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 2) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 3) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 6) - ) - (return) - ) - (i32.store8 - (i32.add - (get_local $0) - (i32.const 3) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 4) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 8) - ) - (return) - ) - (i32.store - (tee_local $0 - (i32.add - (get_local $0) - (tee_local $4 - (i32.and - (i32.sub - (i32.const 0) - (get_local $0) - ) - (i32.const 3) - ) - ) - ) - ) - (tee_local $1 - (i32.mul - (get_local $1) - (i32.const 16843009) - ) - ) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (tee_local $2 - (i32.and - (i32.sub - (get_local $2) - (get_local $4) - ) - (i32.const -4) - ) - ) - ) - (i32.const 4) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 8) - ) - (return) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 4) - ) - (get_local $1) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 8) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 12) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 8) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 24) - ) - (return) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 12) - ) - (get_local $1) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 16) - ) - (get_local $1) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 20) - ) - (get_local $1) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 24) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 28) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 24) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 20) - ) - (get_local $1) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 16) - ) - (get_local $1) - ) - (set_local $0 - (i32.add - (get_local $0) - (tee_local $4 - (i32.add - (i32.and - (get_local $0) - (i32.const 4) - ) - (i32.const 24) - ) - ) - ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (get_local $4) - ) - ) - (set_local $3 - (i64.or - (i64.extend_u/i32 - (get_local $1) - ) - (i64.shl - (i64.extend_u/i32 - (get_local $1) - ) - (i64.const 32) - ) - ) - ) - (loop $continue|0 - (if - (i32.ge_u - (get_local $2) - (i32.const 32) - ) - (block - (i64.store - (get_local $0) - (get_local $3) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 8) - ) - (get_local $3) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 16) - ) - (get_local $3) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 24) - ) - (get_local $3) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 32) - ) - ) - (set_local $0 - (i32.add - (get_local $0) - (i32.const 32) - ) - ) - (br $continue|0) - ) - ) - ) - ) - (func $~lib/array/Array#shift (; 15 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (if - (i32.lt_s - (tee_local $2 - (i32.load offset=8 - (get_local $0) - ) - ) - (i32.const 1) - ) - (unreachable) - ) - (set_local $3 - (i32.load - (tee_local $1 - (i32.load - (get_local $0) - ) ) ) ) (call $~lib/memory/move_memory - (get_local $1) (i32.add - (get_local $1) - (i32.const 4) + (get_local $2) + (i32.const 12) + ) + (i32.add + (get_local $2) + (i32.const 8) ) (i32.shl (i32.sub - (tee_local $4 - (i32.load offset=4 - (get_local $0) - ) - ) + (get_local $5) (i32.const 1) ) (i32.const 2) ) ) - (call $~lib/memory/set_memory + (i32.store offset=8 (i32.add - (get_local $1) - (i32.shl + (get_local $2) + (i32.const 0) + ) + (get_local $1) + ) + (i32.store offset=4 + (get_local $0) + (get_local $3) + ) + (get_local $3) + ) + (func $~lib/array/Array#shift (; 17 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (if + (i32.lt_s + (tee_local $1 + (i32.load offset=4 + (get_local $0) + ) + ) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 159) + (i32.const 20) + ) + (unreachable) + ) + ) + (set_local $3 + (i32.load offset=8 + (i32.add + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + (i32.const 0) + ) + ) + ) + (call $~lib/memory/move_memory + (i32.add + (get_local $2) + (i32.const 8) + ) + (i32.add + (get_local $2) + (i32.const 12) + ) + (i32.shl + (tee_local $1 (i32.sub - (get_local $4) + (get_local $1) (i32.const 1) ) + ) + (i32.const 2) + ) + ) + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $1) (i32.const 2) ) ) (i32.const 0) - (i32.const 4) ) - (i32.store offset=8 + (i32.store offset=4 (get_local $0) - (i32.sub - (get_local $2) - (i32.const 1) - ) + (get_local $1) ) (get_local $3) ) - (func $~lib/array/Array#reverse (; 16 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#reverse (; 18 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2779,7 +2935,7 @@ ) (set_local $2 (i32.sub - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) (i32.const 1) @@ -2787,13 +2943,13 @@ ) (loop $continue|0 (if - (i32.lt_u + (i32.lt_s (get_local $1) (get_local $2) ) (block (set_local $4 - (i32.load + (i32.load offset=8 (i32.add (get_local $3) (i32.shl @@ -2803,7 +2959,7 @@ ) ) ) - (i32.store + (i32.store offset=8 (i32.add (get_local $3) (i32.shl @@ -2811,7 +2967,7 @@ (i32.const 2) ) ) - (i32.load + (i32.load offset=8 (i32.add (get_local $3) (i32.shl @@ -2821,7 +2977,7 @@ ) ) ) - (i32.store + (i32.store offset=8 (i32.add (get_local $3) (i32.shl @@ -2849,25 +3005,25 @@ ) (get_local $0) ) - (func $~lib/array/Array#indexOf (; 17 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#indexOf (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $3 (i32.eqz - (tee_local $3 - (i32.load offset=8 + (tee_local $4 + (i32.load offset=4 (get_local $0) ) ) ) ) - (get_local $4) + (get_local $3) (i32.ge_s (get_local $2) - (get_local $3) + (get_local $4) ) ) (i32.const 1) @@ -2881,22 +3037,25 @@ (get_local $2) (i32.const 0) ) - (if - (i32.lt_s - (tee_local $2 + (set_local $2 + (select + (tee_local $3 (i32.add - (get_local $3) + (get_local $4) (get_local $2) ) ) - (i32.const 0) - ) - (set_local $2 - (i32.const 0) + (tee_local $2 + (i32.const 0) + ) + (i32.gt_s + (get_local $3) + (get_local $2) + ) ) ) ) - (set_local $0 + (set_local $3 (i32.load (get_local $0) ) @@ -2905,14 +3064,14 @@ (if (i32.lt_s (get_local $2) - (get_local $3) + (get_local $4) ) (block (if (i32.eq - (i32.load + (i32.load offset=8 (i32.add - (get_local $0) + (get_local $3) (i32.shl (get_local $2) (i32.const 2) @@ -2937,7 +3096,7 @@ ) (i32.const -1) ) - (func $~lib/array/Array#indexOf|trampoline (; 18 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#indexOf|trampoline (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -2960,25 +3119,25 @@ (get_local $2) ) ) - (func $~lib/array/Array#includes (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#includes (; 21 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $3 (i32.eqz - (tee_local $3 - (i32.load offset=8 + (tee_local $4 + (i32.load offset=4 (get_local $0) ) ) ) ) - (get_local $4) + (get_local $3) (i32.ge_s (get_local $2) - (get_local $3) + (get_local $4) ) ) (i32.const 1) @@ -2992,35 +3151,41 @@ (get_local $2) (i32.const 0) ) - (if - (i32.lt_s - (tee_local $2 + (set_local $2 + (select + (tee_local $3 (i32.add - (get_local $3) + (get_local $4) (get_local $2) ) ) - (i32.const 0) - ) - (set_local $2 - (i32.const 0) + (tee_local $2 + (i32.const 0) + ) + (i32.gt_s + (get_local $3) + (get_local $2) + ) ) ) ) + (set_local $3 + (i32.load + (get_local $0) + ) + ) (loop $continue|0 (if (i32.lt_s (get_local $2) - (get_local $3) + (get_local $4) ) (block (if (i32.eq - (i32.load + (i32.load offset=8 (i32.add - (i32.load - (get_local $0) - ) + (get_local $3) (i32.shl (get_local $2) (i32.const 2) @@ -3045,7 +3210,7 @@ ) (i32.const 0) ) - (func $~lib/array/Array#includes|trampoline (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#includes|trampoline (; 22 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -3068,7 +3233,7 @@ (get_local $2) ) ) - (func $~lib/array/Array#splice (; 21 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#splice (; 23 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (if @@ -3078,8 +3243,8 @@ ) (return) ) - (set_local $3 - (i32.load offset=8 + (set_local $4 + (i32.load offset=4 (get_local $0) ) ) @@ -3088,41 +3253,40 @@ (get_local $1) (i32.const 0) ) - (if - (i32.lt_s - (tee_local $1 + (set_local $1 + (select + (tee_local $3 (i32.add - (get_local $3) + (get_local $4) (get_local $1) ) ) - (i32.const 0) - ) - (set_local $1 - (i32.const 0) - ) - (if - (i32.ge_s - (get_local $1) - (get_local $3) + (tee_local $1 + (i32.const 0) + ) + (i32.gt_s + (get_local $3) + (get_local $1) ) - (return) ) ) - (if - (i32.ge_s - (get_local $1) - (get_local $3) - ) - (return) + ) + (if + (i32.ge_s + (get_local $1) + (get_local $4) ) + (return) ) (call $~lib/memory/move_memory (i32.add - (tee_local $4 - (i32.load - (get_local $0) + (i32.add + (tee_local $3 + (i32.load + (get_local $0) + ) ) + (i32.const 8) ) (i32.shl (get_local $1) @@ -3130,21 +3294,26 @@ ) ) (i32.add - (get_local $4) + (i32.add + (get_local $3) + (i32.const 8) + ) (i32.shl (i32.add (get_local $1) (tee_local $2 (select - (get_local $2) + (tee_local $3 + (get_local $2) + ) (tee_local $1 (i32.sub - (get_local $3) + (get_local $4) (get_local $1) ) ) (i32.lt_s - (get_local $2) + (get_local $3) (get_local $1) ) ) @@ -3158,60 +3327,73 @@ (i32.const 2) ) ) - (i32.store offset=8 + (i32.store offset=4 (get_local $0) (i32.sub - (get_local $3) + (get_local $4) (get_local $2) ) ) ) - (func $~lib/array/Array#__set (; 22 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 24 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) - (local $4 i32) (if - (i32.lt_s + (i32.ge_u (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (if - (i32.ge_s - (get_local $1) - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) + (i32.shr_u + (i32.load + (tee_local $3 + (i32.load + (get_local $0) + ) ) ) - (tee_local $3 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $3) - ) + (i32.const 2) ) ) - ) - (i32.store - (i32.add - (i32.load + (block + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (i32.store (get_local $0) + (tee_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) + ) + ) ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (i32.store offset=8 + (i32.add + (get_local $3) (i32.shl (get_local $1) (i32.const 2) @@ -3220,17 +3402,23 @@ (get_local $2) ) ) - (func $start~anonymous|0 (; 23 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|0 (; 25 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eqz (get_local $0) ) ) - (func $~lib/array/Array#findIndex (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#findIndex (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) (set_local $3 - (i32.load offset=8 + (i32.load + (get_local $0) + ) + ) + (set_local $4 + (i32.load offset=4 (get_local $0) ) ) @@ -3238,19 +3426,19 @@ (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $2) - (get_local $3) + (get_local $4) ) ) (i32.lt_s (get_local $2) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3261,11 +3449,9 @@ (i32.const 3) ) (call_indirect (type $iiii) - (i32.load + (i32.load offset=8 (i32.add - (i32.load - (get_local $0) - ) + (get_local $3) (i32.shl (get_local $2) (i32.const 2) @@ -3293,19 +3479,19 @@ ) (i32.const -1) ) - (func $start~anonymous|1 (; 25 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|1 (; 27 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 1) ) ) - (func $start~anonymous|2 (; 26 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|2 (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 100) ) ) - (func $start~anonymous|3 (; 27 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|3 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3317,7 +3503,7 @@ (i32.const 100) ) ) - (func $start~anonymous|5 (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|5 (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3328,18 +3514,24 @@ (i32.const 100) ) ) - (func $start~anonymous|6 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|6 (; 31 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.ge_s (get_local $0) (i32.const 0) ) ) - (func $~lib/array/Array#every (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#every (; 32 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) (set_local $3 - (i32.load offset=8 + (i32.load + (get_local $0) + ) + ) + (set_local $4 + (i32.load offset=4 (get_local $0) ) ) @@ -3347,19 +3539,19 @@ (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $2) - (get_local $3) + (get_local $4) ) ) (i32.lt_s (get_local $2) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3371,11 +3563,9 @@ ) (i32.eqz (call_indirect (type $iiii) - (i32.load + (i32.load offset=8 (i32.add - (i32.load - (get_local $0) - ) + (get_local $3) (i32.shl (get_local $2) (i32.const 2) @@ -3404,13 +3594,13 @@ ) (i32.const 1) ) - (func $start~anonymous|7 (; 31 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|7 (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.le_s (get_local $0) (i32.const 0) ) ) - (func $start~anonymous|8 (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|8 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3422,13 +3612,13 @@ (i32.const 10) ) ) - (func $start~anonymous|9 (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|9 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.lt_s (get_local $0) (i32.const 10) ) ) - (func $start~anonymous|10 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|10 (; 36 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3439,18 +3629,24 @@ (i32.const 3) ) ) - (func $start~anonymous|11 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|11 (; 37 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.ge_s (get_local $0) (i32.const 3) ) ) - (func $~lib/array/Array#some (; 36 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#some (; 38 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) (set_local $3 - (i32.load offset=8 + (i32.load + (get_local $0) + ) + ) + (set_local $4 + (i32.load offset=4 (get_local $0) ) ) @@ -3458,19 +3654,19 @@ (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $2) - (get_local $3) + (get_local $4) ) ) (i32.lt_s (get_local $2) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3481,11 +3677,9 @@ (i32.const 3) ) (call_indirect (type $iiii) - (i32.load + (i32.load offset=8 (i32.add - (i32.load - (get_local $0) - ) + (get_local $3) (i32.shl (get_local $2) (i32.const 2) @@ -3513,13 +3707,13 @@ ) (i32.const 0) ) - (func $start~anonymous|12 (; 37 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|12 (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.le_s (get_local $0) (i32.const -1) ) ) - (func $start~anonymous|13 (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|13 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3531,13 +3725,13 @@ (i32.const 10) ) ) - (func $start~anonymous|14 (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|14 (; 41 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.gt_s (get_local $0) (i32.const 10) ) ) - (func $start~anonymous|15 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|15 (; 42 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3548,18 +3742,27 @@ (i32.const 3) ) ) - (func $start~anonymous|16 (; 41 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|16 (; 43 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.add (get_local $0) (get_local $1) ) ) - (func $~lib/array/Array#reduce (; 42 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#reduce (; 44 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) (set_local $4 - (i32.load offset=8 + (get_local $2) + ) + (set_local $5 + (i32.load + (get_local $0) + ) + ) + (set_local $6 + (i32.load offset=4 (get_local $0) ) ) @@ -3567,19 +3770,19 @@ (if (i32.and (if (result i32) - (tee_local $5 + (tee_local $2 (i32.lt_s (get_local $3) - (get_local $4) + (get_local $6) ) ) (i32.lt_s (get_local $3) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $5) + (get_local $2) ) (i32.const 1) ) @@ -3587,14 +3790,12 @@ (set_global $argumentCount (i32.const 4) ) - (set_local $2 + (set_local $4 (call_indirect (type $iiiii) - (get_local $2) - (i32.load + (get_local $4) + (i32.load offset=8 (i32.add - (i32.load - (get_local $0) - ) + (get_local $5) (i32.shl (get_local $3) (i32.const 2) @@ -3616,9 +3817,9 @@ ) ) ) - (get_local $2) + (get_local $4) ) - (func $start~anonymous|18 (; 43 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|18 (; 45 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.and (select (get_local $0) @@ -3631,7 +3832,7 @@ (i32.const 1) ) ) - (func $start~anonymous|19 (; 44 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|19 (; 46 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.and (select (get_local $0) @@ -3644,7 +3845,7 @@ (i32.const 1) ) ) - (func $start~anonymous|20 (; 45 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|20 (; 47 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $3) @@ -3656,7 +3857,7 @@ (get_local $1) ) ) - (func $start~anonymous|22 (; 46 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|22 (; 48 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $3) @@ -3667,63 +3868,67 @@ (get_local $1) ) ) - (func $~lib/array/Array#constructor (; 47 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (i32.store - (if (result i32) - (get_local $0) - (get_local $0) - (block (result i32) - (i32.store - (tee_local $2 - (call $~lib/allocator/arena/allocate_memory - (i32.const 12) + (func $~lib/math/murmurHash3 (; 49 ;) (type $II) (param $0 i64) (result i64) + (i64.xor + (tee_local $0 + (i64.mul + (i64.xor + (tee_local $0 + (i64.mul + (i64.xor + (get_local $0) + (i64.shr_u + (get_local $0) + (i64.const 33) + ) + ) + (i64.const -49064778989728563) ) ) - (i32.const 0) - ) - (i32.store offset=4 - (get_local $2) - (i32.const 0) - ) - (i32.store offset=8 - (get_local $2) - (i32.const 0) - ) - (tee_local $0 - (get_local $2) + (i64.shr_u + (get_local $0) + (i64.const 33) + ) ) + (i64.const -4265267296055464877) ) ) - (if (result i32) - (get_local $1) - (call $~lib/allocator/arena/allocate_memory - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - (i32.const 0) + (i64.shr_u + (get_local $0) + (i64.const 33) ) ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) - (i32.store offset=8 - (get_local $0) - (get_local $1) - ) - (get_local $0) ) - (func $std/array/createReverseOrderedArray (; 48 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/math/NativeMath.seedRandom (; 50 ;) (type $Iv) (param $0 i64) + (if + (i64.eqz + (get_local $0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 124) + (i32.const 993) + (i32.const 4) + ) + (unreachable) + ) + ) + (set_global $~lib/math/random_seeded + (i32.const 1) + ) + (set_global $~lib/math/random_state0 + (call $~lib/math/murmurHash3 + (get_local $0) + ) + ) + (set_global $~lib/math/random_state1 + (call $~lib/math/murmurHash3 + (get_global $~lib/math/random_state0) + ) + ) + ) + (func $std/array/createReverseOrderedArray (; 51 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (set_local $1 (call $~lib/array/Array#constructor @@ -3768,14 +3973,22 @@ ) (get_local $1) ) - (func $~lib/math/NativeMath.random (; 49 ;) (type $F) (result f64) + (func $~lib/math/NativeMath.random (; 52 ;) (type $F) (result f64) (local $0 i64) (local $1 i64) (if (i32.eqz (get_global $~lib/math/random_seeded) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 124) + (i32.const 1000) + (i32.const 24) + ) + (unreachable) + ) ) (set_local $0 (get_global $~lib/math/random_state0) @@ -3829,7 +4042,7 @@ (f64.const 1) ) ) - (func $std/array/createRandomOrderedArray (; 50 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createRandomOrderedArray (; 53 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (set_local $0 (call $~lib/array/Array#constructor @@ -3872,7 +4085,7 @@ ) (get_local $0) ) - (func $std/array/createDefaultComparator~anonymous|23 (; 51 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/array/defaultComparator~anonymous|23 (; 54 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (i32.gt_s (get_local $0) @@ -3884,10 +4097,10 @@ ) ) ) - (func $std/array/createDefaultComparator (; 52 ;) (type $i) (result i32) + (func $~lib/internal/array/defaultComparator (; 55 ;) (type $i) (result i32) (i32.const 23) ) - (func $~lib/internal/array/insertionSort (; 53 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/array/insertionSort (; 56 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3913,7 +4126,7 @@ ) (block (set_local $5 - (i32.load + (i32.load offset=8 (i32.add (get_local $4) (i32.shl @@ -3938,7 +4151,7 @@ ) (block (set_local $6 - (i32.load + (i32.load offset=8 (i32.add (get_local $4) (i32.shl @@ -3969,7 +4182,7 @@ (i32.const 1) ) ) - (i32.store + (i32.store offset=8 (i32.add (get_local $4) (i32.shl @@ -3987,7 +4200,7 @@ ) ) ) - (i32.store + (i32.store offset=8 (i32.add (get_local $4) (i32.shl @@ -4012,7 +4225,10 @@ ) (get_local $0) ) - (func $~lib/internal/array/weakHeapSort (; 54 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/allocator/arena/free_memory (; 57 ;) (type $iv) (param $0 i32) + (nop) + ) + (func $~lib/internal/array/weakHeapSort (; 58 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4044,12 +4260,12 @@ (i32.const 0) (get_local $2) ) - (set_local $3 + (set_local $2 (i32.load (get_local $0) ) ) - (set_local $4 + (set_local $3 (i32.sub (get_local $8) (i32.const 1) @@ -4058,18 +4274,18 @@ (loop $continue|0 (if (i32.gt_s - (get_local $4) + (get_local $3) (i32.const 0) ) (block - (set_local $5 - (get_local $4) + (set_local $4 + (get_local $3) ) (loop $continue|1 (if (i32.eq (i32.and - (get_local $5) + (get_local $4) (i32.const 1) ) (i32.and @@ -4079,7 +4295,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $5) + (get_local $4) (i32.const 6) ) (i32.const 2) @@ -4088,7 +4304,7 @@ ) (i32.and (i32.shr_s - (get_local $5) + (get_local $4) (i32.const 1) ) (i32.const 31) @@ -4098,9 +4314,9 @@ ) ) (block - (set_local $5 + (set_local $4 (i32.shr_s - (get_local $5) + (get_local $4) (i32.const 1) ) ) @@ -4108,14 +4324,14 @@ ) ) ) - (set_local $2 - (i32.load + (set_local $7 + (i32.load offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (tee_local $5 + (tee_local $4 (i32.shr_s - (get_local $5) + (get_local $4) (i32.const 1) ) ) @@ -4124,12 +4340,12 @@ ) ) ) - (set_local $7 - (i32.load + (set_local $5 + (i32.load offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $4) + (get_local $3) (i32.const 2) ) ) @@ -4142,8 +4358,8 @@ ) (i32.lt_s (call_indirect (type $iii) - (get_local $2) (get_local $7) + (get_local $5) (get_local $1) ) (i32.const 0) @@ -4155,7 +4371,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $4) + (get_local $3) (i32.const 5) ) (i32.const 2) @@ -4167,7 +4383,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $4) + (get_local $3) (i32.const 5) ) (i32.const 2) @@ -4177,37 +4393,37 @@ (i32.shl (i32.const 1) (i32.and - (get_local $4) + (get_local $3) (i32.const 31) ) ) ) ) - (i32.store + (i32.store offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $4) - (i32.const 2) - ) - ) - (get_local $2) - ) - (i32.store - (i32.add - (get_local $3) - (i32.shl - (get_local $5) + (get_local $3) (i32.const 2) ) ) (get_local $7) ) + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $4) + (i32.const 2) + ) + ) + (get_local $5) + ) ) ) - (set_local $4 + (set_local $3 (i32.sub - (get_local $4) + (get_local $3) (i32.const 1) ) ) @@ -4215,7 +4431,7 @@ ) ) ) - (set_local $4 + (set_local $3 (i32.sub (get_local $8) (i32.const 1) @@ -4224,47 +4440,53 @@ (loop $continue|2 (if (i32.ge_s - (get_local $4) + (get_local $3) (i32.const 2) ) (block (set_local $7 - (i32.load - (get_local $3) + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) ) ) - (i32.store - (get_local $3) - (i32.load + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) + (i32.load offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $4) + (get_local $3) (i32.const 2) ) ) ) ) - (i32.store + (i32.store offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $4) + (get_local $3) (i32.const 2) ) ) (get_local $7) ) - (set_local $2 + (set_local $5 (i32.const 1) ) (loop $continue|3 (if (i32.lt_s - (tee_local $5 + (tee_local $4 (i32.add (i32.shl - (get_local $2) + (get_local $5) (i32.const 1) ) (i32.and @@ -4274,7 +4496,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $2) + (get_local $5) (i32.const 5) ) (i32.const 2) @@ -4282,7 +4504,7 @@ ) ) (i32.and - (get_local $2) + (get_local $5) (i32.const 31) ) ) @@ -4290,11 +4512,11 @@ ) ) ) - (get_local $4) + (get_local $3) ) (block - (set_local $2 - (get_local $5) + (set_local $5 + (get_local $4) ) (br $continue|3) ) @@ -4303,21 +4525,24 @@ (loop $continue|4 (if (i32.gt_s - (get_local $2) + (get_local $5) (i32.const 0) ) (block (set_local $7 - (i32.load - (get_local $3) + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) ) ) - (set_local $5 - (i32.load + (set_local $4 + (i32.load offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $2) + (get_local $5) (i32.const 2) ) ) @@ -4331,7 +4556,7 @@ (i32.lt_s (call_indirect (type $iii) (get_local $7) - (get_local $5) + (get_local $4) (get_local $1) ) (i32.const 0) @@ -4343,7 +4568,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $2) + (get_local $5) (i32.const 5) ) (i32.const 2) @@ -4355,7 +4580,7 @@ (get_local $6) (i32.shl (i32.shr_s - (get_local $2) + (get_local $5) (i32.const 5) ) (i32.const 2) @@ -4365,31 +4590,34 @@ (i32.shl (i32.const 1) (i32.and - (get_local $2) + (get_local $5) (i32.const 31) ) ) ) ) - (i32.store + (i32.store offset=8 (i32.add - (get_local $3) + (get_local $2) (i32.shl - (get_local $2) + (get_local $5) (i32.const 2) ) ) (get_local $7) ) - (i32.store - (get_local $3) - (get_local $5) + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) + (get_local $4) ) ) ) - (set_local $2 + (set_local $5 (i32.shr_s - (get_local $2) + (get_local $5) (i32.const 1) ) ) @@ -4397,9 +4625,9 @@ ) ) ) - (set_local $4 + (set_local $3 (i32.sub - (get_local $4) + (get_local $3) (i32.const 1) ) ) @@ -4410,31 +4638,43 @@ (call $~lib/allocator/arena/free_memory (get_local $6) ) - (set_local $1 - (i32.load offset=4 - (get_local $3) + (set_local $4 + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.const 4) + ) ) ) - (i32.store offset=4 - (get_local $3) - (i32.load - (get_local $3) + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.const 4) + ) + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) ) ) - (i32.store - (get_local $3) - (get_local $1) + (i32.store offset=8 + (i32.add + (get_local $2) + (i32.const 0) + ) + (get_local $4) ) (get_local $0) ) - (func $~lib/array/Array#sort (; 55 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort (; 59 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (if (i32.le_s (tee_local $2 - (call $~lib/array/Array#get:length + (i32.load offset=4 (get_local $0) ) ) @@ -4444,24 +4684,31 @@ (get_local $0) ) ) + (set_local $3 + (i32.load + (get_local $0) + ) + ) (if (i32.eq (get_local $2) (i32.const 2) ) (block - (set_local $3 - (i32.load offset=4 - (tee_local $2 - (i32.load - (get_local $0) - ) + (set_local $2 + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.const 4) ) ) ) (set_local $4 - (i32.load - (get_local $2) + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.const 0) + ) ) ) (if @@ -4471,7 +4718,7 @@ ) (i32.lt_s (call_indirect (type $iii) - (get_local $3) + (get_local $2) (get_local $4) (get_local $1) ) @@ -4479,13 +4726,19 @@ ) ) (block - (i32.store offset=4 - (get_local $2) + (i32.store offset=8 + (i32.add + (get_local $3) + (i32.const 4) + ) (get_local $4) ) - (i32.store + (i32.store offset=8 + (i32.add + (get_local $3) + (i32.const 0) + ) (get_local $2) - (get_local $3) ) ) ) @@ -4495,7 +4748,7 @@ ) ) (if (result i32) - (i32.le_s + (i32.lt_s (get_local $2) (i32.const 256) ) @@ -4509,7 +4762,7 @@ ) ) ) - (func $std/array/isSorted (; 56 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isSorted (; 60 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (set_local $2 @@ -4566,7 +4819,7 @@ ) (i32.const 1) ) - (func $std/array/assertSorted (; 57 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std/array/assertSorted (; 61 ;) (type $iiv) (param $0 i32) (param $1 i32) (if (i32.eqz (call $std/array/isSorted @@ -4580,25 +4833,22 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 77) + (i32.const 96) + (i32.const 419) (i32.const 2) ) (unreachable) ) ) ) - (func $std/array/assertSortedDefault (; 58 ;) (type $iv) (param $0 i32) + (func $std/array/assertSortedDefault (; 62 ;) (type $iv) (param $0 i32) (call $std/array/assertSorted (get_local $0) - (call $std/array/createDefaultComparator) + (call $~lib/internal/array/defaultComparator) ) ) - (func $std/array/isArraysEqual (; 59 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std/array/isArraysEqual (; 63 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) - (set_local $3 - (get_local $2) - ) (if (i32.eqz (get_local $2) @@ -4617,41 +4867,38 @@ (i32.const 0) ) ) - (set_local $3 + (set_local $2 (call $~lib/array/Array#get:length (get_local $0) ) ) ) ) - (set_local $2 - (i32.const 0) - ) (loop $continue|0 (if (i32.lt_s - (get_local $2) (get_local $3) + (get_local $2) ) (block (if (i32.ne (call $~lib/array/Array#__get (get_local $0) - (get_local $2) + (get_local $3) ) (call $~lib/array/Array#__get (get_local $1) - (get_local $2) + (get_local $3) ) ) (return (i32.const 0) ) ) - (set_local $2 + (set_local $3 (i32.add - (get_local $2) + (get_local $3) (i32.const 1) ) ) @@ -4661,7 +4908,7 @@ ) (i32.const 1) ) - (func $std/array/isArraysEqual|trampoline (; 60 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std/array/isArraysEqual|trampoline (; 64 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -4684,19 +4931,19 @@ (get_local $2) ) ) - (func $start~anonymous|24 (; 61 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|24 (; 65 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $0) (get_local $1) ) ) - (func $start~anonymous|25 (; 62 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|25 (; 66 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $1) (get_local $0) ) ) - (func $start (; 63 ;) (type $v) + (func $start (; 67 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -4709,14 +4956,15 @@ (set_global $~lib/allocator/arena/offset (get_global $~lib/allocator/arena/startOffset) ) - (call $~lib/math/NativeMath.seedRandom - (i64.reinterpret/f64 - (call $~lib/math/JSMath.random) - ) - ) (set_global $std/array/arr - (call $~lib/allocator/arena/allocate_memory - (i32.const 12) + (block (result i32) + (set_global $argumentCount + (i32.const 0) + ) + (call $~lib/array/Array#constructor|trampoline + (i32.const 0) + (i32.const 0) + ) ) ) (if @@ -4726,22 +4974,22 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 86) + (i32.const 96) + (i32.const 17) (i32.const 0) ) (unreachable) ) ) (if - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 87) + (i32.const 96) + (i32.const 18) (i32.const 0) ) (unreachable) @@ -4764,8 +5012,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 91) + (i32.const 96) + (i32.const 22) (i32.const 0) ) (unreachable) @@ -4781,8 +5029,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 92) + (i32.const 96) + (i32.const 23) (i32.const 0) ) (unreachable) @@ -4790,7 +5038,7 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -4798,8 +5046,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 93) + (i32.const 96) + (i32.const 24) (i32.const 0) ) (unreachable) @@ -4818,8 +5066,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 97) + (i32.const 96) + (i32.const 28) (i32.const 0) ) (unreachable) @@ -4832,8 +5080,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 98) + (i32.const 96) + (i32.const 29) (i32.const 0) ) (unreachable) @@ -4841,7 +5089,7 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -4849,8 +5097,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 99) + (i32.const 96) + (i32.const 30) (i32.const 0) ) (unreachable) @@ -4872,8 +5120,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 103) + (i32.const 96) + (i32.const 34) (i32.const 0) ) (unreachable) @@ -4881,7 +5129,7 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -4889,8 +5137,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 104) + (i32.const 96) + (i32.const 35) (i32.const 0) ) (unreachable) @@ -4907,8 +5155,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 105) + (i32.const 96) + (i32.const 36) (i32.const 0) ) (unreachable) @@ -4930,8 +5178,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 109) + (i32.const 96) + (i32.const 40) (i32.const 0) ) (unreachable) @@ -4939,7 +5187,7 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 2) @@ -4947,8 +5195,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 110) + (i32.const 96) + (i32.const 41) (i32.const 0) ) (unreachable) @@ -4965,8 +5213,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 111) + (i32.const 96) + (i32.const 42) (i32.const 0) ) (unreachable) @@ -4983,8 +5231,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 112) + (i32.const 96) + (i32.const 43) (i32.const 0) ) (unreachable) @@ -5006,8 +5254,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 116) + (i32.const 96) + (i32.const 47) (i32.const 0) ) (unreachable) @@ -5015,16 +5263,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 4) + (i32.const 3) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 117) + (i32.const 96) + (i32.const 48) (i32.const 0) ) (unreachable) @@ -5041,8 +5289,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 118) + (i32.const 96) + (i32.const 49) (i32.const 0) ) (unreachable) @@ -5059,8 +5307,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 119) + (i32.const 96) + (i32.const 50) (i32.const 0) ) (unreachable) @@ -5077,8 +5325,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 120) + (i32.const 96) + (i32.const 51) (i32.const 0) ) (unreachable) @@ -5100,8 +5348,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 124) + (i32.const 96) + (i32.const 57) (i32.const 0) ) (unreachable) @@ -5109,7 +5357,7 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 4) @@ -5117,8 +5365,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 125) + (i32.const 96) + (i32.const 58) (i32.const 0) ) (unreachable) @@ -5135,8 +5383,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 126) + (i32.const 96) + (i32.const 59) (i32.const 0) ) (unreachable) @@ -5153,8 +5401,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 127) + (i32.const 96) + (i32.const 60) (i32.const 0) ) (unreachable) @@ -5171,8 +5419,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 128) + (i32.const 96) + (i32.const 61) (i32.const 0) ) (unreachable) @@ -5189,8 +5437,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 129) + (i32.const 96) + (i32.const 62) (i32.const 0) ) (unreachable) @@ -5212,8 +5460,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 133) + (i32.const 96) + (i32.const 66) (i32.const 0) ) (unreachable) @@ -5221,16 +5469,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 134) + (i32.const 96) + (i32.const 67) (i32.const 0) ) (unreachable) @@ -5247,8 +5495,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 135) + (i32.const 96) + (i32.const 68) (i32.const 0) ) (unreachable) @@ -5265,8 +5513,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 136) + (i32.const 96) + (i32.const 69) (i32.const 0) ) (unreachable) @@ -5283,8 +5531,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 137) + (i32.const 96) + (i32.const 70) (i32.const 0) ) (unreachable) @@ -5301,8 +5549,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 138) + (i32.const 96) + (i32.const 71) (i32.const 0) ) (unreachable) @@ -5319,8 +5567,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 139) + (i32.const 96) + (i32.const 72) (i32.const 0) ) (unreachable) @@ -5339,8 +5587,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 143) + (i32.const 96) + (i32.const 78) (i32.const 0) ) (unreachable) @@ -5356,8 +5604,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 144) + (i32.const 96) + (i32.const 79) (i32.const 0) ) (unreachable) @@ -5365,16 +5613,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 145) + (i32.const 96) + (i32.const 80) (i32.const 0) ) (unreachable) @@ -5391,8 +5639,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 146) + (i32.const 96) + (i32.const 81) (i32.const 0) ) (unreachable) @@ -5409,8 +5657,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 147) + (i32.const 96) + (i32.const 82) (i32.const 0) ) (unreachable) @@ -5427,8 +5675,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 148) + (i32.const 96) + (i32.const 83) (i32.const 0) ) (unreachable) @@ -5445,8 +5693,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 149) + (i32.const 96) + (i32.const 84) (i32.const 0) ) (unreachable) @@ -5465,8 +5713,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 153) + (i32.const 96) + (i32.const 88) (i32.const 0) ) (unreachable) @@ -5482,8 +5730,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 154) + (i32.const 96) + (i32.const 89) (i32.const 0) ) (unreachable) @@ -5491,16 +5739,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 155) + (i32.const 96) + (i32.const 90) (i32.const 0) ) (unreachable) @@ -5517,8 +5765,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 156) + (i32.const 96) + (i32.const 91) (i32.const 0) ) (unreachable) @@ -5535,8 +5783,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 157) + (i32.const 96) + (i32.const 92) (i32.const 0) ) (unreachable) @@ -5553,8 +5801,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 158) + (i32.const 96) + (i32.const 93) (i32.const 0) ) (unreachable) @@ -5575,8 +5823,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 162) + (i32.const 96) + (i32.const 99) (i32.const 0) ) (unreachable) @@ -5584,16 +5832,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 163) + (i32.const 96) + (i32.const 100) (i32.const 0) ) (unreachable) @@ -5610,8 +5858,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 164) + (i32.const 96) + (i32.const 101) (i32.const 0) ) (unreachable) @@ -5628,8 +5876,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 165) + (i32.const 96) + (i32.const 102) (i32.const 0) ) (unreachable) @@ -5646,8 +5894,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 166) + (i32.const 96) + (i32.const 103) (i32.const 0) ) (unreachable) @@ -5682,8 +5930,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 173) + (i32.const 96) + (i32.const 112) (i32.const 0) ) (unreachable) @@ -5709,8 +5957,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 177) + (i32.const 96) + (i32.const 116) (i32.const 0) ) (unreachable) @@ -5736,8 +5984,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 181) + (i32.const 96) + (i32.const 120) (i32.const 0) ) (unreachable) @@ -5758,8 +6006,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 185) + (i32.const 96) + (i32.const 124) (i32.const 0) ) (unreachable) @@ -5780,8 +6028,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 189) + (i32.const 96) + (i32.const 128) (i32.const 0) ) (unreachable) @@ -5802,8 +6050,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 193) + (i32.const 96) + (i32.const 132) (i32.const 0) ) (unreachable) @@ -5824,8 +6072,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 197) + (i32.const 96) + (i32.const 136) (i32.const 0) ) (unreachable) @@ -5846,8 +6094,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 201) + (i32.const 96) + (i32.const 140) (i32.const 0) ) (unreachable) @@ -5868,8 +6116,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 205) + (i32.const 96) + (i32.const 144) (i32.const 0) ) (unreachable) @@ -5890,8 +6138,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 209) + (i32.const 96) + (i32.const 148) (i32.const 0) ) (unreachable) @@ -5917,8 +6165,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 213) + (i32.const 96) + (i32.const 154) (i32.const 0) ) (unreachable) @@ -5944,8 +6192,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 217) + (i32.const 96) + (i32.const 158) (i32.const 0) ) (unreachable) @@ -5968,8 +6216,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 221) + (i32.const 96) + (i32.const 162) (i32.const 0) ) (unreachable) @@ -5987,8 +6235,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 225) + (i32.const 96) + (i32.const 166) (i32.const 0) ) (unreachable) @@ -6009,8 +6257,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 229) + (i32.const 96) + (i32.const 170) (i32.const 0) ) (unreachable) @@ -6031,8 +6279,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 233) + (i32.const 96) + (i32.const 174) (i32.const 0) ) (unreachable) @@ -6053,8 +6301,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 237) + (i32.const 96) + (i32.const 178) (i32.const 0) ) (unreachable) @@ -6075,8 +6323,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 241) + (i32.const 96) + (i32.const 182) (i32.const 0) ) (unreachable) @@ -6097,8 +6345,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 245) + (i32.const 96) + (i32.const 186) (i32.const 0) ) (unreachable) @@ -6119,8 +6367,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 249) + (i32.const 96) + (i32.const 190) (i32.const 0) ) (unreachable) @@ -6141,8 +6389,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 253) + (i32.const 96) + (i32.const 194) (i32.const 0) ) (unreachable) @@ -6150,16 +6398,16 @@ ) (if (i32.ne - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 254) + (i32.const 96) + (i32.const 195) (i32.const 0) ) (unreachable) @@ -6176,8 +6424,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 255) + (i32.const 96) + (i32.const 196) (i32.const 0) ) (unreachable) @@ -6194,8 +6442,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 256) + (i32.const 96) + (i32.const 197) (i32.const 0) ) (unreachable) @@ -6232,8 +6480,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 265) + (i32.const 96) + (i32.const 207) (i32.const 0) ) (unreachable) @@ -6253,8 +6501,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 268) + (i32.const 96) + (i32.const 210) (i32.const 0) ) (unreachable) @@ -6274,8 +6522,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 271) + (i32.const 96) + (i32.const 213) (i32.const 0) ) (unreachable) @@ -6295,8 +6543,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 279) + (i32.const 96) + (i32.const 221) (i32.const 0) ) (unreachable) @@ -6312,8 +6560,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 280) + (i32.const 96) + (i32.const 222) (i32.const 0) ) (unreachable) @@ -6333,8 +6581,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 282) + (i32.const 96) + (i32.const 224) (i32.const 0) ) (unreachable) @@ -6374,8 +6622,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 295) + (i32.const 96) + (i32.const 237) (i32.const 0) ) (unreachable) @@ -6391,8 +6639,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 296) + (i32.const 96) + (i32.const 238) (i32.const 0) ) (unreachable) @@ -6424,8 +6672,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 302) + (i32.const 96) + (i32.const 246) (i32.const 0) ) (unreachable) @@ -6442,8 +6690,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 305) + (i32.const 96) + (i32.const 249) (i32.const 0) ) (unreachable) @@ -6463,8 +6711,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 313) + (i32.const 96) + (i32.const 257) (i32.const 0) ) (unreachable) @@ -6480,8 +6728,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 314) + (i32.const 96) + (i32.const 258) (i32.const 0) ) (unreachable) @@ -6498,8 +6746,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 316) + (i32.const 96) + (i32.const 260) (i32.const 0) ) (unreachable) @@ -6539,8 +6787,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 329) + (i32.const 96) + (i32.const 273) (i32.const 0) ) (unreachable) @@ -6556,8 +6804,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 330) + (i32.const 96) + (i32.const 274) (i32.const 0) ) (unreachable) @@ -6589,8 +6837,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 336) + (i32.const 96) + (i32.const 282) (i32.const 0) ) (unreachable) @@ -6607,8 +6855,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 339) + (i32.const 96) + (i32.const 285) (i32.const 0) ) (unreachable) @@ -6625,8 +6873,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 347) + (i32.const 96) + (i32.const 293) (i32.const 0) ) (unreachable) @@ -6642,8 +6890,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 348) + (i32.const 96) + (i32.const 294) (i32.const 0) ) (unreachable) @@ -6663,8 +6911,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 350) + (i32.const 96) + (i32.const 296) (i32.const 0) ) (unreachable) @@ -6701,8 +6949,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 363) + (i32.const 96) + (i32.const 309) (i32.const 0) ) (unreachable) @@ -6718,8 +6966,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 364) + (i32.const 96) + (i32.const 310) (i32.const 0) ) (unreachable) @@ -6752,8 +7000,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 371) + (i32.const 96) + (i32.const 318) (i32.const 0) ) (unreachable) @@ -6774,8 +7022,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 375) + (i32.const 96) + (i32.const 322) (i32.const 0) ) (unreachable) @@ -6796,8 +7044,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 378) + (i32.const 96) + (i32.const 325) (i32.const 0) ) (unreachable) @@ -6815,8 +7063,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 381) + (i32.const 96) + (i32.const 328) (i32.const 0) ) (unreachable) @@ -6837,8 +7085,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 389) + (i32.const 96) + (i32.const 336) (i32.const 0) ) (unreachable) @@ -6854,8 +7102,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 390) + (i32.const 96) + (i32.const 337) (i32.const 0) ) (unreachable) @@ -6876,8 +7124,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 392) + (i32.const 96) + (i32.const 339) (i32.const 0) ) (unreachable) @@ -6918,8 +7166,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 405) + (i32.const 96) + (i32.const 352) (i32.const 0) ) (unreachable) @@ -6935,29 +7183,34 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 406) + (i32.const 96) + (i32.const 353) (i32.const 0) ) (unreachable) ) ) - (set_global $std/array/revesed64 + (call $~lib/math/NativeMath.seedRandom + (i64.reinterpret/f64 + (call $~lib/math/JSMath.random) + ) + ) + (set_global $std/array/reversed64 (call $std/array/createReverseOrderedArray (i32.const 64) ) ) - (set_global $std/array/revesed128 + (set_global $std/array/reversed128 (call $std/array/createReverseOrderedArray (i32.const 128) ) ) - (set_global $std/array/revesed1024 + (set_global $std/array/reversed1024 (call $std/array/createReverseOrderedArray (i32.const 1024) ) ) - (set_global $std/array/revesed10000 + (set_global $std/array/reversed10000 (call $std/array/createReverseOrderedArray (i32.const 10000) ) @@ -6968,10 +7221,10 @@ ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed0) + (get_global $std/array/reversed0) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed1) + (get_global $std/array/reversed1) ) (if (block (result i32) @@ -6980,8 +7233,8 @@ ) (i32.eqz (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed1) - (i32.const 216) + (get_global $std/array/reversed1) + (i32.const 296) (i32.const 0) ) ) @@ -6989,15 +7242,15 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 429) + (i32.const 96) + (i32.const 445) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed2) + (get_global $std/array/reversed2) ) (if (block (result i32) @@ -7006,8 +7259,8 @@ ) (i32.eqz (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed2) - (i32.const 232) + (get_global $std/array/reversed2) + (i32.const 320) (i32.const 0) ) ) @@ -7015,15 +7268,15 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 432) + (i32.const 96) + (i32.const 448) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed4) + (get_global $std/array/reversed4) ) (if (block (result i32) @@ -7032,7 +7285,7 @@ ) (i32.eqz (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed4) + (get_global $std/array/reversed4) (get_global $std/array/expected4) (i32.const 0) ) @@ -7041,20 +7294,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 435) + (i32.const 96) + (i32.const 451) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed64) + (get_global $std/array/reversed64) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed64) + (get_global $std/array/reversed64) (get_global $std/array/expected4) (i32.const 4) ) @@ -7062,20 +7315,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 438) + (i32.const 96) + (i32.const 454) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed128) + (get_global $std/array/reversed128) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed128) + (get_global $std/array/reversed128) (get_global $std/array/expected4) (i32.const 4) ) @@ -7083,20 +7336,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 441) + (i32.const 96) + (i32.const 457) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed1024) + (get_global $std/array/reversed1024) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed1024) + (get_global $std/array/reversed1024) (get_global $std/array/expected4) (i32.const 4) ) @@ -7104,20 +7357,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 444) + (i32.const 96) + (i32.const 460) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed10000) + (get_global $std/array/reversed10000) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed10000) + (get_global $std/array/reversed10000) (get_global $std/array/expected4) (i32.const 4) ) @@ -7125,8 +7378,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 447) + (i32.const 96) + (i32.const 463) (i32.const 0) ) (unreachable) diff --git a/tests/compiler/std/array.ts b/tests/compiler/std/array.ts index d083f1d0..43cbee61 100644 --- a/tests/compiler/std/array.ts +++ b/tests/compiler/std/array.ts @@ -1,128 +1,61 @@ import "allocator/arena"; +import { Array } from "array"; +import { defaultComparator } from "internal/array"; -// Default comparator -function createDefaultComparator(): (a: T, b: T) => i32 { - return (a: T, b: T): i32 => ( - (a > b) - (a < b) - ); +// Obtains the internal capacity of an array from its backing buffer. +function internalCapacity(array: Array): i32 { + // the memory region used by the backing buffer might still be larger in that the ArrayBuffer + // pre-allocates a power of 2 sized buffer itself and reuses it as long as it isn't exceeded. + var buffer: ArrayBuffer = array.buffer_; + return buffer.byteLength >> alignof(); } -// Check is array sorted -function isSorted(data: Array, comparator: (a: T, b: T) => i32 = createDefaultComparator()): bool { - for (let i: i32 = 1, len: i32 = data.length; i < len; i++) { - if (comparator(data[i - 1], data[i]) > 0) { - return false; - } - } - return true; -} +var arr = new Array(); -// Check is equality for arrays -function isArraysEqual(a: Array, b: Array, maxLen: i32 = 0): bool { - var len = maxLen; - if (!maxLen) { - if (a.length != b.length) { - return false; - } - len = a.length; - } - for (let i: i32 = 0; i < len; i++) { - if (a[i] != b[i]) return false; - } - return true; -} - -function createReverseOrderedArray(size: i32): Array { - var arr = new Array(size); - for (let i: i32 = 0; i < arr.length; i++) { - arr[i] = arr.length - 1 - i; - } - return arr; -} - -NativeMath.seedRandom(reinterpret(JSMath.random())); - -function createRandomOrderedArray(size: i32): Array { - var arr = new Array(size); - for (let i: i32 = 0; i < arr.length; i++) { - arr[i] = (NativeMath.random() * arr.length); - } - return arr; -} - -/* -function createReverseOrderedNestedArray(size: i32): Array> { - var arr = new Array>(size); - for (let i: i32 = 0; i < arr.length; i++) { - arr[i] = new Array(1); - arr[i][0] = arr.length - 1 - i; - } - return arr; -} - -class Proxy { - constructor(public x: T) {} -} - -function createReverseOrderedElementsArray(size: i32): Proxy[] { - var arr = new Array>(size); - for (let i: i32 = 0; i < arr.length; i++) { - arr[i] = new Proxy(arr.length - 1 - i); - } - return arr; -} -*/ - -function assertSorted(arr: Array, comparator: (a: T, b: T) => i32): void { - assert(isSorted(arr.sort(comparator), comparator)); -} - -function assertSortedDefault(arr: Array): void { - assertSorted(arr, createDefaultComparator()); -} - -var arr = changetype(allocate_memory(sizeof() + 2 * sizeof())); +// Array#push/pop ////////////////////////////////////////////////////////////////////////////////// assert(arr.length == 0); -assert(arr.__capacity == 0); +assert(internalCapacity(arr) == 0); arr.push(42); assert(arr[0] == 42); assert(arr.length == 1); -assert(arr.__capacity == 1); +assert(internalCapacity(arr) == 1); var i = arr.pop(); assert(i == 42); assert(arr.length == 0); -assert(arr.__capacity == 1); +assert(internalCapacity(arr) == 1); arr.push(43); assert(arr.length == 1); -assert(arr.__capacity == 1); +assert(internalCapacity(arr) == 1); assert(arr[0] == 43); arr.push(44); assert(arr.length == 2); -assert(arr.__capacity == 2); +assert(internalCapacity(arr) == 2); assert(arr[0] == 43); assert(arr[1] == 44); arr.push(45); assert(arr.length == 3); -assert(arr.__capacity == 4); +assert(internalCapacity(arr) == 3); assert(arr[0] == 43); assert(arr[1] == 44); assert(arr[2] == 45); +// Array#unshift /////////////////////////////////////////////////////////////////////////////////// + arr.unshift(42); assert(arr.length == 4); -assert(arr.__capacity == 4); +assert(internalCapacity(arr) == 4); assert(arr[0] == 42); assert(arr[1] == 43); assert(arr[2] == 44); @@ -131,18 +64,20 @@ assert(arr[3] == 45); arr.unshift(41); assert(arr.length == 5); -assert(arr.__capacity == 8); +assert(internalCapacity(arr) == 5); assert(arr[0] == 41); assert(arr[1] == 42); assert(arr[2] == 43); assert(arr[3] == 44); assert(arr[4] == 45); +// Array#shift ///////////////////////////////////////////////////////////////////////////////////// + i = arr.shift(); assert(i == 41); assert(arr.length == 4); -assert(arr.__capacity == 8); +assert(internalCapacity(arr) == 5); assert(arr[0] == 42); assert(arr[1] == 43); assert(arr[2] == 44); @@ -152,15 +87,17 @@ i = arr.pop(); assert(i == 45); assert(arr.length == 3); -assert(arr.__capacity == 8); +assert(internalCapacity(arr) == 5); assert(arr[0] == 42); assert(arr[1] == 43); assert(arr[2] == 44); +// Array#reverse /////////////////////////////////////////////////////////////////////////////////// + arr.reverse(); assert(arr.length == 3); -assert(arr.__capacity == 8); +assert(internalCapacity(arr) == 5); assert(arr[0] == 44); assert(arr[1] == 43); assert(arr[2] == 42); @@ -168,6 +105,8 @@ assert(arr[2] == 42); arr.push(43); arr.push(44); +// Array#indexOf /////////////////////////////////////////////////////////////////////////////////// + i = arr.indexOf(44); assert(i == 0); @@ -208,6 +147,8 @@ i = arr.indexOf(43, 2); assert(i == 3); +// Array#includes ////////////////////////////////////////////////////////////////////////////////// + var includes = arr.includes(44); assert(includes == true); @@ -251,16 +192,17 @@ assert(includes == true); arr.splice(1, 1); assert(arr.length == 4); -assert(arr.__capacity == 8); +assert(internalCapacity(arr) == 5); assert(arr[0] == 44); assert(arr[1] == 42); +// Array#findIndex ///////////////////////////////////////////////////////////////////////////////// arr[0] = 0; arr[1] = 1; arr[2] = 2; arr[3] = 3; -/*=============================== findIndex ==========================*/ + i = arr.findIndex((value: i32, index: i32, array: Array): bool => value == 0); assert(i == 0); @@ -272,7 +214,7 @@ assert(i == -1); // Test side effect push i = arr.findIndex((value: i32, index: i32, array: Array): bool => { - array.push(100); //push side effect should not affect this method by spec + array.push(100); // push side effect should not affect this method by spec return value == 100; }); // array should be changed, but this method result should be calculated for old array length @@ -288,7 +230,7 @@ arr.pop(); // Test side effect pop i = arr.findIndex((value: i32, index: i32, array: Array): bool => { - array.pop(); //poped items shouldn't be looked up, and we shouldn't go out of bounds + array.pop(); // poped items shouldn't be looked up, and we shouldn't go out of bounds return value == 100; }); // only 2 first items was looked up, since last 2 was removed by .pop() @@ -297,7 +239,9 @@ assert(arr.length == 2); arr.push(2); arr.push(3); -/*=============================== every ==========================*/ + +// Array#every ///////////////////////////////////////////////////////////////////////////////////// + var every = arr.every((value: i32, index: i32, array: Array): bool => value >= 0); assert(every == true); @@ -306,7 +250,7 @@ assert(every == false); // Test side effect push every = arr.every((value: i32, index: i32, array: Array): bool => { - array.push(100); //push side effect should not affect this method by spec + array.push(100); // push side effect should not affect this method by spec return value < 10; }); // array should be changed, but this method result should be calculated for old array length @@ -331,7 +275,9 @@ assert(arr.length == 2); arr.push(2); arr.push(3); -/*=============================== some ==========================*/ + +// Array#some ////////////////////////////////////////////////////////////////////////////////////// + var some = arr.some((value: i32, index: i32, array: Array): bool => value >= 3); assert(some == true); @@ -340,7 +286,7 @@ assert(some == false); // Test side effect push some = arr.some((value: i32, index: i32, array: Array): bool => { - array.push(100); //push side effect should not affect this method by spec + array.push(100); // push side effect should not affect this method by spec return value > 10; }); // array should be changed, but this method result should be calculated for old array length @@ -356,7 +302,7 @@ arr.pop(); // Test side effect pop some = arr.some((value: i32, index: i32, array: Array): bool => { - array.pop(); //poped items shouldn't be looked up, and we shouldn't go out of bounds + array.pop(); // poped items shouldn't be looked up, and we shouldn't go out of bounds return value > 3; }); // only 2 first items was looked up, since last 2 was removed by .pop() @@ -365,7 +311,8 @@ assert(arr.length == 2); arr.push(2); arr.push(3); -/*=============================== reduce ==========================*/ + +// Array#reduce //////////////////////////////////////////////////////////////////////////////////// i = arr.reduce(((prev: i32, current: i32, index: i32, array: Array): i32 => prev + current), 0); assert(i == 6); @@ -382,7 +329,7 @@ assert(boolVal == false); // Test side effect push i = arr.reduce(((prev: i32, current: i32, index: i32, array: Array): i32 => { - array.push(1); //push side effect should not affect this method by spec + array.push(1); // push side effect should not affect this method by spec return prev + current; }), 0); // array should be changed, but this method result should be calculated for old array length @@ -405,46 +352,115 @@ i = arr.reduce(((prev: i32, current: i32, index: i32, array: Array): i assert(i == 1); assert(arr.length == 2); -/*=============================== sort ==========================*/ +// Array#sort ////////////////////////////////////////////////////////////////////////////////////// -var revesed0: Array = []; -var revesed1: Array = [1]; -var revesed2: Array = [2, 1]; -var revesed4: Array = [3, 2, 1, 0]; +// Checks if an array is properly sorted +function isSorted(data: Array, comparator: (a: T, b: T) => i32 = defaultComparator()): bool { + for (let i: i32 = 1, len: i32 = data.length; i < len; i++) { + if (comparator(data[i - 1], data[i]) > 0) return false; + } + return true; +} + +// Checks if two arrays are equal +function isArraysEqual(a: Array, b: Array, len: i32 = 0): bool { + if (!len) { + if (a.length != b.length) return false; + len = a.length; + } + for (let i = 0; i < len; i++) { + if (a[i] != b[i]) return false; + } + return true; +} + +function createReverseOrderedArray(size: i32): Array { + var arr = new Array(size); + for (let i = 0; i < arr.length; i++) { + arr[i] = arr.length - 1 - i; + } + return arr; +} + +NativeMath.seedRandom(reinterpret(JSMath.random())); + +function createRandomOrderedArray(size: i32): Array { + var arr = new Array(size); + for (let i = 0; i < arr.length; i++) { + arr[i] = (NativeMath.random() * arr.length); + } + return arr; +} + +/* +function createReverseOrderedNestedArray(size: i32): Array> { + var arr = new Array>(size); + for (let i: i32 = 0; i < arr.length; i++) { + arr[i] = new Array(1); + arr[i][0] = arr.length - 1 - i; + } + return arr; +} + +class Proxy { + constructor(public x: T) {} +} + +function createReverseOrderedElementsArray(size: i32): Proxy[] { + var arr = new Array>(size); + for (let i: i32 = 0; i < arr.length; i++) { + arr[i] = new Proxy(arr.length - 1 - i); + } + return arr; +} +*/ + +function assertSorted(arr: Array, comparator: (a: T, b: T) => i32): void { + assert(isSorted(arr.sort(comparator), comparator)); +} + +function assertSortedDefault(arr: Array): void { + assertSorted(arr, defaultComparator()); +} + +var reversed0: Array = []; +var reversed1: Array = [1]; +var reversed2: Array = [2, 1]; +var reversed4: Array = [3, 2, 1, 0]; var expected4: Array = [0, 1, 2, 3]; -var revesed64 = createReverseOrderedArray(64); -var revesed128 = createReverseOrderedArray(128); -var revesed1024 = createReverseOrderedArray(1024); -var revesed10000 = createReverseOrderedArray(10000); +var reversed64 = createReverseOrderedArray(64); +var reversed128 = createReverseOrderedArray(128); +var reversed1024 = createReverseOrderedArray(1024); +var reversed10000 = createReverseOrderedArray(10000); var randomized512 = createRandomOrderedArray(512); // Test sorting with with default comparator -assertSortedDefault(revesed0); +assertSortedDefault(reversed0); -assertSortedDefault(revesed1); -assert(isArraysEqual(revesed1, [1])); +assertSortedDefault(reversed1); +assert(isArraysEqual(reversed1, [1])); -assertSortedDefault(revesed2); -assert(isArraysEqual(revesed2, [1, 2])); +assertSortedDefault(reversed2); +assert(isArraysEqual(reversed2, [1, 2])); -assertSortedDefault(revesed4); -assert(isArraysEqual(revesed4, expected4)); +assertSortedDefault(reversed4); +assert(isArraysEqual(reversed4, expected4)); -assertSortedDefault(revesed64); -assert(isArraysEqual(revesed64, expected4, 4)); +assertSortedDefault(reversed64); +assert(isArraysEqual(reversed64, expected4, 4)); -assertSortedDefault(revesed128); -assert(isArraysEqual(revesed128, expected4, 4)); +assertSortedDefault(reversed128); +assert(isArraysEqual(reversed128, expected4, 4)); -assertSortedDefault(revesed1024); -assert(isArraysEqual(revesed1024, expected4, 4)); +assertSortedDefault(reversed1024); +assert(isArraysEqual(reversed1024, expected4, 4)); -assertSortedDefault(revesed10000); -assert(isArraysEqual(revesed10000, expected4, 4)); +assertSortedDefault(reversed10000); +assert(isArraysEqual(reversed10000, expected4, 4)); assertSortedDefault(randomized512); diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index f09b358d..e6a068bd 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -1,138 +1,87 @@ (module (type $i (func (result i32))) - (type $F (func (result f64))) - (type $Iv (func (param i64))) - (type $iiiiv (func (param i32 i32 i32 i32))) - (type $II (func (param i64) (result i64))) - (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) - (type $iiv (func (param i32 i32))) + (type $iiiiv (func (param i32 i32 i32 i32))) + (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) - (type $iv (func (param i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $iiiii (func (param i32 i32 i32 i32) (result i32))) + (type $F (func (result f64))) + (type $Iv (func (param i64))) + (type $II (func (param i64) (result i64))) + (type $iv (func (param i32))) + (type $iiv (func (param i32 i32))) (type $v (func)) - (import "JSMath" "random" (func $~lib/math/JSMath.random (result f64))) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) + (import "JSMath" "random" (func $~lib/math/JSMath.random (result f64))) (global $~lib/internal/allocator/AL_BITS i32 (i32.const 3)) (global $~lib/internal/allocator/AL_SIZE i32 (i32.const 8)) (global $~lib/internal/allocator/AL_MASK i32 (i32.const 7)) (global $~lib/internal/allocator/MAX_SIZE_32 i32 (i32.const 1073741824)) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $~lib/math/random_seeded (mut i32) (i32.const 0)) - (global $~lib/math/random_state0 (mut i64) (i64.const 0)) - (global $~lib/math/random_state1 (mut i64) (i64.const 0)) + (global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8)) + (global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816)) + (global $argumentCount (mut i32) (i32.const 0)) (global $std/array/arr (mut i32) (i32.const 0)) (global $std/array/i (mut i32) (i32.const 0)) - (global $argumentCount (mut i32) (i32.const 0)) (global $std/array/includes (mut i32) (i32.const 0)) (global $std/array/every (mut i32) (i32.const 0)) (global $std/array/some (mut i32) (i32.const 0)) (global $std/array/boolVal (mut i32) (i32.const 0)) - (global $std/array/revesed0 (mut i32) (i32.const 96)) - (global $std/array/revesed1 (mut i32) (i32.const 112)) - (global $std/array/revesed2 (mut i32) (i32.const 128)) - (global $std/array/revesed4 (mut i32) (i32.const 152)) - (global $std/array/expected4 (mut i32) (i32.const 184)) - (global $std/array/revesed64 (mut i32) (i32.const 0)) - (global $std/array/revesed128 (mut i32) (i32.const 0)) - (global $std/array/revesed1024 (mut i32) (i32.const 0)) - (global $std/array/revesed10000 (mut i32) (i32.const 0)) + (global $~lib/math/random_seeded (mut i32) (i32.const 0)) + (global $~lib/math/random_state0 (mut i64) (i64.const 0)) + (global $~lib/math/random_state1 (mut i64) (i64.const 0)) + (global $std/array/reversed0 (mut i32) (i32.const 152)) + (global $std/array/reversed1 (mut i32) (i32.const 168)) + (global $std/array/reversed2 (mut i32) (i32.const 192)) + (global $std/array/reversed4 (mut i32) (i32.const 216)) + (global $std/array/expected4 (mut i32) (i32.const 256)) + (global $std/array/reversed64 (mut i32) (i32.const 0)) + (global $std/array/reversed128 (mut i32) (i32.const 0)) + (global $std/array/reversed1024 (mut i32) (i32.const 0)) + (global $std/array/reversed10000 (mut i32) (i32.const 0)) (global $std/array/randomized512 (mut i32) (i32.const 0)) (global $std/array/randomized64 (mut i32) (i32.const 0)) (global $std/array/randomized257 (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 252)) + (global $HEAP_BASE i32 (i32.const 344)) (table 28 28 anyfunc) - (elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~anonymous|2 $start~anonymous|3 $start~anonymous|4 $start~anonymous|5 $start~anonymous|6 $start~anonymous|7 $start~anonymous|8 $start~anonymous|9 $start~anonymous|10 $start~anonymous|11 $start~anonymous|12 $start~anonymous|13 $start~anonymous|14 $start~anonymous|15 $start~anonymous|16 $start~anonymous|17 $start~anonymous|18 $start~anonymous|19 $start~anonymous|20 $start~anonymous|21 $start~anonymous|22 $std/array/createDefaultComparator~anonymous|23 $start~anonymous|24 $start~anonymous|25 $start~anonymous|26 $start~anonymous|27) + (elem (i32.const 0) $start~anonymous|0 $start~anonymous|1 $start~anonymous|2 $start~anonymous|3 $start~anonymous|4 $start~anonymous|5 $start~anonymous|6 $start~anonymous|7 $start~anonymous|8 $start~anonymous|9 $start~anonymous|10 $start~anonymous|11 $start~anonymous|12 $start~anonymous|13 $start~anonymous|14 $start~anonymous|15 $start~anonymous|16 $start~anonymous|17 $start~anonymous|18 $start~anonymous|19 $start~anonymous|20 $start~anonymous|21 $start~anonymous|22 $~lib/internal/array/defaultComparator~anonymous|23 $start~anonymous|24 $start~anonymous|25 $start~anonymous|26 $start~anonymous|27) (memory $0 1) - (data (i32.const 4) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s\00") - (data (i32.const 32) "\0c\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 60) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 96) "l\00\00\00\00\00\00\00\00\00\00\00") - (data (i32.const 112) "|\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00") - (data (i32.const 128) "\8c\00\00\00\02\00\00\00\02\00\00\00\02\00\00\00\01\00\00\00") - (data (i32.const 152) "\a4\00\00\00\04\00\00\00\04\00\00\00\03\00\00\00\02\00\00\00\01\00\00\00\00\00\00\00") - (data (i32.const 184) "\c4\00\00\00\04\00\00\00\04\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00") - (data (i32.const 216) "\e4\00\00\00\01\00\00\00\01\00\00\00\01\00\00\00") - (data (i32.const 232) "\f4\00\00\00\02\00\00\00\02\00\00\00\01\00\00\00\02\00\00\00") + (data (i32.const 4) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 36) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (data (i32.const 96) "\0c\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 124) "\0c\00\00\00~\00l\00i\00b\00/\00m\00a\00t\00h\00.\00t\00s\00") + (data (i32.const 152) "\a0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data (i32.const 168) "\b0\00\00\00\01\00\00\00\04\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00") + (data (i32.const 192) "\c8\00\00\00\02\00\00\00\08\00\00\00\00\00\00\00\02\00\00\00\01\00\00\00") + (data (i32.const 216) "\e0\00\00\00\04\00\00\00\10\00\00\00\00\00\00\00\03\00\00\00\02\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data (i32.const 256) "\08\01\00\00\04\00\00\00\10\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00\03\00\00\00\00\00\00\00\00\00\00\00") + (data (i32.const 296) "0\01\00\00\01\00\00\00\04\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00") + (data (i32.const 320) "H\01\00\00\02\00\00\00\08\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00") (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/math/murmurHash3 (; 2 ;) (type $II) (param $0 i64) (result i64) - (set_local $0 - (i64.xor - (get_local $0) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - ) - (set_local $0 - (i64.mul - (get_local $0) - (i64.const -49064778989728563) - ) - ) - (set_local $0 - (i64.xor - (get_local $0) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - ) - (set_local $0 - (i64.mul - (get_local $0) - (i64.const -4265267296055464877) - ) - ) - (set_local $0 - (i64.xor - (get_local $0) - (i64.shr_u - (get_local $0) - (i64.const 33) - ) - ) - ) + (func $~lib/internal/arraybuffer/computeSize (; 2 ;) (type $ii) (param $0 i32) (result i32) (return - (get_local $0) - ) - ) - (func $~lib/math/NativeMath.seedRandom (; 3 ;) (type $Iv) (param $0 i64) - (if - (i64.eqz - (get_local $0) - ) - (block - (call $abort - (i32.const 0) - (i32.const 4) - (i32.const 993) - (i32.const 4) + (i32.shl + (i32.const 1) + (i32.sub + (i32.const 32) + (i32.clz + (i32.sub + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.const 1) + ) + ) ) - (unreachable) - ) - ) - (set_global $~lib/math/random_seeded - (i32.const 1) - ) - (set_global $~lib/math/random_state0 - (call $~lib/math/murmurHash3 - (get_local $0) - ) - ) - (set_global $~lib/math/random_state1 - (call $~lib/math/murmurHash3 - (get_global $~lib/math/random_state0) ) ) ) - (func $~lib/allocator/arena/allocate_memory (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/allocate_memory (; 3 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -242,14 +191,490 @@ (i32.const 0) ) ) - (func $~lib/array/Array#get:length (; 5 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (if + (i32.eqz + (i32.le_u + (get_local $0) + (i32.const 1073741816) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 36) + (i32.const 22) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $1 + (call $~lib/allocator/arena/allocate_memory + (call $~lib/internal/arraybuffer/computeSize + (get_local $0) + ) + ) + ) + (i32.store + (get_local $1) + (get_local $0) + ) (return - (i32.load offset=8 + (get_local $1) + ) + ) + (func $~lib/array/Array#constructor (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (block + (nop) + (if + (i32.gt_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 23) + (i32.const 39) + ) + (unreachable) + ) + ) + (i32.store + (tee_local $0 + (if (result i32) + (get_local $0) + (get_local $0) + (tee_local $0 + (block (result i32) + (set_local $2 + (call $~lib/allocator/arena/allocate_memory + (i32.const 8) + ) + ) + (i32.store + (get_local $2) + (i32.const 0) + ) + (i32.store offset=4 + (get_local $2) + (i32.const 0) + ) + (get_local $2) + ) + ) + ) + ) + (call $~lib/internal/arraybuffer/allocUnsafe + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $1) + ) + ) + (get_local $0) + ) + (func $~lib/array/Array#constructor|trampoline (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (block $1of1 + (block $0of1 + (block $oob + (br_table $0of1 $1of1 $oob + (get_global $argumentCount) + ) + ) + (unreachable) + ) + (set_local $1 + (i32.const 0) + ) + ) + (call $~lib/array/Array#constructor + (get_local $0) + (get_local $1) + ) + ) + (func $~lib/array/Array#get:length (; 7 ;) (type $ii) (param $0 i32) (result i32) + (return + (i32.load offset=4 (get_local $0) ) ) ) - (func $~lib/memory/copy_memory (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $std/array/internalCapacity (; 8 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (set_local $1 + (i32.load + (get_local $0) + ) + ) + (return + (i32.shr_s + (i32.load + (get_local $1) + ) + (i32.const 2) + ) + ) + ) + (func $~lib/memory/set_memory (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i64) + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (set_local $3 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $3) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) + ) + (set_local $2 + (i32.and + (get_local $2) + (i32.const -4) + ) + ) + (set_local $4 + (i32.mul + (i32.div_u + (i32.const -1) + (i32.const 255) + ) + (get_local $1) + ) + ) + (i32.store + (get_local $0) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $4) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $4) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $4) + ) + (set_local $3 + (i32.add + (i32.const 24) + (i32.and + (get_local $0) + (i32.const 4) + ) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $3) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) + ) + (set_local $5 + (i64.or + (i64.extend_u/i32 + (get_local $4) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $4) + ) + (i64.const 32) + ) + ) + ) + (block $break|0 + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (block + (i64.store + (get_local $0) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $5) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + ) + (func $~lib/memory/copy_memory (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2052,7 +2477,7 @@ ) ) ) - (func $~lib/memory/move_memory (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/move_memory (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (if (i32.eq @@ -2375,672 +2800,298 @@ ) ) ) - (func $~lib/allocator/arena/free_memory (; 8 ;) (type $iv) (param $0 i32) - ) - (func $~lib/array/Array#__grow (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/internal/arraybuffer/reallocUnsafe (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - (local $4 i32) (set_local $2 (i32.load (get_local $0) ) ) - (set_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) (if - (i32.eqz - (i32.gt_s - (get_local $1) - (get_local $3) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 60) - (i32.const 16) - (i32.const 4) - ) - (unreachable) - ) - ) - (set_local $4 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $4) - (get_local $2) - (i32.mul - (get_local $3) - (i32.const 4) - ) - ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) - ) - ) - (i32.store - (get_local $0) - (get_local $4) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) - ) - (func $~lib/array/Array#push (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (set_local $2 - (i32.load offset=4 - (get_local $0) - ) - ) - (set_local $3 - (i32.load offset=8 - (get_local $0) - ) - ) - (if - (i32.eq - (get_local $3) + (i32.gt_s + (get_local $1) (get_local $2) ) - (call $~lib/array/Array#__grow - (get_local $0) - (if (result i32) - (get_local $2) - (i32.shl - (get_local $2) - (i32.const 1) - ) - (i32.const 1) - ) - ) - ) - (i32.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $3) - (i32.const 4) - ) - ) - (get_local $1) - ) - (i32.store offset=8 - (get_local $0) - (tee_local $3 - (i32.add - (get_local $3) - (i32.const 1) - ) - ) - ) - (return - (get_local $3) - ) - ) - (func $~lib/array/Array#__get (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - ) - ) - ) - (func $~lib/array/Array#pop (; 12 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - (set_local $1 - (i32.load offset=8 - (get_local $0) - ) - ) - (if - (i32.lt_s - (get_local $1) - (i32.const 1) - ) - (unreachable) - ) - (set_local $2 - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (tee_local $1 - (i32.sub - (get_local $1) - (i32.const 1) - ) - ) - (i32.const 4) - ) - ) - ) - ) - (i32.store offset=8 - (get_local $0) - (get_local $1) - ) - (return - (get_local $2) - ) - ) - (func $~lib/array/Array#unshift (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - (local $6 i32) - (set_local $2 - (i32.load - (get_local $0) - ) - ) - (set_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - (set_local $4 - (i32.load offset=8 - (get_local $0) - ) - ) - (if - (i32.eq - (i32.load offset=8 - (get_local $0) - ) - (get_local $3) - ) (block - (set_local $5 - (if (result i32) - (get_local $3) - (i32.shl - (get_local $3) - (i32.const 1) - ) - (i32.const 1) - ) - ) (if (i32.eqz - (i32.gt_s - (get_local $5) - (get_local $3) + (i32.le_s + (get_local $1) + (i32.const 1073741816) ) ) (block (call $abort (i32.const 0) - (i32.const 60) - (i32.const 204) - (i32.const 6) + (i32.const 36) + (i32.const 32) + (i32.const 4) ) (unreachable) ) ) - (set_local $6 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $5) - (i32.const 4) + (if + (i32.le_s + (get_local $1) + (i32.sub + (call $~lib/internal/arraybuffer/computeSize + (get_local $2) + ) + (i32.const 8) + ) + ) + (block + (i32.store + (get_local $0) + (get_local $1) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + ) + (block + (set_local $3 + (call $~lib/internal/arraybuffer/allocUnsafe + (get_local $1) + ) + ) + (call $~lib/memory/move_memory + (i32.add + (get_local $3) + (i32.const 8) + ) + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $3) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + (return + (get_local $3) ) ) ) - (if + ) + (if + (i32.lt_s + (get_local $1) (get_local $2) - (block - (call $~lib/memory/move_memory - (i32.add - (get_local $6) - (i32.const 4) - ) - (get_local $2) - (i32.mul - (get_local $3) - (i32.const 4) + ) + (block + (if + (i32.eqz + (i32.ge_s + (get_local $1) + (i32.const 0) ) ) - (call $~lib/allocator/arena/free_memory - (get_local $2) + (block + (call $abort + (i32.const 0) + (i32.const 36) + (i32.const 56) + (i32.const 4) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (get_local $1) + ) + ) + ) + ) + (return + (get_local $0) + ) + ) + (func $~lib/array/Array#push (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (set_local $2 + (i32.load offset=4 + (get_local $0) + ) + ) + (set_local $3 + (i32.load + (get_local $0) + ) + ) + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 2) + ) + ) + (set_local $5 + (i32.add + (get_local $2) + (i32.const 1) + ) + ) + (if + (i32.ge_u + (get_local $2) + (get_local $4) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $2) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 128) + (i32.const 42) + ) + (unreachable) + ) + ) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (get_local $5) + (i32.const 2) ) ) ) (i32.store (get_local $0) - (get_local $6) - ) - (i32.store offset=4 - (get_local $0) - (get_local $5) - ) - (set_local $2 - (get_local $6) - ) - ) - (call $~lib/memory/move_memory - (i32.add - (get_local $2) - (i32.const 4) - ) - (get_local $2) - (i32.mul (get_local $3) - (i32.const 4) ) ) ) - (i32.store - (get_local $2) - (get_local $1) - ) - (i32.store offset=8 + (i32.store offset=4 (get_local $0) - (tee_local $4 + (get_local $5) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.0 + (set_local $6 + (get_local $3) + ) + (set_local $7 + (get_local $2) + ) + (set_local $8 + (get_local $1) + ) + (i32.store offset=8 (i32.add - (get_local $4) - (i32.const 1) + (get_local $6) + (i32.shl + (get_local $7) + (i32.const 2) + ) ) + (get_local $8) ) ) (return - (get_local $4) + (get_local $5) ) ) - (func $~lib/memory/set_memory (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__get (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (local $3 i32) (local $4 i32) - (local $5 i64) - (if - (i32.eqz - (get_local $2) - ) - (return) - ) - (i32.store8 - (get_local $0) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 1) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 2) - ) - (return) - ) - (i32.store8 - (i32.add + (local $5 i32) + (set_local $2 + (i32.load (get_local $0) - (i32.const 1) ) - (get_local $1) - ) - (i32.store8 - (i32.add - (get_local $0) - (i32.const 2) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 2) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 3) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 6) - ) - (return) - ) - (i32.store8 - (i32.add - (get_local $0) - (i32.const 3) - ) - (get_local $1) - ) - (i32.store8 - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 4) - ) - (get_local $1) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 8) - ) - (return) ) (set_local $3 - (i32.and - (i32.sub - (i32.const 0) - (get_local $0) + (i32.shr_u + (i32.load + (get_local $2) ) - (i32.const 3) + (i32.const 2) ) ) - (set_local $0 - (i32.add - (get_local $0) - (get_local $3) - ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (get_local $3) - ) - ) - (set_local $2 - (i32.and - (get_local $2) - (i32.const -4) - ) - ) - (set_local $4 - (i32.mul - (i32.div_u - (i32.const -1) - (i32.const 255) - ) + (if + (i32.ge_u (get_local $1) + (get_local $3) ) - ) - (i32.store - (get_local $0) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 4) - ) - (get_local $4) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 8) - ) - (return) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 4) - ) - (get_local $4) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 8) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 12) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 8) - ) - (get_local $4) - ) - (if - (i32.le_u - (get_local $2) - (i32.const 24) - ) - (return) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 12) - ) - (get_local $4) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 16) - ) - (get_local $4) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 20) - ) - (get_local $4) - ) - (i32.store - (i32.add - (get_local $0) - (i32.const 24) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 28) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 24) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 20) - ) - (get_local $4) - ) - (i32.store - (i32.sub - (i32.add - (get_local $0) - (get_local $2) - ) - (i32.const 16) - ) - (get_local $4) - ) - (set_local $3 - (i32.add - (i32.const 24) - (i32.and - (get_local $0) + (block + (call $abort + (i32.const 0) (i32.const 4) + (i32.const 64) + (i32.const 37) ) + (unreachable) ) ) - (set_local $0 - (i32.add - (get_local $0) - (get_local $3) - ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (get_local $3) - ) - ) - (set_local $5 - (i64.or - (i64.extend_u/i32 - (get_local $4) + (return + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result i32) + (set_local $4 + (get_local $2) ) - (i64.shl - (i64.extend_u/i32 - (get_local $4) - ) - (i64.const 32) + (set_local $5 + (get_local $1) ) - ) - ) - (block $break|0 - (loop $continue|0 - (if - (i32.ge_u - (get_local $2) - (i32.const 32) - ) - (block - (block - (i64.store - (get_local $0) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl (get_local $5) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 8) - ) - (get_local $5) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 16) - ) - (get_local $5) - ) - (i64.store - (i32.add - (get_local $0) - (i32.const 24) - ) - (get_local $5) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 32) - ) - ) - (set_local $0 - (i32.add - (get_local $0) - (i32.const 32) - ) + (i32.const 2) ) ) - (br $continue|0) ) ) ) ) ) - (func $~lib/array/Array#shift (; 15 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#pop (; 15 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (set_local $1 - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) @@ -3049,67 +3100,294 @@ (get_local $1) (i32.const 1) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 139) + (i32.const 20) + ) + (unreachable) + ) ) + (set_local $4 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.1 (result i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (tee_local $1 + (i32.sub + (get_local $1) + (i32.const 1) + ) + ) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.1 + (i32.load offset=8 + (i32.add + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) + ) + ) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $1) + ) + (return + (get_local $4) + ) + ) + (func $~lib/array/Array#unshift (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) (set_local $2 (i32.load (get_local $0) ) ) (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) + (set_local $4 (i32.load offset=4 (get_local $0) ) ) - (set_local $4 - (i32.load - (get_local $2) + (set_local $5 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (if + (i32.ge_u + (get_local $4) + (get_local $3) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $4) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 188) + (i32.const 42) + ) + (unreachable) + ) + ) + (set_local $2 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $2) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) + (i32.store + (get_local $0) + (get_local $2) + ) ) ) (call $~lib/memory/move_memory - (get_local $2) (i32.add - (get_local $2) + (i32.add + (get_local $2) + (i32.const 8) + ) (i32.const 4) ) - (i32.mul + (i32.add + (get_local $2) + (i32.const 8) + ) + (i32.shl (i32.sub (get_local $3) (i32.const 1) ) - (i32.const 4) + (i32.const 2) ) ) - (call $~lib/memory/set_memory - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.1 + (set_local $6 (get_local $2) - (i32.mul - (i32.sub - (get_local $3) - (i32.const 1) + ) + (set_local $7 + (i32.const 0) + ) + (set_local $8 + (get_local $1) + ) + (i32.store offset=8 + (i32.add + (get_local $6) + (i32.shl + (get_local $7) + (i32.const 2) ) + ) + (get_local $8) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $5) + ) + (return + (get_local $5) + ) + ) + (func $~lib/array/Array#shift (; 17 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (set_local $1 + (i32.load offset=4 + (get_local $0) + ) + ) + (if + (i32.lt_s + (get_local $1) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) (i32.const 4) + (i32.const 159) + (i32.const 20) + ) + (unreachable) + ) + ) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $5 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.2 (result i32) + (set_local $3 + (get_local $2) + ) + (set_local $4 + (i32.const 0) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.2 + (i32.load offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $4) + (i32.const 2) + ) + ) + ) ) ) - (i32.const 0) - (i32.const 4) ) - (i32.store offset=8 - (get_local $0) + (set_local $6 (i32.sub (get_local $1) (i32.const 1) ) ) + (call $~lib/memory/move_memory + (i32.add + (get_local $2) + (i32.const 8) + ) + (i32.add + (i32.add + (get_local $2) + (i32.const 8) + ) + (i32.const 4) + ) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.2 + (set_local $4 + (get_local $2) + ) + (set_local $3 + (get_local $6) + ) + (set_local $7 + (i32.const 0) + ) + (i32.store offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $3) + (i32.const 2) + ) + ) + (get_local $7) + ) + ) + (i32.store offset=4 + (get_local $0) + (get_local $6) + ) (return - (get_local $4) + (get_local $5) ) ) - (func $~lib/array/Array#reverse (; 16 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#reverse (; 18 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) (set_local $1 (i32.load (get_local $0) @@ -3122,7 +3400,7 @@ ) (set_local $3 (i32.sub - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) (i32.const 1) @@ -3131,50 +3409,92 @@ ) (loop $continue|0 (if - (i32.lt_u + (i32.lt_s (get_local $2) (get_local $3) ) (block (block - (set_local $4 - (i32.load - (i32.add + (set_local $5 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.3 (result i32) + (set_local $4 (get_local $1) - (i32.mul - (get_local $2) - (i32.const 4) - ) ) - ) - ) - (i32.store - (i32.add - (get_local $1) - (i32.mul + (set_local $5 (get_local $2) - (i32.const 4) ) - ) - (i32.load - (i32.add - (get_local $1) - (i32.mul - (get_local $3) - (i32.const 4) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.3 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.3 + (set_local $4 (get_local $1) - (i32.mul - (get_local $3) - (i32.const 4) + ) + (set_local $6 + (get_local $2) + ) + (set_local $7 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.4 (result i32) + (set_local $8 + (get_local $1) + ) + (set_local $9 + (get_local $3) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.4 + (i32.load offset=8 + (i32.add + (get_local $8) + (i32.shl + (get_local $9) + (i32.const 2) + ) + ) + ) + ) ) ) - (get_local $4) + (i32.store offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $7) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.4 + (set_local $7 + (get_local $1) + ) + (set_local $6 + (get_local $3) + ) + (set_local $4 + (get_local $5) + ) + (i32.store offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $4) + ) ) ) (block @@ -3200,12 +3520,13 @@ (get_local $0) ) ) - (func $~lib/array/Array#indexOf (; 17 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#indexOf (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) (set_local $3 - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) @@ -3235,25 +3556,25 @@ (get_local $2) (i32.const 0) ) - (block - (set_local $2 - (i32.add - (get_local $3) - (get_local $2) + (set_local $2 + (select + (tee_local $4 + (i32.add + (get_local $3) + (get_local $2) + ) ) - ) - (if - (i32.lt_s - (get_local $2) + (tee_local $5 (i32.const 0) ) - (set_local $2 - (i32.const 0) + (i32.gt_s + (get_local $4) + (get_local $5) ) ) ) ) - (set_local $5 + (set_local $6 (i32.load (get_local $0) ) @@ -3269,12 +3590,22 @@ (block (if (i32.eq - (i32.load - (i32.add - (get_local $5) - (i32.mul - (get_local $2) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.5 (result i32) + (set_local $4 + (get_local $6) + ) + (set_local $5 + (get_local $2) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.5 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) @@ -3300,7 +3631,7 @@ (i32.const -1) ) ) - (func $~lib/array/Array#indexOf|trampoline (; 18 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#indexOf|trampoline (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -3323,11 +3654,13 @@ (get_local $2) ) ) - (func $~lib/array/Array#includes (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#includes (; 21 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) (set_local $3 - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) @@ -3357,24 +3690,29 @@ (get_local $2) (i32.const 0) ) - (block - (set_local $2 - (i32.add - (get_local $3) - (get_local $2) + (set_local $2 + (select + (tee_local $4 + (i32.add + (get_local $3) + (get_local $2) + ) ) - ) - (if - (i32.lt_s - (get_local $2) + (tee_local $5 (i32.const 0) ) - (set_local $2 - (i32.const 0) + (i32.gt_s + (get_local $4) + (get_local $5) ) ) ) ) + (set_local $6 + (i32.load + (get_local $0) + ) + ) (block $break|0 (loop $continue|0 (if @@ -3386,14 +3724,22 @@ (block (if (i32.eq - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $2) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.6 (result i32) + (set_local $4 + (get_local $6) + ) + (set_local $5 + (get_local $2) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.6 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) @@ -3419,7 +3765,7 @@ (i32.const 0) ) ) - (func $~lib/array/Array#includes|trampoline (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#includes|trampoline (; 22 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -3442,7 +3788,7 @@ (get_local $2) ) ) - (func $~lib/array/Array#splice (; 21 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#splice (; 23 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -3455,7 +3801,7 @@ (return) ) (set_local $3 - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) @@ -3464,37 +3810,30 @@ (get_local $1) (i32.const 0) ) - (block - (set_local $1 - (i32.add - (get_local $3) - (get_local $1) - ) - ) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (set_local $1 - (i32.const 0) - ) - (if - (i32.ge_s - (get_local $1) + (set_local $1 + (select + (tee_local $4 + (i32.add (get_local $3) + (get_local $1) ) - (return) + ) + (tee_local $5 + (i32.const 0) + ) + (i32.gt_s + (get_local $4) + (get_local $5) ) ) ) - (if - (i32.ge_s - (get_local $1) - (get_local $3) - ) - (return) + ) + (if + (i32.ge_s + (get_local $1) + (get_local $3) ) + (return) ) (set_local $2 (select @@ -3520,28 +3859,34 @@ ) (call $~lib/memory/move_memory (i32.add - (get_local $6) - (i32.mul + (i32.add + (get_local $6) + (i32.const 8) + ) + (i32.shl (get_local $1) - (i32.const 4) + (i32.const 2) ) ) (i32.add - (get_local $6) - (i32.mul + (i32.add + (get_local $6) + (i32.const 8) + ) + (i32.shl (i32.add (get_local $1) (get_local $2) ) - (i32.const 4) + (i32.const 2) ) ) - (i32.mul + (i32.shl (get_local $2) - (i32.const 4) + (i32.const 2) ) ) - (i32.store offset=8 + (i32.store offset=4 (get_local $0) (i32.sub (get_local $3) @@ -3549,98 +3894,139 @@ ) ) ) - (func $~lib/array/Array#__set (; 22 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 24 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) + (local $6 i32) + (local $7 i32) (set_local $3 - (i32.load offset=4 + (i32.load (get_local $0) ) ) + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 2) + ) + ) (if - (i32.ge_s + (i32.ge_u (get_local $1) + (get_local $4) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.5 + (set_local $5 (get_local $3) ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $5 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $5) - ) - ) + (set_local $6 + (get_local $1) ) - ) - (i32.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) - ) + (set_local $7 + (get_local $2) + ) + (i32.store offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $7) ) - (get_local $2) ) ) - (func $start~anonymous|0 (; 23 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|0 (; 25 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 0) ) ) - (func $~lib/array/Array#findIndex (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#findIndex (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) (set_local $2 - (i32.load offset=8 + (i32.load (get_local $0) ) ) - (set_local $3 - (i32.const 0) - ) (block $break|0 + (block + (set_local $3 + (i32.const 0) + ) + (set_local $4 + (i32.load offset=4 + (get_local $0) + ) + ) + ) (loop $continue|0 (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $3) - (get_local $2) + (get_local $4) ) ) (i32.lt_s (get_local $3) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3652,14 +4038,22 @@ (i32.const 3) ) (call_indirect (type $iiii) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $3) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.7 (result i32) + (set_local $5 + (get_local $2) + ) + (set_local $6 + (get_local $3) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.7 + (i32.load offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) ) ) ) @@ -3672,11 +4066,11 @@ (get_local $3) ) ) - (set_local $3 - (i32.add - (get_local $3) - (i32.const 1) - ) + ) + (set_local $3 + (i32.add + (get_local $3) + (i32.const 1) ) ) (br $continue|0) @@ -3688,19 +4082,19 @@ (i32.const -1) ) ) - (func $start~anonymous|1 (; 25 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|1 (; 27 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 1) ) ) - (func $start~anonymous|2 (; 26 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|2 (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 100) ) ) - (func $start~anonymous|3 (; 27 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|3 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3714,13 +4108,13 @@ ) ) ) - (func $start~anonymous|4 (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|4 (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.eq (get_local $0) (i32.const 100) ) ) - (func $start~anonymous|5 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|5 (; 31 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3733,42 +4127,51 @@ ) ) ) - (func $start~anonymous|6 (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|6 (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.ge_s (get_local $0) (i32.const 0) ) ) - (func $~lib/array/Array#every (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#every (; 33 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) (set_local $2 - (i32.load offset=8 + (i32.load (get_local $0) ) ) - (set_local $3 - (i32.const 0) - ) (block $break|0 + (block + (set_local $3 + (i32.const 0) + ) + (set_local $4 + (i32.load offset=4 + (get_local $0) + ) + ) + ) (loop $continue|0 (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $3) - (get_local $2) + (get_local $4) ) ) (i32.lt_s (get_local $3) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3781,14 +4184,22 @@ (i32.const 3) ) (call_indirect (type $iiii) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $3) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.8 (result i32) + (set_local $5 + (get_local $2) + ) + (set_local $6 + (get_local $3) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.8 + (i32.load offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) ) ) ) @@ -3802,11 +4213,11 @@ (i32.const 0) ) ) - (set_local $3 - (i32.add - (get_local $3) - (i32.const 1) - ) + ) + (set_local $3 + (i32.add + (get_local $3) + (i32.const 1) ) ) (br $continue|0) @@ -3818,13 +4229,13 @@ (i32.const 1) ) ) - (func $start~anonymous|7 (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|7 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.le_s (get_local $0) (i32.const 0) ) ) - (func $start~anonymous|8 (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|8 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3838,13 +4249,13 @@ ) ) ) - (func $start~anonymous|9 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|9 (; 36 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.lt_s (get_local $0) (i32.const 10) ) ) - (func $start~anonymous|10 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|10 (; 37 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3857,42 +4268,51 @@ ) ) ) - (func $start~anonymous|11 (; 36 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|11 (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.ge_s (get_local $0) (i32.const 3) ) ) - (func $~lib/array/Array#some (; 37 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#some (; 39 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) (set_local $2 - (i32.load offset=8 + (i32.load (get_local $0) ) ) - (set_local $3 - (i32.const 0) - ) (block $break|0 + (block + (set_local $3 + (i32.const 0) + ) + (set_local $4 + (i32.load offset=4 + (get_local $0) + ) + ) + ) (loop $continue|0 (if (i32.and (if (result i32) - (tee_local $4 + (tee_local $5 (i32.lt_s (get_local $3) - (get_local $2) + (get_local $4) ) ) (i32.lt_s (get_local $3) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $4) + (get_local $5) ) (i32.const 1) ) @@ -3904,14 +4324,22 @@ (i32.const 3) ) (call_indirect (type $iiii) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $3) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.9 (result i32) + (set_local $5 + (get_local $2) + ) + (set_local $6 + (get_local $3) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.9 + (i32.load offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) ) ) ) @@ -3924,11 +4352,11 @@ (i32.const 1) ) ) - (set_local $3 - (i32.add - (get_local $3) - (i32.const 1) - ) + ) + (set_local $3 + (i32.add + (get_local $3) + (i32.const 1) ) ) (br $continue|0) @@ -3940,13 +4368,13 @@ (i32.const 0) ) ) - (func $start~anonymous|12 (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|12 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.le_s (get_local $0) (i32.const -1) ) ) - (func $start~anonymous|13 (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|13 (; 41 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $2) @@ -3960,13 +4388,13 @@ ) ) ) - (func $start~anonymous|14 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|14 (; 42 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (i32.gt_s (get_local $0) (i32.const 10) ) ) - (func $start~anonymous|15 (; 41 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|15 (; 43 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $2) @@ -3979,46 +4407,55 @@ ) ) ) - (func $start~anonymous|16 (; 42 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|16 (; 44 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.add (get_local $0) (get_local $1) ) ) - (func $~lib/array/Array#reduce (; 43 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#reduce (; 45 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) (set_local $3 (get_local $2) ) (set_local $4 - (i32.load offset=8 + (i32.load (get_local $0) ) ) - (set_local $5 - (i32.const 0) - ) (block $break|0 + (block + (set_local $5 + (i32.const 0) + ) + (set_local $6 + (i32.load offset=4 + (get_local $0) + ) + ) + ) (loop $continue|0 (if (i32.and (if (result i32) - (tee_local $6 + (tee_local $7 (i32.lt_s (get_local $5) - (get_local $4) + (get_local $6) ) ) (i32.lt_s (get_local $5) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $6) + (get_local $7) ) (i32.const 1) ) @@ -4031,14 +4468,22 @@ ) (call_indirect (type $iiiii) (get_local $3) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $5) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.10 (result i32) + (set_local $7 + (get_local $4) + ) + (set_local $8 + (get_local $5) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.10 + (i32.load offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) ) ) ) @@ -4048,11 +4493,11 @@ ) ) ) - (set_local $5 - (i32.add - (get_local $5) - (i32.const 1) - ) + ) + (set_local $5 + (i32.add + (get_local $5) + (i32.const 1) ) ) (br $continue|0) @@ -4064,13 +4509,13 @@ (get_local $3) ) ) - (func $start~anonymous|17 (; 44 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|17 (; 46 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.add (get_local $0) (get_local $1) ) ) - (func $start~anonymous|18 (; 45 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|18 (; 47 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.and (if (result i32) (get_local $0) @@ -4083,40 +4528,49 @@ (i32.const 1) ) ) - (func $~lib/array/Array#reduce (; 46 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#reduce (; 48 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) + (local $7 i32) + (local $8 i32) (set_local $3 (get_local $2) ) (set_local $4 - (i32.load offset=8 + (i32.load (get_local $0) ) ) - (set_local $5 - (i32.const 0) - ) (block $break|0 + (block + (set_local $5 + (i32.const 0) + ) + (set_local $6 + (i32.load offset=4 + (get_local $0) + ) + ) + ) (loop $continue|0 (if (i32.and (if (result i32) - (tee_local $6 + (tee_local $7 (i32.lt_s (get_local $5) - (get_local $4) + (get_local $6) ) ) (i32.lt_s (get_local $5) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) - (get_local $6) + (get_local $7) ) (i32.const 1) ) @@ -4129,14 +4583,22 @@ ) (call_indirect (type $iiiii) (get_local $3) - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $5) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.11 (result i32) + (set_local $7 + (get_local $4) + ) + (set_local $8 + (get_local $5) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.11 + (i32.load offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) ) ) ) @@ -4146,11 +4608,11 @@ ) ) ) - (set_local $5 - (i32.add - (get_local $5) - (i32.const 1) - ) + ) + (set_local $5 + (i32.add + (get_local $5) + (i32.const 1) ) ) (br $continue|0) @@ -4162,7 +4624,7 @@ (get_local $3) ) ) - (func $start~anonymous|19 (; 47 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|19 (; 49 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.and (if (result i32) (get_local $0) @@ -4175,7 +4637,7 @@ (i32.const 1) ) ) - (func $start~anonymous|20 (; 48 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|20 (; 50 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (drop (call $~lib/array/Array#push (get_local $3) @@ -4189,13 +4651,13 @@ ) ) ) - (func $start~anonymous|21 (; 49 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|21 (; 51 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (i32.add (get_local $0) (get_local $1) ) ) - (func $start~anonymous|22 (; 50 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|22 (; 52 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (drop (call $~lib/array/Array#pop (get_local $3) @@ -4208,68 +4670,80 @@ ) ) ) - (func $~lib/array/Array#constructor (; 51 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (block - (if - (i32.lt_s - (get_local $1) + (func $~lib/math/murmurHash3 (; 53 ;) (type $II) (param $0 i64) (result i64) + (set_local $0 + (i64.xor + (get_local $0) + (i64.shr_u + (get_local $0) + (i64.const 33) + ) + ) + ) + (set_local $0 + (i64.mul + (get_local $0) + (i64.const -49064778989728563) + ) + ) + (set_local $0 + (i64.xor + (get_local $0) + (i64.shr_u + (get_local $0) + (i64.const 33) + ) + ) + ) + (set_local $0 + (i64.mul + (get_local $0) + (i64.const -4265267296055464877) + ) + ) + (set_local $0 + (i64.xor + (get_local $0) + (i64.shr_u + (get_local $0) + (i64.const 33) + ) + ) + ) + (return + (get_local $0) + ) + ) + (func $~lib/math/NativeMath.seedRandom (; 54 ;) (type $Iv) (param $0 i64) + (if + (i64.eqz + (get_local $0) + ) + (block + (call $abort (i32.const 0) + (i32.const 124) + (i32.const 993) + (i32.const 4) ) (unreachable) ) - (i32.store - (tee_local $0 - (if (result i32) - (get_local $0) - (get_local $0) - (tee_local $0 - (block (result i32) - (set_local $2 - (call $~lib/allocator/arena/allocate_memory - (i32.const 12) - ) - ) - (i32.store - (get_local $2) - (i32.const 0) - ) - (i32.store offset=4 - (get_local $2) - (i32.const 0) - ) - (i32.store offset=8 - (get_local $2) - (i32.const 0) - ) - (get_local $2) - ) - ) - ) - ) - (if (result i32) - (get_local $1) - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - (i32.const 0) - ) - ) - (i32.store offset=4 + ) + (set_global $~lib/math/random_seeded + (i32.const 1) + ) + (set_global $~lib/math/random_state0 + (call $~lib/math/murmurHash3 (get_local $0) - (get_local $1) - ) - (i32.store offset=8 - (get_local $0) - (get_local $1) ) ) - (get_local $0) + (set_global $~lib/math/random_state1 + (call $~lib/math/murmurHash3 + (get_global $~lib/math/random_state0) + ) + ) ) - (func $std/array/createReverseOrderedArray (; 52 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createReverseOrderedArray (; 55 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (set_local $1 @@ -4321,7 +4795,7 @@ (get_local $1) ) ) - (func $~lib/math/NativeMath.random (; 53 ;) (type $F) (result f64) + (func $~lib/math/NativeMath.random (; 56 ;) (type $F) (result f64) (local $0 i64) (local $1 i64) (local $2 i64) @@ -4329,7 +4803,15 @@ (i32.eqz (get_global $~lib/math/random_seeded) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 124) + (i32.const 1000) + (i32.const 24) + ) + (unreachable) + ) ) (set_local $0 (get_global $~lib/math/random_state0) @@ -4397,7 +4879,7 @@ ) ) ) - (func $std/array/createRandomOrderedArray (; 54 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createRandomOrderedArray (; 57 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (set_local $1 @@ -4450,7 +4932,7 @@ (get_local $1) ) ) - (func $std/array/createDefaultComparator~anonymous|23 (; 55 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/array/defaultComparator~anonymous|23 (; 58 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (i32.gt_s (get_local $0) @@ -4462,12 +4944,12 @@ ) ) ) - (func $std/array/createDefaultComparator (; 56 ;) (type $i) (result i32) + (func $~lib/internal/array/defaultComparator (; 59 ;) (type $i) (result i32) (return (i32.const 23) ) ) - (func $~lib/internal/array/insertionSort (; 57 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/array/insertionSort (; 60 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4475,7 +4957,8 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (nop) + (local $9 i32) + (local $10 i32) (set_local $2 (i32.load (get_local $0) @@ -4500,18 +4983,28 @@ ) (block (block - (set_local $5 - (i32.load - (i32.add + (set_local $6 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.14 (result i32) + (set_local $5 (get_local $2) - (i32.shl - (get_local $3) - (i32.const 2) + ) + (set_local $6 + (get_local $3) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.14 + (i32.load offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) ) ) ) ) - (set_local $6 + (set_local $5 (i32.sub (get_local $3) (i32.const 1) @@ -4521,18 +5014,28 @@ (loop $continue|1 (if (i32.ge_s - (get_local $6) + (get_local $5) (i32.const 0) ) (block (block - (set_local $7 - (i32.load - (i32.add + (set_local $8 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.15 (result i32) + (set_local $7 (get_local $2) - (i32.shl - (get_local $6) - (i32.const 2) + ) + (set_local $8 + (get_local $5) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.15 + (i32.load offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) ) ) ) @@ -4544,36 +5047,47 @@ (i32.const 2) ) (call_indirect (type $iii) - (get_local $5) - (get_local $7) + (get_local $6) + (get_local $8) (get_local $1) ) ) (i32.const 0) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.8 + (set_local $7 (get_local $2) - (i32.shl - (i32.add - (block (result i32) - (set_local $8 - (get_local $6) - ) - (set_local $6 - (i32.sub - (get_local $8) - (i32.const 1) - ) - ) - (get_local $8) + ) + (set_local $9 + (i32.add + (block (result i32) + (set_local $10 + (get_local $5) ) - (i32.const 1) + (set_local $5 + (i32.sub + (get_local $10) + (i32.const 1) + ) + ) + (get_local $10) ) - (i32.const 2) + (i32.const 1) ) ) - (get_local $7) + (set_local $10 + (get_local $8) + ) + (i32.store offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $9) + (i32.const 2) + ) + ) + (get_local $10) + ) ) (br $break|1) ) @@ -4583,18 +5097,29 @@ ) ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.9 + (set_local $8 (get_local $2) - (i32.shl - (i32.add - (get_local $6) - (i32.const 1) - ) - (i32.const 2) + ) + (set_local $10 + (i32.add + (get_local $5) + (i32.const 1) ) ) - (get_local $5) + (set_local $9 + (get_local $6) + ) + (i32.store offset=8 + (i32.add + (get_local $8) + (i32.shl + (get_local $10) + (i32.const 2) + ) + ) + (get_local $9) + ) ) ) (set_local $3 @@ -4612,7 +5137,9 @@ (get_local $0) ) ) - (func $~lib/internal/array/weakHeapSort (; 58 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/allocator/arena/free_memory (; 61 ;) (type $iv) (param $0 i32) + ) + (func $~lib/internal/array/weakHeapSort (; 62 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4623,7 +5150,9 @@ (local $9 i32) (local $10 i32) (local $11 i32) - (nop) + (local $12 i32) + (local $13 i32) + (local $14 i32) (nop) (set_local $2 (call $~lib/array/Array#get:length @@ -4726,24 +5255,44 @@ (i32.const 1) ) ) - (set_local $9 - (i32.load - (i32.add + (set_local $10 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.16 (result i32) + (set_local $9 (get_local $5) - (i32.shl - (get_local $8) - (i32.const 2) + ) + (set_local $10 + (get_local $8) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.16 + (i32.load offset=8 + (i32.add + (get_local $9) + (i32.shl + (get_local $10) + (i32.const 2) + ) + ) ) ) ) ) - (set_local $10 - (i32.load - (i32.add + (set_local $11 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.17 (result i32) + (set_local $9 (get_local $5) - (i32.shl - (get_local $6) - (i32.const 2) + ) + (set_local $11 + (get_local $6) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.17 + (i32.load offset=8 + (i32.add + (get_local $9) + (i32.shl + (get_local $11) + (i32.const 2) + ) + ) ) ) ) @@ -4755,8 +5304,8 @@ (i32.const 2) ) (call_indirect (type $iii) - (get_local $9) (get_local $10) + (get_local $11) (get_local $1) ) ) @@ -4796,25 +5345,47 @@ ) ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.10 + (set_local $9 (get_local $5) - (i32.shl - (get_local $6) - (i32.const 2) - ) ) - (get_local $9) + (set_local $12 + (get_local $6) + ) + (set_local $13 + (get_local $10) + ) + (i32.store offset=8 + (i32.add + (get_local $9) + (i32.shl + (get_local $12) + (i32.const 2) + ) + ) + (get_local $13) + ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.11 + (set_local $13 (get_local $5) - (i32.shl - (get_local $8) - (i32.const 2) - ) ) - (get_local $10) + (set_local $12 + (get_local $8) + ) + (set_local $9 + (get_local $11) + ) + (i32.store offset=8 + (i32.add + (get_local $13) + (i32.shl + (get_local $12) + (i32.const 2) + ) + ) + (get_local $9) + ) ) ) ) @@ -4846,33 +5417,87 @@ (block (block (set_local $10 - (i32.load - (get_local $5) - ) - ) - (i32.store - (get_local $5) - (i32.load - (i32.add + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.18 (result i32) + (set_local $11 (get_local $5) - (i32.shl - (get_local $6) - (i32.const 2) + ) + (set_local $10 + (i32.const 0) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.18 + (i32.load offset=8 + (i32.add + (get_local $11) + (i32.shl + (get_local $10) + (i32.const 2) + ) + ) ) ) ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.12 + (set_local $11 (get_local $5) - (i32.shl - (get_local $6) - (i32.const 2) + ) + (set_local $8 + (i32.const 0) + ) + (set_local $7 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.19 (result i32) + (set_local $9 + (get_local $5) + ) + (set_local $12 + (get_local $6) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.19 + (i32.load offset=8 + (i32.add + (get_local $9) + (i32.shl + (get_local $12) + (i32.const 2) + ) + ) + ) + ) ) ) - (get_local $10) + (i32.store offset=8 + (i32.add + (get_local $11) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) + (get_local $7) + ) ) - (set_local $9 + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.13 + (set_local $7 + (get_local $5) + ) + (set_local $8 + (get_local $6) + ) + (set_local $11 + (get_local $10) + ) + (i32.store offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) + (get_local $11) + ) + ) + (set_local $11 (i32.const 1) ) (block $break|3 @@ -4882,7 +5507,7 @@ (tee_local $8 (i32.add (i32.shl - (get_local $9) + (get_local $11) (i32.const 1) ) (i32.and @@ -4892,7 +5517,7 @@ (get_local $4) (i32.shl (i32.shr_s - (get_local $9) + (get_local $11) (i32.const 5) ) (i32.const 2) @@ -4900,7 +5525,7 @@ ) ) (i32.and - (get_local $9) + (get_local $11) (i32.const 31) ) ) @@ -4911,7 +5536,7 @@ (get_local $6) ) (block - (set_local $9 + (set_local $11 (get_local $8) ) (br $continue|3) @@ -4923,23 +5548,49 @@ (loop $continue|4 (if (i32.gt_s - (get_local $9) + (get_local $11) (i32.const 0) ) (block (block (set_local $10 - (i32.load - (get_local $5) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.20 (result i32) + (set_local $7 + (get_local $5) + ) + (set_local $12 + (i32.const 0) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.20 + (i32.load offset=8 + (i32.add + (get_local $7) + (i32.shl + (get_local $12) + (i32.const 2) + ) + ) + ) + ) ) ) (set_local $7 - (i32.load - (i32.add + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.21 (result i32) + (set_local $12 (get_local $5) - (i32.shl - (get_local $9) - (i32.const 2) + ) + (set_local $7 + (get_local $11) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.21 + (i32.load offset=8 + (i32.add + (get_local $12) + (i32.shl + (get_local $7) + (i32.const 2) + ) + ) ) ) ) @@ -4964,7 +5615,7 @@ (get_local $4) (i32.shl (i32.shr_s - (get_local $9) + (get_local $11) (i32.const 5) ) (i32.const 2) @@ -4976,7 +5627,7 @@ (get_local $4) (i32.shl (i32.shr_s - (get_local $9) + (get_local $11) (i32.const 5) ) (i32.const 2) @@ -4986,31 +5637,59 @@ (i32.shl (i32.const 1) (i32.and - (get_local $9) + (get_local $11) (i32.const 31) ) ) ) ) - (i32.store - (i32.add + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.14 + (set_local $12 (get_local $5) - (i32.shl - (get_local $9) - (i32.const 2) - ) ) - (get_local $10) + (set_local $9 + (get_local $11) + ) + (set_local $13 + (get_local $10) + ) + (i32.store offset=8 + (i32.add + (get_local $12) + (i32.shl + (get_local $9) + (i32.const 2) + ) + ) + (get_local $13) + ) ) - (i32.store - (get_local $5) - (get_local $7) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.15 + (set_local $13 + (get_local $5) + ) + (set_local $9 + (i32.const 0) + ) + (set_local $12 + (get_local $7) + ) + (i32.store offset=8 + (i32.add + (get_local $13) + (i32.shl + (get_local $9) + (i32.const 2) + ) + ) + (get_local $12) + ) ) ) ) - (set_local $9 + (set_local $11 (i32.shr_s - (get_local $9) + (get_local $11) (i32.const 1) ) ) @@ -5035,32 +5714,101 @@ (call $~lib/allocator/arena/free_memory (get_local $4) ) - (set_local $11 - (i32.load offset=4 - (get_local $5) + (set_local $14 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.22 (result i32) + (set_local $6 + (get_local $5) + ) + (set_local $8 + (i32.const 1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.22 + (i32.load offset=8 + (i32.add + (get_local $6) + (i32.shl + (get_local $8) + (i32.const 2) + ) + ) + ) + ) ) ) - (i32.store offset=4 - (get_local $5) - (i32.load + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.16 + (set_local $8 (get_local $5) ) + (set_local $6 + (i32.const 1) + ) + (set_local $11 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.23 (result i32) + (set_local $10 + (get_local $5) + ) + (set_local $7 + (i32.const 0) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.23 + (i32.load offset=8 + (i32.add + (get_local $10) + (i32.shl + (get_local $7) + (i32.const 2) + ) + ) + ) + ) + ) + ) + (i32.store offset=8 + (i32.add + (get_local $8) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $11) + ) ) - (i32.store - (get_local $5) - (get_local $11) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.17 + (set_local $11 + (get_local $5) + ) + (set_local $6 + (i32.const 0) + ) + (set_local $8 + (get_local $14) + ) + (i32.store offset=8 + (i32.add + (get_local $11) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $8) + ) ) (return (get_local $0) ) ) - (func $~lib/array/Array#sort (; 59 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort (; 63 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) (set_local $2 - (call $~lib/array/Array#get:length + (i32.load offset=4 (get_local $0) ) ) @@ -5073,25 +5821,57 @@ (get_local $0) ) ) + (set_local $3 + (i32.load + (get_local $0) + ) + ) (if (i32.eq (get_local $2) (i32.const 2) ) (block - (set_local $3 - (i32.load - (get_local $0) - ) - ) - (set_local $4 - (i32.load offset=4 - (get_local $3) - ) - ) (set_local $5 - (i32.load - (get_local $3) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.12 (result i32) + (set_local $4 + (get_local $3) + ) + (set_local $5 + (i32.const 1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.12 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) + ) + ) + ) + ) + (set_local $6 + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.13 (result i32) + (set_local $4 + (get_local $3) + ) + (set_local $6 + (i32.const 0) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.13 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + ) + ) ) ) (if @@ -5101,21 +5881,55 @@ (i32.const 2) ) (call_indirect (type $iii) - (get_local $4) (get_local $5) + (get_local $6) (get_local $1) ) ) (i32.const 0) ) (block - (i32.store offset=4 - (get_local $3) - (get_local $5) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.6 + (set_local $4 + (get_local $3) + ) + (set_local $7 + (i32.const 1) + ) + (set_local $8 + (get_local $6) + ) + (i32.store offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $7) + (i32.const 2) + ) + ) + (get_local $8) + ) ) - (i32.store - (get_local $3) - (get_local $4) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.7 + (set_local $8 + (get_local $3) + ) + (set_local $7 + (i32.const 0) + ) + (set_local $4 + (get_local $5) + ) + (i32.store offset=8 + (i32.add + (get_local $8) + (i32.shl + (get_local $7) + (i32.const 2) + ) + ) + (get_local $4) + ) ) ) ) @@ -5126,7 +5940,7 @@ ) (return (if (result i32) - (i32.le_s + (i32.lt_s (get_local $2) (i32.const 256) ) @@ -5141,7 +5955,7 @@ ) ) ) - (func $std/array/isSorted (; 60 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isSorted (; 64 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (block $break|0 @@ -5206,7 +6020,7 @@ (i32.const 1) ) ) - (func $std/array/assertSorted (; 61 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std/array/assertSorted (; 65 ;) (type $iiv) (param $0 i32) (param $1 i32) (if (i32.eqz (call $std/array/isSorted @@ -5220,26 +6034,22 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 77) + (i32.const 96) + (i32.const 419) (i32.const 2) ) (unreachable) ) ) ) - (func $std/array/assertSortedDefault (; 62 ;) (type $iv) (param $0 i32) + (func $std/array/assertSortedDefault (; 66 ;) (type $iv) (param $0 i32) (call $std/array/assertSorted (get_local $0) - (call $std/array/createDefaultComparator) + (call $~lib/internal/array/defaultComparator) ) ) - (func $std/array/isArraysEqual (; 63 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std/array/isArraysEqual (; 67 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) - (local $4 i32) - (set_local $3 - (get_local $2) - ) (if (i32.eqz (get_local $2) @@ -5258,7 +6068,7 @@ (i32.const 0) ) ) - (set_local $3 + (set_local $2 (call $~lib/array/Array#get:length (get_local $0) ) @@ -5266,14 +6076,14 @@ ) ) (block $break|0 - (set_local $4 + (set_local $3 (i32.const 0) ) (loop $continue|0 (if (i32.lt_s - (get_local $4) (get_local $3) + (get_local $2) ) (block (block @@ -5281,11 +6091,11 @@ (i32.ne (call $~lib/array/Array#__get (get_local $0) - (get_local $4) + (get_local $3) ) (call $~lib/array/Array#__get (get_local $1) - (get_local $4) + (get_local $3) ) ) (return @@ -5293,9 +6103,9 @@ ) ) ) - (set_local $4 + (set_local $3 (i32.add - (get_local $4) + (get_local $3) (i32.const 1) ) ) @@ -5308,7 +6118,7 @@ (i32.const 1) ) ) - (func $std/array/isArraysEqual|trampoline (; 64 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std/array/isArraysEqual|trampoline (; 68 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (block $1of1 (block $0of1 (block $oob @@ -5331,31 +6141,31 @@ (get_local $2) ) ) - (func $start~anonymous|24 (; 65 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|24 (; 69 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $0) (get_local $1) ) ) - (func $start~anonymous|25 (; 66 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|25 (; 70 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $1) (get_local $0) ) ) - (func $start~anonymous|26 (; 67 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|26 (; 71 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $0) (get_local $1) ) ) - (func $start~anonymous|27 (; 68 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|27 (; 72 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (i32.sub (get_local $1) (get_local $0) ) ) - (func $start (; 69 ;) (type $v) + (func $start (; 73 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -5371,19 +6181,14 @@ (set_global $~lib/allocator/arena/offset (get_global $~lib/allocator/arena/startOffset) ) - (call $~lib/math/NativeMath.seedRandom - (i64.reinterpret/f64 - (call $~lib/math/JSMath.random) - ) - ) (set_global $std/array/arr - (call $~lib/allocator/arena/allocate_memory - (i32.add - (i32.const 4) - (i32.mul - (i32.const 2) - (i32.const 4) - ) + (block (result i32) + (set_global $argumentCount + (i32.const 0) + ) + (call $~lib/array/Array#constructor|trampoline + (i32.const 0) + (i32.const 0) ) ) ) @@ -5399,8 +6204,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 86) + (i32.const 96) + (i32.const 17) (i32.const 0) ) (unreachable) @@ -5409,7 +6214,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 0) @@ -5418,8 +6223,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 87) + (i32.const 96) + (i32.const 18) (i32.const 0) ) (unreachable) @@ -5444,8 +6249,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 91) + (i32.const 96) + (i32.const 22) (i32.const 0) ) (unreachable) @@ -5463,8 +6268,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 92) + (i32.const 96) + (i32.const 23) (i32.const 0) ) (unreachable) @@ -5473,7 +6278,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -5482,8 +6287,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 93) + (i32.const 96) + (i32.const 24) (i32.const 0) ) (unreachable) @@ -5504,8 +6309,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 97) + (i32.const 96) + (i32.const 28) (i32.const 0) ) (unreachable) @@ -5523,8 +6328,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 98) + (i32.const 96) + (i32.const 29) (i32.const 0) ) (unreachable) @@ -5533,7 +6338,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -5542,8 +6347,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 99) + (i32.const 96) + (i32.const 30) (i32.const 0) ) (unreachable) @@ -5567,8 +6372,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 103) + (i32.const 96) + (i32.const 34) (i32.const 0) ) (unreachable) @@ -5577,7 +6382,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 1) @@ -5586,8 +6391,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 104) + (i32.const 96) + (i32.const 35) (i32.const 0) ) (unreachable) @@ -5606,8 +6411,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 105) + (i32.const 96) + (i32.const 36) (i32.const 0) ) (unreachable) @@ -5631,8 +6436,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 109) + (i32.const 96) + (i32.const 40) (i32.const 0) ) (unreachable) @@ -5641,7 +6446,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 2) @@ -5650,8 +6455,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 110) + (i32.const 96) + (i32.const 41) (i32.const 0) ) (unreachable) @@ -5670,8 +6475,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 111) + (i32.const 96) + (i32.const 42) (i32.const 0) ) (unreachable) @@ -5690,8 +6495,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 112) + (i32.const 96) + (i32.const 43) (i32.const 0) ) (unreachable) @@ -5715,8 +6520,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 116) + (i32.const 96) + (i32.const 47) (i32.const 0) ) (unreachable) @@ -5725,17 +6530,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 4) + (i32.const 3) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 117) + (i32.const 96) + (i32.const 48) (i32.const 0) ) (unreachable) @@ -5754,8 +6559,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 118) + (i32.const 96) + (i32.const 49) (i32.const 0) ) (unreachable) @@ -5774,8 +6579,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 119) + (i32.const 96) + (i32.const 50) (i32.const 0) ) (unreachable) @@ -5794,8 +6599,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 120) + (i32.const 96) + (i32.const 51) (i32.const 0) ) (unreachable) @@ -5819,8 +6624,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 124) + (i32.const 96) + (i32.const 57) (i32.const 0) ) (unreachable) @@ -5829,7 +6634,7 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) (i32.const 4) @@ -5838,8 +6643,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 125) + (i32.const 96) + (i32.const 58) (i32.const 0) ) (unreachable) @@ -5858,8 +6663,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 126) + (i32.const 96) + (i32.const 59) (i32.const 0) ) (unreachable) @@ -5878,8 +6683,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 127) + (i32.const 96) + (i32.const 60) (i32.const 0) ) (unreachable) @@ -5898,8 +6703,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 128) + (i32.const 96) + (i32.const 61) (i32.const 0) ) (unreachable) @@ -5918,8 +6723,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 129) + (i32.const 96) + (i32.const 62) (i32.const 0) ) (unreachable) @@ -5943,8 +6748,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 133) + (i32.const 96) + (i32.const 66) (i32.const 0) ) (unreachable) @@ -5953,17 +6758,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 134) + (i32.const 96) + (i32.const 67) (i32.const 0) ) (unreachable) @@ -5982,8 +6787,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 135) + (i32.const 96) + (i32.const 68) (i32.const 0) ) (unreachable) @@ -6002,8 +6807,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 136) + (i32.const 96) + (i32.const 69) (i32.const 0) ) (unreachable) @@ -6022,8 +6827,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 137) + (i32.const 96) + (i32.const 70) (i32.const 0) ) (unreachable) @@ -6042,8 +6847,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 138) + (i32.const 96) + (i32.const 71) (i32.const 0) ) (unreachable) @@ -6062,8 +6867,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 139) + (i32.const 96) + (i32.const 72) (i32.const 0) ) (unreachable) @@ -6084,8 +6889,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 143) + (i32.const 96) + (i32.const 78) (i32.const 0) ) (unreachable) @@ -6103,8 +6908,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 144) + (i32.const 96) + (i32.const 79) (i32.const 0) ) (unreachable) @@ -6113,17 +6918,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 145) + (i32.const 96) + (i32.const 80) (i32.const 0) ) (unreachable) @@ -6142,8 +6947,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 146) + (i32.const 96) + (i32.const 81) (i32.const 0) ) (unreachable) @@ -6162,8 +6967,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 147) + (i32.const 96) + (i32.const 82) (i32.const 0) ) (unreachable) @@ -6182,8 +6987,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 148) + (i32.const 96) + (i32.const 83) (i32.const 0) ) (unreachable) @@ -6202,8 +7007,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 149) + (i32.const 96) + (i32.const 84) (i32.const 0) ) (unreachable) @@ -6224,8 +7029,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 153) + (i32.const 96) + (i32.const 88) (i32.const 0) ) (unreachable) @@ -6243,8 +7048,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 154) + (i32.const 96) + (i32.const 89) (i32.const 0) ) (unreachable) @@ -6253,17 +7058,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 155) + (i32.const 96) + (i32.const 90) (i32.const 0) ) (unreachable) @@ -6282,8 +7087,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 156) + (i32.const 96) + (i32.const 91) (i32.const 0) ) (unreachable) @@ -6302,8 +7107,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 157) + (i32.const 96) + (i32.const 92) (i32.const 0) ) (unreachable) @@ -6322,8 +7127,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 158) + (i32.const 96) + (i32.const 93) (i32.const 0) ) (unreachable) @@ -6346,8 +7151,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 162) + (i32.const 96) + (i32.const 99) (i32.const 0) ) (unreachable) @@ -6356,17 +7161,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 163) + (i32.const 96) + (i32.const 100) (i32.const 0) ) (unreachable) @@ -6385,8 +7190,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 164) + (i32.const 96) + (i32.const 101) (i32.const 0) ) (unreachable) @@ -6405,8 +7210,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 165) + (i32.const 96) + (i32.const 102) (i32.const 0) ) (unreachable) @@ -6425,8 +7230,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 166) + (i32.const 96) + (i32.const 103) (i32.const 0) ) (unreachable) @@ -6466,8 +7271,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 173) + (i32.const 96) + (i32.const 112) (i32.const 0) ) (unreachable) @@ -6495,8 +7300,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 177) + (i32.const 96) + (i32.const 116) (i32.const 0) ) (unreachable) @@ -6524,8 +7329,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 181) + (i32.const 96) + (i32.const 120) (i32.const 0) ) (unreachable) @@ -6548,8 +7353,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 185) + (i32.const 96) + (i32.const 124) (i32.const 0) ) (unreachable) @@ -6572,8 +7377,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 189) + (i32.const 96) + (i32.const 128) (i32.const 0) ) (unreachable) @@ -6596,8 +7401,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 193) + (i32.const 96) + (i32.const 132) (i32.const 0) ) (unreachable) @@ -6620,8 +7425,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 197) + (i32.const 96) + (i32.const 136) (i32.const 0) ) (unreachable) @@ -6644,8 +7449,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 201) + (i32.const 96) + (i32.const 140) (i32.const 0) ) (unreachable) @@ -6668,8 +7473,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 205) + (i32.const 96) + (i32.const 144) (i32.const 0) ) (unreachable) @@ -6692,8 +7497,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 209) + (i32.const 96) + (i32.const 148) (i32.const 0) ) (unreachable) @@ -6721,8 +7526,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 213) + (i32.const 96) + (i32.const 154) (i32.const 0) ) (unreachable) @@ -6750,8 +7555,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 217) + (i32.const 96) + (i32.const 158) (i32.const 0) ) (unreachable) @@ -6779,8 +7584,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 221) + (i32.const 96) + (i32.const 162) (i32.const 0) ) (unreachable) @@ -6803,8 +7608,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 225) + (i32.const 96) + (i32.const 166) (i32.const 0) ) (unreachable) @@ -6827,8 +7632,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 229) + (i32.const 96) + (i32.const 170) (i32.const 0) ) (unreachable) @@ -6851,8 +7656,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 233) + (i32.const 96) + (i32.const 174) (i32.const 0) ) (unreachable) @@ -6875,8 +7680,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 237) + (i32.const 96) + (i32.const 178) (i32.const 0) ) (unreachable) @@ -6899,8 +7704,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 241) + (i32.const 96) + (i32.const 182) (i32.const 0) ) (unreachable) @@ -6923,8 +7728,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 245) + (i32.const 96) + (i32.const 186) (i32.const 0) ) (unreachable) @@ -6947,8 +7752,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 249) + (i32.const 96) + (i32.const 190) (i32.const 0) ) (unreachable) @@ -6971,8 +7776,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 253) + (i32.const 96) + (i32.const 194) (i32.const 0) ) (unreachable) @@ -6981,17 +7786,17 @@ (if (i32.eqz (i32.eq - (i32.load offset=4 + (call $std/array/internalCapacity (get_global $std/array/arr) ) - (i32.const 8) + (i32.const 5) ) ) (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 254) + (i32.const 96) + (i32.const 195) (i32.const 0) ) (unreachable) @@ -7010,8 +7815,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 255) + (i32.const 96) + (i32.const 196) (i32.const 0) ) (unreachable) @@ -7030,8 +7835,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 256) + (i32.const 96) + (i32.const 197) (i32.const 0) ) (unreachable) @@ -7073,8 +7878,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 265) + (i32.const 96) + (i32.const 207) (i32.const 0) ) (unreachable) @@ -7096,8 +7901,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 268) + (i32.const 96) + (i32.const 210) (i32.const 0) ) (unreachable) @@ -7119,8 +7924,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 271) + (i32.const 96) + (i32.const 213) (i32.const 0) ) (unreachable) @@ -7142,8 +7947,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 279) + (i32.const 96) + (i32.const 221) (i32.const 0) ) (unreachable) @@ -7161,8 +7966,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 280) + (i32.const 96) + (i32.const 222) (i32.const 0) ) (unreachable) @@ -7184,8 +7989,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 282) + (i32.const 96) + (i32.const 224) (i32.const 0) ) (unreachable) @@ -7227,8 +8032,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 295) + (i32.const 96) + (i32.const 237) (i32.const 0) ) (unreachable) @@ -7246,8 +8051,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 296) + (i32.const 96) + (i32.const 238) (i32.const 0) ) (unreachable) @@ -7281,8 +8086,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 302) + (i32.const 96) + (i32.const 246) (i32.const 0) ) (unreachable) @@ -7304,8 +8109,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 305) + (i32.const 96) + (i32.const 249) (i32.const 0) ) (unreachable) @@ -7327,8 +8132,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 313) + (i32.const 96) + (i32.const 257) (i32.const 0) ) (unreachable) @@ -7346,8 +8151,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 314) + (i32.const 96) + (i32.const 258) (i32.const 0) ) (unreachable) @@ -7369,8 +8174,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 316) + (i32.const 96) + (i32.const 260) (i32.const 0) ) (unreachable) @@ -7412,8 +8217,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 329) + (i32.const 96) + (i32.const 273) (i32.const 0) ) (unreachable) @@ -7431,8 +8236,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 330) + (i32.const 96) + (i32.const 274) (i32.const 0) ) (unreachable) @@ -7466,8 +8271,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 336) + (i32.const 96) + (i32.const 282) (i32.const 0) ) (unreachable) @@ -7489,8 +8294,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 339) + (i32.const 96) + (i32.const 285) (i32.const 0) ) (unreachable) @@ -7512,8 +8317,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 347) + (i32.const 96) + (i32.const 293) (i32.const 0) ) (unreachable) @@ -7531,8 +8336,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 348) + (i32.const 96) + (i32.const 294) (i32.const 0) ) (unreachable) @@ -7554,8 +8359,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 350) + (i32.const 96) + (i32.const 296) (i32.const 0) ) (unreachable) @@ -7597,8 +8402,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 363) + (i32.const 96) + (i32.const 309) (i32.const 0) ) (unreachable) @@ -7616,8 +8421,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 364) + (i32.const 96) + (i32.const 310) (i32.const 0) ) (unreachable) @@ -7652,8 +8457,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 371) + (i32.const 96) + (i32.const 318) (i32.const 0) ) (unreachable) @@ -7676,8 +8481,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 375) + (i32.const 96) + (i32.const 322) (i32.const 0) ) (unreachable) @@ -7700,8 +8505,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 378) + (i32.const 96) + (i32.const 325) (i32.const 0) ) (unreachable) @@ -7724,8 +8529,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 381) + (i32.const 96) + (i32.const 328) (i32.const 0) ) (unreachable) @@ -7748,8 +8553,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 389) + (i32.const 96) + (i32.const 336) (i32.const 0) ) (unreachable) @@ -7767,8 +8572,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 390) + (i32.const 96) + (i32.const 337) (i32.const 0) ) (unreachable) @@ -7791,8 +8596,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 392) + (i32.const 96) + (i32.const 339) (i32.const 0) ) (unreachable) @@ -7835,8 +8640,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 405) + (i32.const 96) + (i32.const 352) (i32.const 0) ) (unreachable) @@ -7854,29 +8659,34 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 406) + (i32.const 96) + (i32.const 353) (i32.const 0) ) (unreachable) ) ) - (set_global $std/array/revesed64 + (call $~lib/math/NativeMath.seedRandom + (i64.reinterpret/f64 + (call $~lib/math/JSMath.random) + ) + ) + (set_global $std/array/reversed64 (call $std/array/createReverseOrderedArray (i32.const 64) ) ) - (set_global $std/array/revesed128 + (set_global $std/array/reversed128 (call $std/array/createReverseOrderedArray (i32.const 128) ) ) - (set_global $std/array/revesed1024 + (set_global $std/array/reversed1024 (call $std/array/createReverseOrderedArray (i32.const 1024) ) ) - (set_global $std/array/revesed10000 + (set_global $std/array/reversed10000 (call $std/array/createReverseOrderedArray (i32.const 10000) ) @@ -7887,10 +8697,10 @@ ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed0) + (get_global $std/array/reversed0) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed1) + (get_global $std/array/reversed1) ) (if (i32.eqz @@ -7899,8 +8709,8 @@ (i32.const 2) ) (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed1) - (i32.const 216) + (get_global $std/array/reversed1) + (i32.const 296) (i32.const 0) ) ) @@ -7908,15 +8718,15 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 429) + (i32.const 96) + (i32.const 445) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed2) + (get_global $std/array/reversed2) ) (if (i32.eqz @@ -7925,8 +8735,8 @@ (i32.const 2) ) (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed2) - (i32.const 232) + (get_global $std/array/reversed2) + (i32.const 320) (i32.const 0) ) ) @@ -7934,15 +8744,15 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 432) + (i32.const 96) + (i32.const 448) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed4) + (get_global $std/array/reversed4) ) (if (i32.eqz @@ -7951,7 +8761,7 @@ (i32.const 2) ) (call $std/array/isArraysEqual|trampoline - (get_global $std/array/revesed4) + (get_global $std/array/reversed4) (get_global $std/array/expected4) (i32.const 0) ) @@ -7960,20 +8770,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 435) + (i32.const 96) + (i32.const 451) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed64) + (get_global $std/array/reversed64) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed64) + (get_global $std/array/reversed64) (get_global $std/array/expected4) (i32.const 4) ) @@ -7981,20 +8791,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 438) + (i32.const 96) + (i32.const 454) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed128) + (get_global $std/array/reversed128) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed128) + (get_global $std/array/reversed128) (get_global $std/array/expected4) (i32.const 4) ) @@ -8002,20 +8812,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 441) + (i32.const 96) + (i32.const 457) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed1024) + (get_global $std/array/reversed1024) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed1024) + (get_global $std/array/reversed1024) (get_global $std/array/expected4) (i32.const 4) ) @@ -8023,20 +8833,20 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 444) + (i32.const 96) + (i32.const 460) (i32.const 0) ) (unreachable) ) ) (call $std/array/assertSortedDefault - (get_global $std/array/revesed10000) + (get_global $std/array/reversed10000) ) (if (i32.eqz (call $std/array/isArraysEqual - (get_global $std/array/revesed10000) + (get_global $std/array/reversed10000) (get_global $std/array/expected4) (i32.const 4) ) @@ -8044,8 +8854,8 @@ (block (call $abort (i32.const 0) - (i32.const 32) - (i32.const 447) + (i32.const 96) + (i32.const 463) (i32.const 0) ) (unreachable) diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index 6ec483a6..638104df 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -1,7 +1,7 @@ (module (type $iii (func (param i32 i32) (result i32))) - (type $ii (func (param i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $v (func)) @@ -11,10 +11,11 @@ (global $std/arraybuffer/buffer (mut i32) (i32.const 0)) (global $argumentCount (mut i32) (i32.const 0)) (global $std/arraybuffer/sliced (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 104)) + (global $HEAP_BASE i32 (i32.const 148)) (memory $0 1) - (data (i32.const 4) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") - (data (i32.const 64) "\12\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 4) "\13\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 48) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 108) "\12\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") (export "memory" (memory $0)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -130,7 +131,7 @@ (block (call $abort (i32.const 0) - (i32.const 4) + (i32.const 48) (i32.const 22) (i32.const 2) ) @@ -489,7 +490,15 @@ (get_local $1) (i32.const 1073741816) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 13) + (i32.const 40) + ) + (unreachable) + ) ) (call $~lib/memory/set_memory (i32.add @@ -2537,7 +2546,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 5) (i32.const 0) ) @@ -2566,7 +2575,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 9) (i32.const 0) ) @@ -2581,7 +2590,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 10) (i32.const 0) ) @@ -2610,7 +2619,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 14) (i32.const 0) ) @@ -2639,7 +2648,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 18) (i32.const 0) ) @@ -2663,7 +2672,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 22) (i32.const 0) ) @@ -2687,7 +2696,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 26) (i32.const 0) ) @@ -2711,7 +2720,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 30) (i32.const 0) ) @@ -2735,7 +2744,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 34) (i32.const 0) ) @@ -2761,7 +2770,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 38) (i32.const 0) ) @@ -2775,7 +2784,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 39) (i32.const 0) ) diff --git a/tests/compiler/std/arraybuffer.untouched.wat b/tests/compiler/std/arraybuffer.untouched.wat index 5bd409ad..d4de2351 100644 --- a/tests/compiler/std/arraybuffer.untouched.wat +++ b/tests/compiler/std/arraybuffer.untouched.wat @@ -1,8 +1,8 @@ (module (type $i (func (result i32))) (type $iii (func (param i32 i32) (result i32))) - (type $ii (func (param i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) (type $iiii (func (param i32 i32 i32) (result i32))) (type $v (func)) @@ -18,10 +18,11 @@ (global $std/arraybuffer/buffer (mut i32) (i32.const 0)) (global $argumentCount (mut i32) (i32.const 0)) (global $std/arraybuffer/sliced (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 104)) + (global $HEAP_BASE i32 (i32.const 148)) (memory $0 1) - (data (i32.const 4) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") - (data (i32.const 64) "\12\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (data (i32.const 4) "\13\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (data (i32.const 48) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (data (i32.const 108) "\12\00\00\00s\00t\00d\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") (export "memory" (memory $0)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -165,7 +166,7 @@ (block (call $abort (i32.const 0) - (i32.const 4) + (i32.const 48) (i32.const 22) (i32.const 2) ) @@ -543,7 +544,15 @@ (get_local $1) (i32.const 1073741816) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 13) + (i32.const 40) + ) + (unreachable) + ) ) (set_local $2 (call $~lib/internal/arraybuffer/allocUnsafe @@ -2872,7 +2881,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 5) (i32.const 0) ) @@ -2903,7 +2912,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 9) (i32.const 0) ) @@ -2920,7 +2929,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 10) (i32.const 0) ) @@ -2951,7 +2960,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 14) (i32.const 0) ) @@ -2982,7 +2991,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 18) (i32.const 0) ) @@ -3008,7 +3017,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 22) (i32.const 0) ) @@ -3034,7 +3043,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 26) (i32.const 0) ) @@ -3060,7 +3069,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 30) (i32.const 0) ) @@ -3086,7 +3095,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 34) (i32.const 0) ) @@ -3117,7 +3126,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 38) (i32.const 0) ) @@ -3134,7 +3143,7 @@ (block (call $abort (i32.const 0) - (i32.const 64) + (i32.const 108) (i32.const 39) (i32.const 0) ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 82d58e02..2377eba8 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -12161,7 +12161,15 @@ (i32.eqz (get_global $~lib/math/random_seeded) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 32) + (i32.const 1000) + (i32.const 24) + ) + (unreachable) + ) ) (set_local $0 (get_global $~lib/math/random_state0) diff --git a/tests/compiler/std/math.untouched.wat b/tests/compiler/std/math.untouched.wat index b7f21f31..bac236c5 100644 --- a/tests/compiler/std/math.untouched.wat +++ b/tests/compiler/std/math.untouched.wat @@ -14381,7 +14381,15 @@ (i32.eqz (get_global $~lib/math/random_seeded) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 32) + (i32.const 1000) + (i32.const 24) + ) + (unreachable) + ) ) (set_local $0 (get_global $~lib/math/random_state0) diff --git a/tests/compiler/std/operator-overloading.optimized.wat b/tests/compiler/std/operator-overloading.optimized.wat index 7a862dc6..fd943faa 100644 --- a/tests/compiler/std/operator-overloading.optimized.wat +++ b/tests/compiler/std/operator-overloading.optimized.wat @@ -3,6 +3,8 @@ (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $FFF (func (param f64 f64) (result f64))) + (type $FiF (func (param f64 i32) (result f64))) (type $v (func)) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) @@ -22,6 +24,9 @@ (global $std/operator-overloading/f1 (mut i32) (i32.const 0)) (global $std/operator-overloading/f2 (mut i32) (i32.const 0)) (global $std/operator-overloading/f (mut i32) (i32.const 0)) + (global $std/operator-overloading/p1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/p2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/p (mut i32) (i32.const 0)) (global $std/operator-overloading/n1 (mut i32) (i32.const 0)) (global $std/operator-overloading/n2 (mut i32) (i32.const 0)) (global $std/operator-overloading/n (mut i32) (i32.const 0)) @@ -49,6 +54,12 @@ (global $std/operator-overloading/leq1 (mut i32) (i32.const 0)) (global $std/operator-overloading/leq2 (mut i32) (i32.const 0)) (global $std/operator-overloading/leq (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii (mut i32) (i32.const 0)) (global $HEAP_BASE i32 (i32.const 64)) (memory $0 1) (data (i32.const 4) "\1b\00\00\00s\00t\00d\00/\00o\00p\00e\00r\00a\00t\00o\00r\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00.\00t\00s") @@ -270,7 +281,1553 @@ ) ) ) - (func $std/operator-overloading/Tester.and (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/math/NativeMath.scalbn (; 8 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (local $2 f64) + (set_local $2 + (get_local $0) + ) + (if + (i32.gt_s + (get_local $1) + (i32.const 1023) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 8988465674311579538646525e283) + ) + ) + (if + (i32.gt_s + (tee_local $1 + (i32.sub + (get_local $1) + (i32.const 1023) + ) + ) + (i32.const 1023) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 8988465674311579538646525e283) + ) + ) + (if + (i32.gt_s + (tee_local $1 + (i32.sub + (get_local $1) + (i32.const 1023) + ) + ) + (i32.const 1023) + ) + (set_local $1 + (i32.const 1023) + ) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $1) + (i32.const -1022) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 2.2250738585072014e-308) + ) + ) + (if + (i32.lt_s + (tee_local $1 + (i32.add + (get_local $1) + (i32.const 1022) + ) + ) + (i32.const -1022) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 2.2250738585072014e-308) + ) + ) + (if + (i32.lt_s + (tee_local $1 + (i32.add + (get_local $1) + (i32.const 1022) + ) + ) + (i32.const -1022) + ) + (set_local $1 + (i32.const -1022) + ) + ) + ) + ) + ) + ) + ) + (f64.mul + (get_local $2) + (f64.reinterpret/i64 + (i64.shl + (i64.add + (i64.extend_u/i32 + (get_local $1) + ) + (i64.const 1023) + ) + (i64.const 52) + ) + ) + ) + ) + (func $~lib/math/NativeMath.pow (; 9 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (local $2 f64) + (local $3 f64) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 f64) + (local $10 i32) + (local $11 i32) + (local $12 f64) + (local $13 i32) + (local $14 f64) + (local $15 i32) + (local $16 f64) + (local $17 f64) + (local $18 f64) + (local $19 i64) + (block $folding-inner1 + (block $folding-inner0 + (set_local $4 + (i32.wrap/i64 + (i64.shr_u + (tee_local $19 + (i64.reinterpret/f64 + (get_local $0) + ) + ) + (i64.const 32) + ) + ) + ) + (set_local $13 + (i32.wrap/i64 + (get_local $19) + ) + ) + (set_local $5 + (i32.and + (get_local $4) + (i32.const 2147483647) + ) + ) + (if + (i32.eqz + (i32.or + (tee_local $10 + (i32.and + (tee_local $11 + (i32.wrap/i64 + (i64.shr_u + (tee_local $19 + (i64.reinterpret/f64 + (get_local $1) + ) + ) + (i64.const 32) + ) + ) + ) + (i32.const 2147483647) + ) + ) + (tee_local $6 + (i32.wrap/i64 + (get_local $19) + ) + ) + ) + ) + (return + (f64.const 1) + ) + ) + (if + (i32.and + (if (result i32) + (tee_local $7 + (i32.and + (if (result i32) + (tee_local $7 + (i32.and + (if (result i32) + (tee_local $7 + (i32.gt_s + (get_local $5) + (i32.const 2146435072) + ) + ) + (get_local $7) + (if (result i32) + (tee_local $7 + (i32.eq + (get_local $5) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $13) + (i32.const 0) + ) + (get_local $7) + ) + ) + (i32.const 1) + ) + ) + (get_local $7) + (i32.gt_s + (get_local $10) + (i32.const 2146435072) + ) + ) + (i32.const 1) + ) + ) + (get_local $7) + (if (result i32) + (tee_local $7 + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $7) + ) + ) + (i32.const 1) + ) + (return + (f64.add + (get_local $0) + (get_local $1) + ) + ) + ) + (if + (i32.lt_s + (get_local $4) + (i32.const 0) + ) + (if + (i32.ge_s + (get_local $10) + (i32.const 1128267776) + ) + (set_local $15 + (i32.const 2) + ) + (if + (i32.ge_s + (get_local $10) + (i32.const 1072693248) + ) + (if + (i32.gt_s + (tee_local $8 + (i32.sub + (i32.shr_s + (get_local $10) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (i32.const 20) + ) + (if + (i32.eq + (i32.shl + (tee_local $7 + (i32.shr_u + (get_local $6) + (i32.sub + (i32.const 52) + (get_local $8) + ) + ) + ) + (i32.sub + (i32.const 52) + (get_local $8) + ) + ) + (get_local $6) + ) + (set_local $15 + (i32.sub + (i32.const 2) + (i32.and + (get_local $7) + (i32.const 1) + ) + ) + ) + ) + (if + (i32.eqz + (get_local $6) + ) + (if + (i32.eq + (i32.shl + (tee_local $7 + (i32.shr_s + (get_local $10) + (i32.sub + (i32.const 20) + (get_local $8) + ) + ) + ) + (i32.sub + (i32.const 20) + (get_local $8) + ) + ) + (get_local $10) + ) + (set_local $15 + (i32.sub + (i32.const 2) + (i32.and + (get_local $7) + (i32.const 1) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (if + (i32.eqz + (get_local $6) + ) + (block + (if + (i32.eq + (get_local $10) + (i32.const 2146435072) + ) + (if + (i32.or + (i32.sub + (get_local $5) + (i32.const 1072693248) + ) + (get_local $13) + ) + (if + (i32.ge_s + (get_local $5) + (i32.const 1072693248) + ) + (return + (select + (get_local $1) + (f64.const 0) + (i32.ge_s + (get_local $11) + (i32.const 0) + ) + ) + ) + (return + (select + (f64.const 0) + (f64.neg + (get_local $1) + ) + (i32.ge_s + (get_local $11) + (i32.const 0) + ) + ) + ) + ) + (return + (f64.const nan:0x8000000000000) + ) + ) + ) + (if + (i32.eq + (get_local $10) + (i32.const 1072693248) + ) + (block + (if + (i32.ge_s + (get_local $11) + (i32.const 0) + ) + (return + (get_local $0) + ) + ) + (return + (f64.div + (f64.const 1) + (get_local $0) + ) + ) + ) + ) + (if + (i32.eq + (get_local $11) + (i32.const 1073741824) + ) + (return + (f64.mul + (get_local $0) + (get_local $0) + ) + ) + ) + (if + (i32.eq + (get_local $11) + (i32.const 1071644672) + ) + (if + (i32.ge_s + (get_local $4) + (i32.const 0) + ) + (return + (f64.sqrt + (get_local $0) + ) + ) + ) + ) + ) + ) + (set_local $2 + (f64.abs + (get_local $0) + ) + ) + (if + (i32.eqz + (get_local $13) + ) + (if + (i32.and + (if (result i32) + (tee_local $7 + (i32.and + (if (result i32) + (tee_local $7 + (i32.eq + (get_local $5) + (i32.const 2146435072) + ) + ) + (get_local $7) + (i32.eqz + (get_local $5) + ) + ) + (i32.const 1) + ) + ) + (get_local $7) + (i32.eq + (get_local $5) + (i32.const 1072693248) + ) + ) + (i32.const 1) + ) + (block + (if + (i32.lt_s + (get_local $11) + (i32.const 0) + ) + (set_local $2 + (f64.div + (f64.const 1) + (get_local $2) + ) + ) + ) + (if + (i32.lt_s + (get_local $4) + (i32.const 0) + ) + (if + (i32.or + (i32.sub + (get_local $5) + (i32.const 1072693248) + ) + (get_local $15) + ) + (if + (i32.eq + (get_local $15) + (i32.const 1) + ) + (set_local $2 + (f64.neg + (get_local $2) + ) + ) + ) + (set_local $2 + (f64.div + (f64.sub + (get_local $2) + (get_local $2) + ) + (f64.sub + (get_local $2) + (get_local $2) + ) + ) + ) + ) + ) + (return + (get_local $2) + ) + ) + ) + ) + (set_local $12 + (f64.const 1) + ) + (if + (i32.lt_s + (get_local $4) + (i32.const 0) + ) + (block + (if + (i32.eqz + (get_local $15) + ) + (return + (f64.div + (f64.sub + (get_local $0) + (get_local $0) + ) + (f64.sub + (get_local $0) + (get_local $0) + ) + ) + ) + ) + (if + (i32.eq + (get_local $15) + (i32.const 1) + ) + (set_local $12 + (f64.const -1) + ) + ) + ) + ) + (set_local $2 + (if (result f64) + (i32.gt_s + (get_local $10) + (i32.const 1105199104) + ) + (block (result f64) + (if + (i32.gt_s + (get_local $10) + (i32.const 1139802112) + ) + (block + (if + (i32.le_s + (get_local $5) + (i32.const 1072693247) + ) + (return + (select + (f64.const inf) + (f64.const 0) + (i32.lt_s + (get_local $11) + (i32.const 0) + ) + ) + ) + ) + (if + (i32.ge_s + (get_local $5) + (i32.const 1072693248) + ) + (return + (select + (f64.const inf) + (f64.const 0) + (i32.gt_s + (get_local $11) + (i32.const 0) + ) + ) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $5) + (i32.const 1072693247) + ) + (return + (select + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + (i32.lt_s + (get_local $11) + (i32.const 0) + ) + ) + ) + ) + (if + (i32.gt_s + (get_local $5) + (i32.const 1072693248) + ) + (return + (select + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + (i32.gt_s + (get_local $11) + (i32.const 0) + ) + ) + ) + ) + (set_local $0 + (f64.mul + (f64.mul + (tee_local $3 + (f64.sub + (get_local $2) + (f64.const 1) + ) + ) + (get_local $3) + ) + (f64.sub + (f64.const 0.5) + (f64.mul + (get_local $3) + (f64.sub + (f64.const 0.3333333333333333) + (f64.mul + (get_local $3) + (f64.const 0.25) + ) + ) + ) + ) + ) + ) + (set_local $9 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (f64.add + (tee_local $16 + (f64.mul + (f64.const 1.4426950216293335) + (get_local $3) + ) + ) + (tee_local $17 + (f64.sub + (f64.mul + (get_local $3) + (f64.const 1.9259629911266175e-08) + ) + (f64.mul + (get_local $0) + (f64.const 1.4426950408889634) + ) + ) + ) + ) + ) + (i64.const -4294967296) + ) + ) + ) + (f64.sub + (get_local $17) + (f64.sub + (get_local $9) + (get_local $16) + ) + ) + ) + (block (result f64) + (set_local $4 + (i32.const 0) + ) + (if + (i32.lt_s + (get_local $5) + (i32.const 1048576) + ) + (block + (set_local $4 + (i32.sub + (get_local $4) + (i32.const 53) + ) + ) + (set_local $5 + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (tee_local $2 + (f64.mul + (get_local $2) + (f64.const 9007199254740992) + ) + ) + ) + (i64.const 32) + ) + ) + ) + ) + ) + (set_local $4 + (i32.add + (get_local $4) + (i32.sub + (i32.shr_s + (get_local $5) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + ) + (set_local $5 + (i32.or + (tee_local $6 + (i32.and + (get_local $5) + (i32.const 1048575) + ) + ) + (i32.const 1072693248) + ) + ) + (set_local $8 + (if (result i32) + (i32.le_s + (get_local $6) + (i32.const 235662) + ) + (i32.const 0) + (if (result i32) + (i32.lt_s + (get_local $6) + (i32.const 767610) + ) + (i32.const 1) + (block (result i32) + (set_local $4 + (i32.add + (get_local $4) + (i32.const 1) + ) + ) + (set_local $5 + (i32.sub + (get_local $5) + (i32.const 1048576) + ) + ) + (i32.const 0) + ) + ) + ) + ) + (set_local $3 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (tee_local $18 + (f64.mul + (tee_local $16 + (f64.sub + (tee_local $2 + (f64.reinterpret/i64 + (i64.or + (i64.and + (i64.reinterpret/f64 + (get_local $2) + ) + (i64.const 4294967295) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $5) + ) + (i64.const 32) + ) + ) + ) + ) + (tee_local $0 + (select + (f64.const 1.5) + (f64.const 1) + (get_local $8) + ) + ) + ) + ) + (tee_local $17 + (f64.div + (f64.const 1) + (f64.add + (get_local $2) + (get_local $0) + ) + ) + ) + ) + ) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $2 + (f64.sub + (get_local $2) + (f64.sub + (tee_local $9 + (f64.reinterpret/i64 + (i64.shl + (i64.extend_u/i32 + (i32.add + (i32.add + (i32.or + (i32.shr_s + (get_local $5) + (i32.const 1) + ) + (i32.const 536870912) + ) + (i32.const 524288) + ) + (i32.shl + (get_local $8) + (i32.const 18) + ) + ) + ) + (i64.const 32) + ) + ) + ) + (get_local $0) + ) + ) + ) + (set_local $2 + (f64.sub + (tee_local $2 + (f64.add + (f64.mul + (f64.mul + (tee_local $14 + (f64.mul + (get_local $18) + (get_local $18) + ) + ) + (get_local $14) + ) + (f64.add + (f64.const 0.5999999999999946) + (f64.mul + (get_local $14) + (f64.add + (f64.const 0.4285714285785502) + (f64.mul + (get_local $14) + (f64.add + (f64.const 0.33333332981837743) + (f64.mul + (get_local $14) + (f64.add + (f64.const 0.272728123808534) + (f64.mul + (get_local $14) + (f64.add + (f64.const 0.23066074577556175) + (f64.mul + (get_local $14) + (f64.const 0.20697501780033842) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (f64.mul + (tee_local $0 + (f64.mul + (get_local $17) + (f64.sub + (f64.sub + (get_local $16) + (f64.mul + (get_local $3) + (get_local $9) + ) + ) + (f64.mul + (get_local $3) + (get_local $2) + ) + ) + ) + ) + (f64.add + (get_local $3) + (get_local $18) + ) + ) + ) + ) + (f64.sub + (f64.sub + (tee_local $9 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (f64.add + (f64.add + (f64.const 3) + (tee_local $14 + (f64.mul + (get_local $3) + (get_local $3) + ) + ) + ) + (get_local $2) + ) + ) + (i64.const -4294967296) + ) + ) + ) + (f64.const 3) + ) + (get_local $14) + ) + ) + ) + (set_local $9 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (f64.add + (f64.add + (f64.add + (tee_local $18 + (f64.mul + (f64.const 0.9617967009544373) + (tee_local $0 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (f64.add + (tee_local $16 + (f64.mul + (get_local $3) + (get_local $9) + ) + ) + (tee_local $17 + (f64.add + (f64.mul + (get_local $0) + (get_local $9) + ) + (f64.mul + (get_local $2) + (get_local $18) + ) + ) + ) + ) + ) + (i64.const -4294967296) + ) + ) + ) + ) + ) + (tee_local $2 + (f64.add + (f64.add + (f64.mul + (f64.const -7.028461650952758e-09) + (get_local $0) + ) + (f64.mul + (f64.sub + (get_local $17) + (f64.sub + (get_local $0) + (get_local $16) + ) + ) + (f64.const 0.9617966939259756) + ) + ) + (select + (f64.const 1.350039202129749e-08) + (f64.const 0) + (get_local $8) + ) + ) + ) + ) + (tee_local $0 + (select + (f64.const 0.5849624872207642) + (f64.const 0) + (get_local $8) + ) + ) + ) + (tee_local $3 + (f64.convert_s/i32 + (get_local $4) + ) + ) + ) + ) + (i64.const -4294967296) + ) + ) + ) + (f64.sub + (get_local $2) + (f64.sub + (f64.sub + (f64.sub + (get_local $9) + (get_local $3) + ) + (get_local $0) + ) + (get_local $18) + ) + ) + ) + ) + ) + (set_local $6 + (i32.wrap/i64 + (i64.shr_u + (tee_local $19 + (i64.reinterpret/f64 + (tee_local $2 + (f64.add + (tee_local $1 + (f64.add + (f64.mul + (f64.sub + (get_local $1) + (tee_local $0 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $1) + ) + (i64.const -4294967296) + ) + ) + ) + ) + (get_local $9) + ) + (f64.mul + (get_local $1) + (get_local $2) + ) + ) + ) + (tee_local $0 + (f64.mul + (get_local $0) + (get_local $9) + ) + ) + ) + ) + ) + ) + (i64.const 32) + ) + ) + ) + (set_local $13 + (i32.wrap/i64 + (get_local $19) + ) + ) + (if + (i32.ge_s + (get_local $6) + (i32.const 1083179008) + ) + (br_if $folding-inner1 + (i32.or + (i32.or + (i32.sub + (get_local $6) + (i32.const 1083179008) + ) + (get_local $13) + ) + (f64.gt + (f64.add + (get_local $1) + (f64.const 8.008566259537294e-17) + ) + (f64.sub + (get_local $2) + (get_local $0) + ) + ) + ) + ) + (if + (i32.ge_s + (i32.and + (get_local $6) + (i32.const 2147483647) + ) + (i32.const 1083231232) + ) + (br_if $folding-inner0 + (i32.or + (i32.or + (i32.sub + (get_local $6) + (i32.const -1064252416) + ) + (get_local $13) + ) + (f64.le + (get_local $1) + (f64.sub + (get_local $2) + (get_local $0) + ) + ) + ) + ) + ) + ) + (set_local $8 + (i32.sub + (i32.shr_s + (tee_local $13 + (i32.and + (get_local $6) + (i32.const 2147483647) + ) + ) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (set_local $4 + (i32.const 0) + ) + (if + (i32.gt_s + (get_local $13) + (i32.const 1071644672) + ) + (block + (set_local $8 + (i32.sub + (i32.shr_s + (i32.and + (tee_local $4 + (i32.add + (get_local $6) + (i32.shr_s + (i32.const 1048576) + (i32.add + (get_local $8) + (i32.const 1) + ) + ) + ) + ) + (i32.const 2147483647) + ) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (set_local $3 + (f64.reinterpret/i64 + (i64.shl + (i64.extend_u/i32 + (i32.and + (get_local $4) + (i32.xor + (i32.shr_s + (i32.const 1048575) + (get_local $8) + ) + (i32.const -1) + ) + ) + ) + (i64.const 32) + ) + ) + ) + (set_local $4 + (i32.shr_s + (i32.or + (i32.and + (get_local $4) + (i32.const 1048575) + ) + (i32.const 1048576) + ) + (i32.sub + (i32.const 20) + (get_local $8) + ) + ) + ) + (if + (i32.lt_s + (get_local $6) + (i32.const 0) + ) + (set_local $4 + (i32.sub + (i32.const 0) + (get_local $4) + ) + ) + ) + (set_local $0 + (f64.sub + (get_local $0) + (get_local $3) + ) + ) + ) + ) + (return + (f64.mul + (get_local $12) + (tee_local $2 + (if (result f64) + (i32.le_s + (i32.shr_s + (tee_local $6 + (i32.add + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (tee_local $2 + (f64.sub + (f64.const 1) + (f64.sub + (f64.sub + (f64.div + (f64.mul + (tee_local $2 + (f64.add + (tee_local $16 + (f64.mul + (tee_local $3 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (f64.add + (get_local $1) + (get_local $0) + ) + ) + (i64.const -4294967296) + ) + ) + ) + (f64.const 0.6931471824645996) + ) + ) + (tee_local $17 + (f64.add + (f64.mul + (f64.sub + (get_local $1) + (f64.sub + (get_local $3) + (get_local $0) + ) + ) + (f64.const 0.6931471805599453) + ) + (f64.mul + (get_local $3) + (f64.const -1.904654299957768e-09) + ) + ) + ) + ) + ) + (tee_local $9 + (f64.sub + (get_local $2) + (f64.mul + (tee_local $3 + (f64.mul + (get_local $2) + (get_local $2) + ) + ) + (f64.add + (f64.const 0.16666666666666602) + (f64.mul + (get_local $3) + (f64.add + (f64.const -2.7777777777015593e-03) + (f64.mul + (get_local $3) + (f64.add + (f64.const 6.613756321437934e-05) + (f64.mul + (get_local $3) + (f64.add + (f64.const -1.6533902205465252e-06) + (f64.mul + (get_local $3) + (f64.const 4.1381367970572385e-08) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (f64.sub + (get_local $9) + (f64.const 2) + ) + ) + (f64.add + (tee_local $0 + (f64.sub + (get_local $17) + (f64.sub + (get_local $2) + (get_local $16) + ) + ) + ) + (f64.mul + (get_local $2) + (get_local $0) + ) + ) + ) + (get_local $2) + ) + ) + ) + ) + (i64.const 32) + ) + ) + (i32.shl + (get_local $4) + (i32.const 20) + ) + ) + ) + (i32.const 20) + ) + (i32.const 0) + ) + (call $~lib/math/NativeMath.scalbn + (get_local $2) + (get_local $4) + ) + (f64.reinterpret/i64 + (i64.or + (i64.and + (i64.reinterpret/f64 + (get_local $2) + ) + (i64.const 4294967295) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $6) + ) + (i64.const 32) + ) + ) + ) + ) + ) + ) + ) + ) + (return + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + ) + ) + (f64.mul + (f64.mul + (get_local $12) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + ) + (func $std/operator-overloading/Tester.pow (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.trunc_s/f64 + (call $~lib/math/NativeMath.pow + (f64.convert_s/i32 + (i32.load + (get_local $0) + ) + ) + (f64.convert_s/i32 + (i32.load + (get_local $1) + ) + ) + ) + ) + (i32.trunc_s/f64 + (call $~lib/math/NativeMath.pow + (f64.convert_s/i32 + (i32.load offset=4 + (get_local $0) + ) + ) + (f64.convert_s/i32 + (i32.load offset=4 + (get_local $1) + ) + ) + ) + ) + ) + ) + (func $std/operator-overloading/Tester.and (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (call $std/operator-overloading/Tester#constructor (i32.const 0) (i32.and @@ -291,7 +1848,7 @@ ) ) ) - (func $std/operator-overloading/Tester.or (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.or (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (call $std/operator-overloading/Tester#constructor (i32.const 0) (i32.or @@ -312,7 +1869,7 @@ ) ) ) - (func $std/operator-overloading/Tester.xor (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.xor (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (call $std/operator-overloading/Tester#constructor (i32.const 0) (i32.xor @@ -333,7 +1890,7 @@ ) ) ) - (func $std/operator-overloading/Tester.equals (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.equals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -360,7 +1917,7 @@ (i32.const 1) ) ) - (func $std/operator-overloading/Tester.notEquals (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.notEquals (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -387,7 +1944,7 @@ (i32.const 1) ) ) - (func $std/operator-overloading/Tester.greater (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.greater (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -414,7 +1971,7 @@ (i32.const 1) ) ) - (func $std/operator-overloading/Tester.greaterEquals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.greaterEquals (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -441,7 +1998,7 @@ (i32.const 1) ) ) - (func $std/operator-overloading/Tester.less (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.less (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -468,7 +2025,7 @@ (i32.const 1) ) ) - (func $std/operator-overloading/Tester.lessEquals (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.lessEquals (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (i32.and (if (result i32) @@ -495,8 +2052,9 @@ (i32.const 1) ) ) - (func $start (; 17 ;) (type $v) + (func $start (; 20 ;) (type $v) (local $0 i32) + (local $1 i32) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -556,7 +2114,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 82) + (i32.const 87) (i32.const 0) ) (unreachable) @@ -608,7 +2166,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 88) + (i32.const 93) (i32.const 0) ) (unreachable) @@ -661,7 +2219,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 94) + (i32.const 99) (i32.const 0) ) (unreachable) @@ -714,7 +2272,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 100) + (i32.const 105) (i32.const 0) ) (unreachable) @@ -766,7 +2324,60 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 106) + (i32.const 111) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/p1 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/p2 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 4) + (i32.const 5) + ) + ) + (set_global $std/operator-overloading/p + (call $std/operator-overloading/Tester.pow + (get_global $std/operator-overloading/p1) + (get_global $std/operator-overloading/p2) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $0 + (i32.eq + (i32.load + (get_global $std/operator-overloading/p) + ) + (i32.const 16) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/p) + ) + (i32.const 243) + ) + (get_local $0) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 117) (i32.const 0) ) (unreachable) @@ -819,7 +2430,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 112) + (i32.const 123) (i32.const 0) ) (unreachable) @@ -872,7 +2483,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 118) + (i32.const 129) (i32.const 0) ) (unreachable) @@ -925,7 +2536,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 124) + (i32.const 135) (i32.const 0) ) (unreachable) @@ -960,7 +2571,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 130) + (i32.const 141) (i32.const 0) ) (unreachable) @@ -992,7 +2603,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 136) + (i32.const 147) (i32.const 0) ) (unreachable) @@ -1010,7 +2621,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 140) + (i32.const 151) (i32.const 0) ) (unreachable) @@ -1031,7 +2642,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 144) + (i32.const 155) (i32.const 0) ) (unreachable) @@ -1066,7 +2677,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 150) + (i32.const 161) (i32.const 0) ) (unreachable) @@ -1101,7 +2712,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 156) + (i32.const 167) (i32.const 0) ) (unreachable) @@ -1136,7 +2747,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 162) + (i32.const 173) (i32.const 0) ) (unreachable) @@ -1171,7 +2782,151 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 168) + (i32.const 179) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/ais1 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 1) + (i32.const 2) + ) + ) + (set_global $std/operator-overloading/ais2 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/ais + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.add + (i32.load + (tee_local $0 + (get_global $std/operator-overloading/ais1) + ) + ) + (i32.load + (tee_local $1 + (get_global $std/operator-overloading/ais2) + ) + ) + ) + (i32.add + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $1 + (i32.eq + (i32.load + (get_global $std/operator-overloading/ais) + ) + (i32.const 3) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/ais) + ) + (i32.const 5) + ) + (get_local $1) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 193) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/aii1 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 1) + (i32.const 2) + ) + ) + (set_global $std/operator-overloading/aii2 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/aii + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.add + (i32.load + (tee_local $1 + (get_global $std/operator-overloading/aii1) + ) + ) + (i32.load + (tee_local $0 + (get_global $std/operator-overloading/aii2) + ) + ) + ) + (i32.add + (i32.load offset=4 + (get_local $1) + ) + (i32.load offset=4 + (get_local $0) + ) + ) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $0 + (i32.eq + (i32.load + (get_global $std/operator-overloading/aii) + ) + (i32.const 3) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/aii) + ) + (i32.const 5) + ) + (get_local $0) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 207) (i32.const 0) ) (unreachable) diff --git a/tests/compiler/std/operator-overloading.ts b/tests/compiler/std/operator-overloading.ts index 01d1221a..03b4f906 100644 --- a/tests/compiler/std/operator-overloading.ts +++ b/tests/compiler/std/operator-overloading.ts @@ -29,6 +29,11 @@ class Tester { return new Tester(a.x % b.x, a.y % b.y); } + @operator('**') + static pow(a: Tester, b: Tester): Tester { + return new Tester((a.x ** b.x), (a.y ** b.y)); + } + @operator('|') static or(a: Tester, b: Tester): Tester { return new Tester(a.x | b.x, a.y | b.y); @@ -99,12 +104,18 @@ var d2 = new Tester(3, 10); var d = d1 / d2; assert(d.x == 2 && d.y == 5); -// check fractional +// check remainder var f1 = new Tester(10, 10); var f2 = new Tester(6, 10); var f = f1 % f2; assert(f.x == 4 && f.y == 0); +// check power +var p1 = new Tester(2, 3); +var p2 = new Tester(4, 5); +var p = p1 ** p2; +assert(p.x == 16 && p.y == 243); + // check bitwise and var n1 = new Tester(0xFF, 0x0F); var n2 = new Tester(0x0F, 0xFF); @@ -166,3 +177,31 @@ var leq1 = new Tester(4, 3); var leq2 = new Tester(4, 3); var leq = leq1 <= leq2; assert(leq == true); + +// check inlined static +class TesterInlineStatic { + constructor(public x: i32, public y: i32) { + } + @inline @operator('+') + static add(a: TesterInlineStatic, b: TesterInlineStatic): TesterInlineStatic { + return new TesterInlineStatic(a.x + b.x, a.y + b.y); + } +} +var ais1 = new TesterInlineStatic(1, 2); +var ais2 = new TesterInlineStatic(2, 3); +var ais = ais1 + ais2; +assert(ais.x == 3 && ais.y == 5); + +// check inlined instance +class TesterInlineInstance { + constructor(public x: i32, public y: i32) { + } + @inline @operator('+') + add(b: TesterInlineInstance): TesterInlineInstance { + return new TesterInlineInstance(this.x + b.x, this.y + b.y); + } +} +var aii1 = new TesterInlineInstance(1, 2); +var aii2 = new TesterInlineInstance(2, 3); +var aii = aii1 + aii2; +assert(aii.x == 3 && aii.y == 5); diff --git a/tests/compiler/std/operator-overloading.untouched.wat b/tests/compiler/std/operator-overloading.untouched.wat index cba9ca09..77613597 100644 --- a/tests/compiler/std/operator-overloading.untouched.wat +++ b/tests/compiler/std/operator-overloading.untouched.wat @@ -4,6 +4,9 @@ (type $ii (func (param i32) (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) + (type $FFF (func (param f64 f64) (result f64))) + (type $F (func (result f64))) + (type $FiF (func (param f64 i32) (result f64))) (type $v (func)) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $~lib/internal/allocator/AL_BITS i32 (i32.const 3)) @@ -27,6 +30,9 @@ (global $std/operator-overloading/f1 (mut i32) (i32.const 0)) (global $std/operator-overloading/f2 (mut i32) (i32.const 0)) (global $std/operator-overloading/f (mut i32) (i32.const 0)) + (global $std/operator-overloading/p1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/p2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/p (mut i32) (i32.const 0)) (global $std/operator-overloading/n1 (mut i32) (i32.const 0)) (global $std/operator-overloading/n2 (mut i32) (i32.const 0)) (global $std/operator-overloading/n (mut i32) (i32.const 0)) @@ -54,6 +60,12 @@ (global $std/operator-overloading/leq1 (mut i32) (i32.const 0)) (global $std/operator-overloading/leq2 (mut i32) (i32.const 0)) (global $std/operator-overloading/leq (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/ais (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii1 (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii2 (mut i32) (i32.const 0)) + (global $std/operator-overloading/aii (mut i32) (i32.const 0)) (global $HEAP_BASE i32 (i32.const 64)) (memory $0 1) (data (i32.const 4) "\1b\00\00\00s\00t\00d\00/\00o\00p\00e\00r\00a\00t\00o\00r\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00.\00t\00s\00") @@ -313,7 +325,1742 @@ ) ) ) - (func $std/operator-overloading/Tester.and (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/math/NativeMath.scalbn (; 8 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (local $2 f64) + (nop) + (set_local $2 + (get_local $0) + ) + (if + (i32.gt_s + (get_local $1) + (i32.const 1023) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 8988465674311579538646525e283) + ) + ) + (set_local $1 + (i32.sub + (get_local $1) + (i32.const 1023) + ) + ) + (if + (i32.gt_s + (get_local $1) + (i32.const 1023) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 8988465674311579538646525e283) + ) + ) + (set_local $1 + (i32.sub + (get_local $1) + (i32.const 1023) + ) + ) + (if + (i32.gt_s + (get_local $1) + (i32.const 1023) + ) + (set_local $1 + (i32.const 1023) + ) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $1) + (i32.const -1022) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 2.2250738585072014e-308) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1022) + ) + ) + (if + (i32.lt_s + (get_local $1) + (i32.const -1022) + ) + (block + (set_local $2 + (f64.mul + (get_local $2) + (f64.const 2.2250738585072014e-308) + ) + ) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1022) + ) + ) + (if + (i32.lt_s + (get_local $1) + (i32.const -1022) + ) + (set_local $1 + (i32.const -1022) + ) + ) + ) + ) + ) + ) + ) + (return + (f64.mul + (get_local $2) + (f64.reinterpret/i64 + (i64.shl + (i64.add + (i64.const 1023) + (i64.extend_u/i32 + (get_local $1) + ) + ) + (i64.const 52) + ) + ) + ) + ) + ) + (func $~lib/math/NativeMath.pow (; 9 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (local $2 i64) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 f64) + (local $13 f64) + (local $14 f64) + (local $15 f64) + (local $16 f64) + (local $17 f64) + (local $18 f64) + (local $19 f64) + (local $20 f64) + (local $21 f64) + (local $22 f64) + (local $23 f64) + (local $24 i32) + (local $25 i32) + (local $26 f64) + (local $27 f64) + (local $28 f64) + (local $29 f64) + (local $30 f64) + (local $31 f64) + (local $32 f64) + (local $33 f64) + (local $34 f64) + (local $35 f64) + (local $36 f64) + (local $37 f64) + (local $38 i32) + (nop) + (set_local $2 + (i64.reinterpret/f64 + (get_local $0) + ) + ) + (set_local $3 + (i32.wrap/i64 + (i64.shr_u + (get_local $2) + (i64.const 32) + ) + ) + ) + (set_local $4 + (i32.wrap/i64 + (get_local $2) + ) + ) + (set_local $2 + (i64.reinterpret/f64 + (get_local $1) + ) + ) + (set_local $5 + (i32.wrap/i64 + (i64.shr_u + (get_local $2) + (i64.const 32) + ) + ) + ) + (set_local $6 + (i32.wrap/i64 + (get_local $2) + ) + ) + (set_local $7 + (i32.and + (get_local $3) + (i32.const 2147483647) + ) + ) + (set_local $8 + (i32.and + (get_local $5) + (i32.const 2147483647) + ) + ) + (if + (i32.eq + (i32.or + (get_local $8) + (get_local $6) + ) + (i32.const 0) + ) + (return + (f64.const 1) + ) + ) + (if + (i32.and + (if (result i32) + (tee_local $9 + (i32.and + (if (result i32) + (tee_local $9 + (i32.and + (if (result i32) + (tee_local $9 + (i32.gt_s + (get_local $7) + (i32.const 2146435072) + ) + ) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $4) + (i32.const 0) + ) + (get_local $9) + ) + ) + (i32.const 1) + ) + ) + (get_local $9) + (i32.gt_s + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.const 1) + ) + ) + (get_local $9) + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + ) + (i32.ne + (get_local $6) + (i32.const 0) + ) + (get_local $9) + ) + ) + (i32.const 1) + ) + (return + (f64.add + (get_local $0) + (get_local $1) + ) + ) + ) + (set_local $10 + (i32.const 0) + ) + (if + (i32.lt_s + (get_local $3) + (i32.const 0) + ) + (if + (i32.ge_s + (get_local $8) + (i32.const 1128267776) + ) + (set_local $10 + (i32.const 2) + ) + (if + (i32.ge_s + (get_local $8) + (i32.const 1072693248) + ) + (block + (set_local $11 + (i32.sub + (i32.shr_s + (get_local $8) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (if + (i32.gt_s + (get_local $11) + (i32.const 20) + ) + (block + (set_local $9 + (i32.shr_u + (get_local $6) + (i32.sub + (i32.const 52) + (get_local $11) + ) + ) + ) + (if + (i32.eq + (i32.shl + (get_local $9) + (i32.sub + (i32.const 52) + (get_local $11) + ) + ) + (get_local $6) + ) + (set_local $10 + (i32.sub + (i32.const 2) + (i32.and + (get_local $9) + (i32.const 1) + ) + ) + ) + ) + ) + (if + (i32.eq + (get_local $6) + (i32.const 0) + ) + (block + (set_local $9 + (i32.shr_s + (get_local $8) + (i32.sub + (i32.const 20) + (get_local $11) + ) + ) + ) + (if + (i32.eq + (i32.shl + (get_local $9) + (i32.sub + (i32.const 20) + (get_local $11) + ) + ) + (get_local $8) + ) + (set_local $10 + (i32.sub + (i32.const 2) + (i32.and + (get_local $9) + (i32.const 1) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (if + (i32.eq + (get_local $6) + (i32.const 0) + ) + (block + (if + (i32.eq + (get_local $8) + (i32.const 2146435072) + ) + (if + (i32.eq + (i32.or + (i32.sub + (get_local $7) + (i32.const 1072693248) + ) + (get_local $4) + ) + (i32.const 0) + ) + (return + (f64.const nan:0x8000000000000) + ) + (if + (i32.ge_s + (get_local $7) + (i32.const 1072693248) + ) + (return + (if (result f64) + (i32.ge_s + (get_local $5) + (i32.const 0) + ) + (get_local $1) + (f64.const 0) + ) + ) + (return + (if (result f64) + (i32.ge_s + (get_local $5) + (i32.const 0) + ) + (f64.const 0) + (f64.neg + (get_local $1) + ) + ) + ) + ) + ) + ) + (if + (i32.eq + (get_local $8) + (i32.const 1072693248) + ) + (block + (if + (i32.ge_s + (get_local $5) + (i32.const 0) + ) + (return + (get_local $0) + ) + ) + (return + (f64.div + (f64.const 1) + (get_local $0) + ) + ) + ) + ) + (if + (i32.eq + (get_local $5) + (i32.const 1073741824) + ) + (return + (f64.mul + (get_local $0) + (get_local $0) + ) + ) + ) + (if + (i32.eq + (get_local $5) + (i32.const 1071644672) + ) + (if + (i32.ge_s + (get_local $3) + (i32.const 0) + ) + (return + (f64.sqrt + (get_local $0) + ) + ) + ) + ) + ) + ) + (set_local $12 + (f64.abs + (get_local $0) + ) + ) + (if + (i32.eq + (get_local $4) + (i32.const 0) + ) + (if + (i32.and + (if (result i32) + (tee_local $9 + (i32.and + (if (result i32) + (tee_local $9 + (i32.eq + (get_local $7) + (i32.const 2146435072) + ) + ) + (get_local $9) + (i32.eq + (get_local $7) + (i32.const 0) + ) + ) + (i32.const 1) + ) + ) + (get_local $9) + (i32.eq + (get_local $7) + (i32.const 1072693248) + ) + ) + (i32.const 1) + ) + (block + (set_local $13 + (get_local $12) + ) + (if + (i32.lt_s + (get_local $5) + (i32.const 0) + ) + (set_local $13 + (f64.div + (f64.const 1) + (get_local $13) + ) + ) + ) + (if + (i32.lt_s + (get_local $3) + (i32.const 0) + ) + (if + (i32.eq + (i32.or + (i32.sub + (get_local $7) + (i32.const 1072693248) + ) + (get_local $10) + ) + (i32.const 0) + ) + (set_local $13 + (f64.div + (f64.sub + (get_local $13) + (get_local $13) + ) + (f64.sub + (get_local $13) + (get_local $13) + ) + ) + ) + (if + (i32.eq + (get_local $10) + (i32.const 1) + ) + (set_local $13 + (f64.neg + (get_local $13) + ) + ) + ) + ) + ) + (return + (get_local $13) + ) + ) + ) + ) + (set_local $14 + (f64.const 1) + ) + (if + (i32.lt_s + (get_local $3) + (i32.const 0) + ) + (block + (if + (i32.eq + (get_local $10) + (i32.const 0) + ) + (return + (f64.div + (f64.sub + (get_local $0) + (get_local $0) + ) + (f64.sub + (get_local $0) + (get_local $0) + ) + ) + ) + ) + (if + (i32.eq + (get_local $10) + (i32.const 1) + ) + (set_local $14 + (f64.const -1) + ) + ) + ) + ) + (nop) + (nop) + (if + (i32.gt_s + (get_local $8) + (i32.const 1105199104) + ) + (block + (if + (i32.gt_s + (get_local $8) + (i32.const 1139802112) + ) + (block + (if + (i32.le_s + (get_local $7) + (i32.const 1072693247) + ) + (return + (if (result f64) + (i32.lt_s + (get_local $5) + (i32.const 0) + ) + (f64.mul + (f64.const 1.e+300) + (f64.const 1.e+300) + ) + (f64.mul + (f64.const 1e-300) + (f64.const 1e-300) + ) + ) + ) + ) + (if + (i32.ge_s + (get_local $7) + (i32.const 1072693248) + ) + (return + (if (result f64) + (i32.gt_s + (get_local $5) + (i32.const 0) + ) + (f64.mul + (f64.const 1.e+300) + (f64.const 1.e+300) + ) + (f64.mul + (f64.const 1e-300) + (f64.const 1e-300) + ) + ) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $7) + (i32.const 1072693247) + ) + (return + (if (result f64) + (i32.lt_s + (get_local $5) + (i32.const 0) + ) + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + ) + ) + ) + (if + (i32.gt_s + (get_local $7) + (i32.const 1072693248) + ) + (return + (if (result f64) + (i32.gt_s + (get_local $5) + (i32.const 0) + ) + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + ) + ) + ) + (set_local $20 + (f64.sub + (get_local $12) + (f64.const 1) + ) + ) + (set_local $23 + (f64.mul + (f64.mul + (get_local $20) + (get_local $20) + ) + (f64.sub + (f64.const 0.5) + (f64.mul + (get_local $20) + (f64.sub + (f64.const 0.3333333333333333) + (f64.mul + (get_local $20) + (f64.const 0.25) + ) + ) + ) + ) + ) + ) + (set_local $21 + (f64.mul + (f64.const 1.4426950216293335) + (get_local $20) + ) + ) + (set_local $22 + (f64.sub + (f64.mul + (get_local $20) + (f64.const 1.9259629911266175e-08) + ) + (f64.mul + (get_local $23) + (f64.const 1.4426950408889634) + ) + ) + ) + (set_local $15 + (f64.add + (get_local $21) + (get_local $22) + ) + ) + (set_local $15 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $15) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $16 + (f64.sub + (get_local $22) + (f64.sub + (get_local $15) + (get_local $21) + ) + ) + ) + ) + (block + (nop) + (set_local $25 + (i32.const 0) + ) + (if + (i32.lt_s + (get_local $7) + (i32.const 1048576) + ) + (block + (set_local $12 + (f64.mul + (get_local $12) + (f64.const 9007199254740992) + ) + ) + (set_local $25 + (i32.sub + (get_local $25) + (i32.const 53) + ) + ) + (set_local $7 + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (get_local $12) + ) + (i64.const 32) + ) + ) + ) + ) + ) + (set_local $25 + (i32.add + (get_local $25) + (i32.sub + (i32.shr_s + (get_local $7) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + ) + (set_local $24 + (i32.and + (get_local $7) + (i32.const 1048575) + ) + ) + (set_local $7 + (i32.or + (get_local $24) + (i32.const 1072693248) + ) + ) + (if + (i32.le_s + (get_local $24) + (i32.const 235662) + ) + (set_local $11 + (i32.const 0) + ) + (if + (i32.lt_s + (get_local $24) + (i32.const 767610) + ) + (set_local $11 + (i32.const 1) + ) + (block + (set_local $11 + (i32.const 0) + ) + (set_local $25 + (i32.add + (get_local $25) + (i32.const 1) + ) + ) + (set_local $7 + (i32.sub + (get_local $7) + (i32.const 1048576) + ) + ) + ) + ) + ) + (set_local $12 + (f64.reinterpret/i64 + (i64.or + (i64.and + (i64.reinterpret/f64 + (get_local $12) + ) + (i64.const 4294967295) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $7) + ) + (i64.const 32) + ) + ) + ) + ) + (set_local $32 + (select + (f64.const 1.5) + (f64.const 1) + (get_local $11) + ) + ) + (set_local $21 + (f64.sub + (get_local $12) + (get_local $32) + ) + ) + (set_local $22 + (f64.div + (f64.const 1) + (f64.add + (get_local $12) + (get_local $32) + ) + ) + ) + (set_local $26 + (f64.mul + (get_local $21) + (get_local $22) + ) + ) + (set_local $28 + (get_local $26) + ) + (set_local $28 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $28) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $30 + (f64.reinterpret/i64 + (i64.shl + (i64.extend_u/i32 + (i32.add + (i32.add + (i32.or + (i32.shr_s + (get_local $7) + (i32.const 1) + ) + (i32.const 536870912) + ) + (i32.const 524288) + ) + (i32.shl + (get_local $11) + (i32.const 18) + ) + ) + ) + (i64.const 32) + ) + ) + ) + (set_local $31 + (f64.sub + (get_local $12) + (f64.sub + (get_local $30) + (get_local $32) + ) + ) + ) + (set_local $29 + (f64.mul + (get_local $22) + (f64.sub + (f64.sub + (get_local $21) + (f64.mul + (get_local $28) + (get_local $30) + ) + ) + (f64.mul + (get_local $28) + (get_local $31) + ) + ) + ) + ) + (set_local $27 + (f64.mul + (get_local $26) + (get_local $26) + ) + ) + (set_local $19 + (f64.mul + (f64.mul + (get_local $27) + (get_local $27) + ) + (f64.add + (f64.const 0.5999999999999946) + (f64.mul + (get_local $27) + (f64.add + (f64.const 0.4285714285785502) + (f64.mul + (get_local $27) + (f64.add + (f64.const 0.33333332981837743) + (f64.mul + (get_local $27) + (f64.add + (f64.const 0.272728123808534) + (f64.mul + (get_local $27) + (f64.add + (f64.const 0.23066074577556175) + (f64.mul + (get_local $27) + (f64.const 0.20697501780033842) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (set_local $19 + (f64.add + (get_local $19) + (f64.mul + (get_local $29) + (f64.add + (get_local $28) + (get_local $26) + ) + ) + ) + ) + (set_local $27 + (f64.mul + (get_local $28) + (get_local $28) + ) + ) + (set_local $30 + (f64.add + (f64.add + (f64.const 3) + (get_local $27) + ) + (get_local $19) + ) + ) + (set_local $30 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $30) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $31 + (f64.sub + (get_local $19) + (f64.sub + (f64.sub + (get_local $30) + (f64.const 3) + ) + (get_local $27) + ) + ) + ) + (set_local $21 + (f64.mul + (get_local $28) + (get_local $30) + ) + ) + (set_local $22 + (f64.add + (f64.mul + (get_local $29) + (get_local $30) + ) + (f64.mul + (get_local $31) + (get_local $26) + ) + ) + ) + (set_local $17 + (f64.add + (get_local $21) + (get_local $22) + ) + ) + (set_local $17 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $17) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $18 + (f64.sub + (get_local $22) + (f64.sub + (get_local $17) + (get_local $21) + ) + ) + ) + (set_local $33 + (f64.mul + (f64.const 0.9617967009544373) + (get_local $17) + ) + ) + (set_local $34 + (select + (f64.const 1.350039202129749e-08) + (f64.const 0) + (get_local $11) + ) + ) + (set_local $35 + (f64.add + (f64.add + (f64.mul + (f64.const -7.028461650952758e-09) + (get_local $17) + ) + (f64.mul + (get_local $18) + (f64.const 0.9617966939259756) + ) + ) + (get_local $34) + ) + ) + (set_local $20 + (f64.convert_s/i32 + (get_local $25) + ) + ) + (set_local $36 + (select + (f64.const 0.5849624872207642) + (f64.const 0) + (get_local $11) + ) + ) + (set_local $15 + (f64.add + (f64.add + (f64.add + (get_local $33) + (get_local $35) + ) + (get_local $36) + ) + (get_local $20) + ) + ) + (set_local $15 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $15) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $16 + (f64.sub + (get_local $35) + (f64.sub + (f64.sub + (f64.sub + (get_local $15) + (get_local $20) + ) + (get_local $36) + ) + (get_local $33) + ) + ) + ) + ) + ) + (set_local $37 + (get_local $1) + ) + (set_local $37 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $37) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $18 + (f64.add + (f64.mul + (f64.sub + (get_local $1) + (get_local $37) + ) + (get_local $15) + ) + (f64.mul + (get_local $1) + (get_local $16) + ) + ) + ) + (set_local $17 + (f64.mul + (get_local $37) + (get_local $15) + ) + ) + (set_local $13 + (f64.add + (get_local $18) + (get_local $17) + ) + ) + (set_local $2 + (i64.reinterpret/f64 + (get_local $13) + ) + ) + (set_local $24 + (i32.wrap/i64 + (i64.shr_u + (get_local $2) + (i64.const 32) + ) + ) + ) + (set_local $38 + (i32.wrap/i64 + (get_local $2) + ) + ) + (if + (i32.ge_s + (get_local $24) + (i32.const 1083179008) + ) + (block + (if + (i32.ne + (i32.or + (i32.sub + (get_local $24) + (i32.const 1083179008) + ) + (get_local $38) + ) + (i32.const 0) + ) + (return + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + ) + ) + (if + (f64.gt + (f64.add + (get_local $18) + (f64.const 8.008566259537294e-17) + ) + (f64.sub + (get_local $13) + (get_local $17) + ) + ) + (return + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1.e+300) + ) + (f64.const 1.e+300) + ) + ) + ) + ) + (if + (i32.ge_s + (i32.and + (get_local $24) + (i32.const 2147483647) + ) + (i32.const 1083231232) + ) + (block + (if + (i32.ne + (i32.or + (i32.sub + (get_local $24) + (i32.const -1064252416) + ) + (get_local $38) + ) + (i32.const 0) + ) + (return + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + ) + ) + (if + (f64.le + (get_local $18) + (f64.sub + (get_local $13) + (get_local $17) + ) + ) + (return + (f64.mul + (f64.mul + (get_local $14) + (f64.const 1e-300) + ) + (f64.const 1e-300) + ) + ) + ) + ) + ) + ) + (set_local $38 + (i32.and + (get_local $24) + (i32.const 2147483647) + ) + ) + (set_local $11 + (i32.sub + (i32.shr_s + (get_local $38) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (set_local $25 + (i32.const 0) + ) + (if + (i32.gt_s + (get_local $38) + (i32.const 1071644672) + ) + (block + (set_local $25 + (i32.add + (get_local $24) + (i32.shr_s + (i32.const 1048576) + (i32.add + (get_local $11) + (i32.const 1) + ) + ) + ) + ) + (set_local $11 + (i32.sub + (i32.shr_s + (i32.and + (get_local $25) + (i32.const 2147483647) + ) + (i32.const 20) + ) + (i32.const 1023) + ) + ) + (set_local $20 + (f64.const 0) + ) + (set_local $20 + (f64.reinterpret/i64 + (i64.shl + (i64.extend_u/i32 + (i32.and + (get_local $25) + (i32.xor + (i32.shr_s + (i32.const 1048575) + (get_local $11) + ) + (i32.const -1) + ) + ) + ) + (i64.const 32) + ) + ) + ) + (set_local $25 + (i32.shr_s + (i32.or + (i32.and + (get_local $25) + (i32.const 1048575) + ) + (i32.const 1048576) + ) + (i32.sub + (i32.const 20) + (get_local $11) + ) + ) + ) + (if + (i32.lt_s + (get_local $24) + (i32.const 0) + ) + (set_local $25 + (i32.sub + (i32.const 0) + (get_local $25) + ) + ) + ) + (set_local $17 + (f64.sub + (get_local $17) + (get_local $20) + ) + ) + ) + ) + (set_local $20 + (f64.add + (get_local $18) + (get_local $17) + ) + ) + (set_local $20 + (f64.reinterpret/i64 + (i64.and + (i64.reinterpret/f64 + (get_local $20) + ) + (i64.const -4294967296) + ) + ) + ) + (set_local $21 + (f64.mul + (get_local $20) + (f64.const 0.6931471824645996) + ) + ) + (set_local $22 + (f64.add + (f64.mul + (f64.sub + (get_local $18) + (f64.sub + (get_local $20) + (get_local $17) + ) + ) + (f64.const 0.6931471805599453) + ) + (f64.mul + (get_local $20) + (f64.const -1.904654299957768e-09) + ) + ) + ) + (set_local $13 + (f64.add + (get_local $21) + (get_local $22) + ) + ) + (set_local $23 + (f64.sub + (get_local $22) + (f64.sub + (get_local $13) + (get_local $21) + ) + ) + ) + (set_local $20 + (f64.mul + (get_local $13) + (get_local $13) + ) + ) + (set_local $15 + (f64.sub + (get_local $13) + (f64.mul + (get_local $20) + (f64.add + (f64.const 0.16666666666666602) + (f64.mul + (get_local $20) + (f64.add + (f64.const -2.7777777777015593e-03) + (f64.mul + (get_local $20) + (f64.add + (f64.const 6.613756321437934e-05) + (f64.mul + (get_local $20) + (f64.add + (f64.const -1.6533902205465252e-06) + (f64.mul + (get_local $20) + (f64.const 4.1381367970572385e-08) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (set_local $19 + (f64.sub + (f64.div + (f64.mul + (get_local $13) + (get_local $15) + ) + (f64.sub + (get_local $15) + (f64.const 2) + ) + ) + (f64.add + (get_local $23) + (f64.mul + (get_local $13) + (get_local $23) + ) + ) + ) + ) + (set_local $13 + (f64.sub + (f64.const 1) + (f64.sub + (get_local $19) + (get_local $13) + ) + ) + ) + (set_local $24 + (i32.wrap/i64 + (i64.shr_u + (i64.reinterpret/f64 + (get_local $13) + ) + (i64.const 32) + ) + ) + ) + (set_local $24 + (i32.add + (get_local $24) + (i32.shl + (get_local $25) + (i32.const 20) + ) + ) + ) + (if + (i32.le_s + (i32.shr_s + (get_local $24) + (i32.const 20) + ) + (i32.const 0) + ) + (set_local $13 + (call $~lib/math/NativeMath.scalbn + (get_local $13) + (get_local $25) + ) + ) + (set_local $13 + (f64.reinterpret/i64 + (i64.or + (i64.and + (i64.reinterpret/f64 + (get_local $13) + ) + (i64.const 4294967295) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $24) + ) + (i64.const 32) + ) + ) + ) + ) + ) + (return + (f64.mul + (get_local $14) + (get_local $13) + ) + ) + ) + (func $std/operator-overloading/Tester.pow (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (return + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.trunc_s/f64 + (call $~lib/math/NativeMath.pow + (f64.convert_s/i32 + (i32.load + (get_local $0) + ) + ) + (f64.convert_s/i32 + (i32.load + (get_local $1) + ) + ) + ) + ) + (i32.trunc_s/f64 + (call $~lib/math/NativeMath.pow + (f64.convert_s/i32 + (i32.load offset=4 + (get_local $0) + ) + ) + (f64.convert_s/i32 + (i32.load offset=4 + (get_local $1) + ) + ) + ) + ) + ) + ) + ) + (func $std/operator-overloading/Tester.and (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (return (call $std/operator-overloading/Tester#constructor (i32.const 0) @@ -336,7 +2083,7 @@ ) ) ) - (func $std/operator-overloading/Tester.or (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.or (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (return (call $std/operator-overloading/Tester#constructor (i32.const 0) @@ -359,7 +2106,7 @@ ) ) ) - (func $std/operator-overloading/Tester.xor (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.xor (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (return (call $std/operator-overloading/Tester#constructor (i32.const 0) @@ -382,7 +2129,7 @@ ) ) ) - (func $std/operator-overloading/Tester.equals (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.equals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -411,7 +2158,7 @@ ) ) ) - (func $std/operator-overloading/Tester.notEquals (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.notEquals (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -440,7 +2187,7 @@ ) ) ) - (func $std/operator-overloading/Tester.greater (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.greater (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -469,7 +2216,7 @@ ) ) ) - (func $std/operator-overloading/Tester.greaterEquals (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.greaterEquals (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -498,7 +2245,7 @@ ) ) ) - (func $std/operator-overloading/Tester.less (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.less (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -527,7 +2274,7 @@ ) ) ) - (func $std/operator-overloading/Tester.lessEquals (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester.lessEquals (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (return (i32.and @@ -556,8 +2303,67 @@ ) ) ) - (func $start (; 17 ;) (type $v) + (func $std/operator-overloading/TesterInlineStatic#constructor (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (block + ) + (tee_local $0 + (if (result i32) + (get_local $0) + (get_local $0) + (tee_local $0 + (block (result i32) + (set_local $3 + (call $~lib/allocator/arena/allocate_memory + (i32.const 8) + ) + ) + (i32.store + (get_local $3) + (get_local $1) + ) + (i32.store offset=4 + (get_local $3) + (get_local $2) + ) + (get_local $3) + ) + ) + ) + ) + ) + (func $std/operator-overloading/TesterInlineInstance#constructor (; 21 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (block + ) + (tee_local $0 + (if (result i32) + (get_local $0) + (get_local $0) + (tee_local $0 + (block (result i32) + (set_local $3 + (call $~lib/allocator/arena/allocate_memory + (i32.const 8) + ) + ) + (i32.store + (get_local $3) + (get_local $1) + ) + (i32.store offset=4 + (get_local $3) + (get_local $2) + ) + (get_local $3) + ) + ) + ) + ) + ) + (func $start (; 22 ;) (type $v) (local $0 i32) + (local $1 i32) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -620,7 +2426,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 82) + (i32.const 87) (i32.const 0) ) (unreachable) @@ -673,7 +2479,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 88) + (i32.const 93) (i32.const 0) ) (unreachable) @@ -726,7 +2532,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 94) + (i32.const 99) (i32.const 0) ) (unreachable) @@ -779,7 +2585,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 100) + (i32.const 105) (i32.const 0) ) (unreachable) @@ -832,7 +2638,60 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 106) + (i32.const 111) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/p1 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/p2 + (call $std/operator-overloading/Tester#constructor + (i32.const 0) + (i32.const 4) + (i32.const 5) + ) + ) + (set_global $std/operator-overloading/p + (call $std/operator-overloading/Tester.pow + (get_global $std/operator-overloading/p1) + (get_global $std/operator-overloading/p2) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $0 + (i32.eq + (i32.load + (get_global $std/operator-overloading/p) + ) + (i32.const 16) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/p) + ) + (i32.const 243) + ) + (get_local $0) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 117) (i32.const 0) ) (unreachable) @@ -885,7 +2744,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 112) + (i32.const 123) (i32.const 0) ) (unreachable) @@ -938,7 +2797,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 118) + (i32.const 129) (i32.const 0) ) (unreachable) @@ -991,7 +2850,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 124) + (i32.const 135) (i32.const 0) ) (unreachable) @@ -1028,7 +2887,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 130) + (i32.const 141) (i32.const 0) ) (unreachable) @@ -1065,7 +2924,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 136) + (i32.const 147) (i32.const 0) ) (unreachable) @@ -1088,7 +2947,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 140) + (i32.const 151) (i32.const 0) ) (unreachable) @@ -1111,7 +2970,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 144) + (i32.const 155) (i32.const 0) ) (unreachable) @@ -1148,7 +3007,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 150) + (i32.const 161) (i32.const 0) ) (unreachable) @@ -1185,7 +3044,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 156) + (i32.const 167) (i32.const 0) ) (unreachable) @@ -1222,7 +3081,7 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 162) + (i32.const 173) (i32.const 0) ) (unreachable) @@ -1259,7 +3118,163 @@ (call $abort (i32.const 0) (i32.const 4) - (i32.const 168) + (i32.const 179) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/ais1 + (call $std/operator-overloading/TesterInlineStatic#constructor + (i32.const 0) + (i32.const 1) + (i32.const 2) + ) + ) + (set_global $std/operator-overloading/ais2 + (call $std/operator-overloading/TesterInlineStatic#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/ais + (block $std/operator-overloading/TesterInlineStatic.add|inlined.0 (result i32) + (set_local $0 + (get_global $std/operator-overloading/ais1) + ) + (set_local $1 + (get_global $std/operator-overloading/ais2) + ) + (br $std/operator-overloading/TesterInlineStatic.add|inlined.0 + (call $std/operator-overloading/TesterInlineStatic#constructor + (i32.const 0) + (i32.add + (i32.load + (get_local $0) + ) + (i32.load + (get_local $1) + ) + ) + (i32.add + (i32.load offset=4 + (get_local $0) + ) + (i32.load offset=4 + (get_local $1) + ) + ) + ) + ) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $1 + (i32.eq + (i32.load + (get_global $std/operator-overloading/ais) + ) + (i32.const 3) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/ais) + ) + (i32.const 5) + ) + (get_local $1) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 193) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/operator-overloading/aii1 + (call $std/operator-overloading/TesterInlineInstance#constructor + (i32.const 0) + (i32.const 1) + (i32.const 2) + ) + ) + (set_global $std/operator-overloading/aii2 + (call $std/operator-overloading/TesterInlineInstance#constructor + (i32.const 0) + (i32.const 2) + (i32.const 3) + ) + ) + (set_global $std/operator-overloading/aii + (block $std/operator-overloading/TesterInlineInstance#add|inlined.0 (result i32) + (set_local $1 + (get_global $std/operator-overloading/aii1) + ) + (set_local $0 + (get_global $std/operator-overloading/aii2) + ) + (br $std/operator-overloading/TesterInlineInstance#add|inlined.0 + (call $std/operator-overloading/TesterInlineInstance#constructor + (i32.const 0) + (i32.add + (i32.load + (get_local $1) + ) + (i32.load + (get_local $0) + ) + ) + (i32.add + (i32.load offset=4 + (get_local $1) + ) + (i32.load offset=4 + (get_local $0) + ) + ) + ) + ) + ) + ) + (if + (i32.eqz + (i32.and + (if (result i32) + (tee_local $0 + (i32.eq + (i32.load + (get_global $std/operator-overloading/aii) + ) + (i32.const 3) + ) + ) + (i32.eq + (i32.load offset=4 + (get_global $std/operator-overloading/aii) + ) + (i32.const 5) + ) + (get_local $0) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 207) (i32.const 0) ) (unreachable) diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index a5c379fd..15ed20da 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -3,8 +3,6 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) - (type $iiv (func (param i32 i32))) - (type $iv (func (param i32))) (type $iiI (func (param i32 i32) (result i64))) (type $iiIv (func (param i32 i32 i64))) (type $iif (func (param i32 i32) (result f32))) @@ -15,37 +13,53 @@ (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 192)) + (global $HEAP_BASE i32 (i32.const 272)) (memory $0 1) - (data (i32.const 8) "\14\00\00\00\02\00\00\00\02\00\00\00\01\00\00\00\02") - (data (i32.const 32) ",\00\00\00\02\00\00\00\02\00\00\00\03\00\00\00\00\00\00\00\04") - (data (i32.const 64) "L\00\00\00\02\00\00\00\02\00\00\00\00\00\c0?\00\00 @") - (data (i32.const 88) "d\00\00\00\02\00\00\00\02") - (data (i32.const 106) "\f4?\00\00\00\00\00\00\02@") - (data (i32.const 116) "\13\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 160) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 8) "\10\00\00\00\02\00\00\00\08\00\00\00\00\00\00\00\01\00\00\00\02") + (data (i32.const 32) "(\00\00\00\02\00\00\00\10\00\00\00\00\00\00\00\03\00\00\00\00\00\00\00\04") + (data (i32.const 72) "P\00\00\00\02\00\00\00\08") + (data (i32.const 90) "\c0?\00\00 @") + (data (i32.const 96) "h\00\00\00\02\00\00\00\10") + (data (i32.const 118) "\f4?\00\00\00\00\00\00\02@") + (data (i32.const 136) "\13\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 180) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 212) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") (export "memory" (memory $0)) (start $start) (func $~lib/array/Array#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32) - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) (func $~lib/array/Array#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) ) ) - (unreachable) - ) - (i32.load - (i32.add - (i32.load - (get_local $0) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) + (unreachable) + ) + ) + (i32.load offset=8 + (i32.add + (get_local $2) (i32.shl (get_local $1) (i32.const 2) @@ -53,7 +67,354 @@ ) ) ) - (func $~lib/allocator/arena/allocate_memory (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32) + (i32.shl + (i32.const 1) + (i32.sub + (i32.const 32) + (i32.clz + (i32.add + (get_local $0) + (i32.const 7) + ) + ) + ) + ) + ) + (func $~lib/memory/set_memory (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i64) + (local $4 i32) + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (tee_local $0 + (i32.add + (get_local $0) + (tee_local $4 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + ) + ) + (tee_local $1 + (i32.mul + (get_local $1) + (i32.const 16843009) + ) + ) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (tee_local $2 + (i32.and + (i32.sub + (get_local $2) + (get_local $4) + ) + (i32.const -4) + ) + ) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $1) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $1) + ) + (set_local $0 + (i32.add + (get_local $0) + (tee_local $4 + (i32.add + (i32.and + (get_local $0) + (i32.const 4) + ) + (i32.const 24) + ) + ) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $4) + ) + ) + (set_local $3 + (i64.or + (i64.extend_u/i32 + (get_local $1) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $1) + ) + (i64.const 32) + ) + ) + ) + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (i64.store + (get_local $0) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $3) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $3) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + (br $continue|0) + ) + ) + ) + ) + (func $~lib/allocator/arena/allocate_memory (; 5 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -142,7 +503,36 @@ ) (i32.const 0) ) - (func $~lib/memory/copy_memory (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/arraybuffer/allocUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (if + (i32.gt_u + (get_local $0) + (i32.const 1073741816) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 22) + (i32.const 2) + ) + (unreachable) + ) + ) + (i32.store + (tee_local $1 + (call $~lib/allocator/arena/allocate_memory + (call $~lib/internal/arraybuffer/computeSize + (get_local $0) + ) + ) + ) + (get_local $0) + ) + (get_local $1) + ) + (func $~lib/memory/copy_memory (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (loop $continue|0 @@ -1718,7 +2108,7 @@ ) ) ) - (func $~lib/memory/move_memory (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/move_memory (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (if (i32.eq @@ -2008,139 +2398,226 @@ ) ) ) - (func $~lib/allocator/arena/free_memory (; 6 ;) (type $iv) (param $0 i32) - (nop) - ) - (func $~lib/array/Array#__grow (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/internal/arraybuffer/reallocUnsafe (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - (local $4 i32) - (set_local $2 - (i32.load - (get_local $0) - ) - ) (if - (i32.le_s + (i32.gt_s (get_local $1) - (tee_local $4 - (i32.load offset=4 + (tee_local $2 + (i32.load (get_local $0) ) ) ) + (block + (if + (i32.gt_s + (get_local $1) + (i32.const 1073741816) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 32) + (i32.const 4) + ) + (unreachable) + ) + ) + (if + (i32.le_s + (get_local $1) + (i32.sub + (call $~lib/internal/arraybuffer/computeSize + (get_local $2) + ) + (i32.const 8) + ) + ) + (block + (i32.store + (get_local $0) + (get_local $1) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + ) + (block + (call $~lib/memory/move_memory + (i32.add + (tee_local $3 + (call $~lib/internal/arraybuffer/allocUnsafe + (get_local $1) + ) + ) + (i32.const 8) + ) + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $3) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + (return + (get_local $3) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $1) + (get_local $2) + ) + (block + (if + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 56) + (i32.const 4) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (get_local $1) + ) + ) + ) + ) + (get_local $0) + ) + (func $~lib/array/Array#__set (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.load + (tee_local $3 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (tee_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (i32.store offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (get_local $2) + ) + ) + (func $~lib/array/Array#__get (; 11 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) + (local $2 i32) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 3) + ) + ) (block (call $abort (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) (unreachable) ) ) - (set_local $3 - (call $~lib/allocator/arena/allocate_memory - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $3) - (get_local $2) - (i32.shl - (get_local $4) - (i32.const 2) - ) - ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) - ) - ) - (i32.store - (get_local $0) - (get_local $3) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) - ) - (func $~lib/array/Array#__set (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - (local $4 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (if - (i32.ge_s - (get_local $1) - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $3 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $3) - ) - ) - ) - ) - (i32.store + (i64.load offset=8 (i32.add - (i32.load - (get_local $0) - ) - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - (get_local $2) - ) - ) - (func $~lib/array/Array#__get (; 9 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (i64.load - (i32.add - (i32.load - (get_local $0) - ) + (get_local $2) (i32.shl (get_local $1) (i32.const 3) @@ -2148,189 +2625,168 @@ ) ) ) - (func $~lib/array/Array#__grow (; 10 ;) (type $iiv) (param $0 i32) (param $1 i32) - (local $2 i32) + (func $~lib/array/Array#__set (; 12 ;) (type $iiIv) (param $0 i32) (param $1 i32) (param $2 i64) (local $3 i32) - (local $4 i32) - (set_local $2 - (i32.load - (get_local $0) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.load + (tee_local $3 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 3) + ) + ) + (block + (if + (i32.ge_u + (get_local $1) + (i32.const 134217727) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (tee_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 3) + ) + ) + ) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) ) ) + (i64.store offset=8 + (i32.add + (get_local $3) + (i32.shl + (get_local $1) + (i32.const 3) + ) + ) + (get_local $2) + ) + ) + (func $~lib/array/Array#__get (; 13 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) + (local $2 i32) (if - (i32.le_s + (i32.ge_u (get_local $1) - (tee_local $4 - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) ) + (i32.const 2) ) ) (block (call $abort (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) (unreachable) ) ) - (set_local $3 - (call $~lib/allocator/arena/allocate_memory + (f32.load offset=8 + (i32.add + (get_local $2) (i32.shl (get_local $1) - (i32.const 3) + (i32.const 2) ) ) ) + ) + (func $~lib/array/Array#__set (; 14 ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) + (local $3 i32) (if - (get_local $2) + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.load + (tee_local $3 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) (block - (call $~lib/memory/move_memory - (get_local $3) - (get_local $2) - (i32.shl - (get_local $4) - (i32.const 3) + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) ) - ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) - ) - ) - (i32.store - (get_local $0) - (get_local $3) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) - ) - (func $~lib/array/Array#__set (; 11 ;) (type $iiIv) (param $0 i32) (param $1 i32) (param $2 i64) - (local $3 i32) - (local $4 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (if - (i32.ge_s - (get_local $1) - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) ) + (unreachable) ) + ) + (i32.store + (get_local $0) (tee_local $3 - (i32.shl + (call $~lib/internal/arraybuffer/reallocUnsafe (get_local $3) - (i32.const 1) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) ) ) - (i32.gt_s - (get_local $4) - (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) ) ) ) ) - (i64.store + (f32.store offset=8 (i32.add - (i32.load - (get_local $0) - ) - (i32.shl - (get_local $1) - (i32.const 3) - ) - ) - (get_local $2) - ) - ) - (func $~lib/array/Array#__get (; 12 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (f32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.shl - (get_local $1) - (i32.const 2) - ) - ) - ) - ) - (func $~lib/array/Array#__set (; 13 ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) - (local $3 i32) - (local $4 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (if - (i32.ge_s - (get_local $1) - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $3 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $3) - ) - ) - ) - ) - (f32.store - (i32.add - (i32.load - (get_local $0) - ) + (get_local $3) (i32.shl (get_local $1) (i32.const 2) @@ -2339,21 +2795,35 @@ (get_local $2) ) ) - (func $~lib/array/Array#__get (; 14 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (func $~lib/array/Array#__get (; 15 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (local $2 i32) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (tee_local $2 + (i32.load + (get_local $0) + ) + ) + ) + (i32.const 3) ) ) - (unreachable) - ) - (f64.load - (i32.add - (i32.load - (get_local $0) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) + (unreachable) + ) + ) + (f64.load offset=8 + (i32.add + (get_local $2) (i32.shl (get_local $1) (i32.const 3) @@ -2361,52 +2831,65 @@ ) ) ) - (func $~lib/array/Array#__set (; 15 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) + (func $~lib/array/Array#__set (; 16 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) (local $3 i32) - (local $4 i32) (if - (i32.lt_s + (i32.ge_u (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (if - (i32.ge_s - (get_local $1) - (tee_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) + (i32.shr_u + (i32.load + (tee_local $3 + (i32.load + (get_local $0) + ) ) ) - (tee_local $3 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $3) - ) + (i32.const 3) ) ) - ) - (f64.store - (i32.add - (i32.load + (block + (if + (i32.ge_u + (get_local $1) + (i32.const 134217727) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (i32.store (get_local $0) + (tee_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 3) + ) + ) + ) ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (f64.store offset=8 + (i32.add + (get_local $3) (i32.shl (get_local $1) (i32.const 3) @@ -2415,7 +2898,7 @@ (get_local $2) ) ) - (func $start (; 16 ;) (type $v) + (func $start (; 17 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -2438,7 +2921,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 8) (i32.const 0) ) @@ -2456,7 +2939,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 9) (i32.const 0) ) @@ -2474,7 +2957,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 10) (i32.const 0) ) @@ -2497,7 +2980,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 12) (i32.const 0) ) @@ -2514,7 +2997,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 14) (i32.const 0) ) @@ -2532,7 +3015,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 15) (i32.const 0) ) @@ -2550,7 +3033,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 16) (i32.const 0) ) @@ -2573,7 +3056,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 18) (i32.const 0) ) @@ -2583,14 +3066,14 @@ (if (i32.ne (call $~lib/array/Array#get:length - (i32.const 64) + (i32.const 72) ) (i32.const 2) ) (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 20) (i32.const 0) ) @@ -2600,7 +3083,7 @@ (if (f32.ne (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 0) ) (f32.const 1.5) @@ -2608,7 +3091,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 21) (i32.const 0) ) @@ -2618,7 +3101,7 @@ (if (f32.ne (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 1) ) (f32.const 2.5) @@ -2626,7 +3109,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 22) (i32.const 0) ) @@ -2634,14 +3117,14 @@ ) ) (call $~lib/array/Array#__set - (i32.const 64) + (i32.const 72) (i32.const 0) (f32.const 2.5) ) (if (f32.ne (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 0) ) (f32.const 2.5) @@ -2649,7 +3132,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 24) (i32.const 0) ) @@ -2659,14 +3142,14 @@ (if (i32.ne (call $~lib/array/Array#get:length - (i32.const 88) + (i32.const 96) ) (i32.const 2) ) (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 26) (i32.const 0) ) @@ -2676,7 +3159,7 @@ (if (f64.ne (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 0) ) (f64.const 1.25) @@ -2684,7 +3167,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 27) (i32.const 0) ) @@ -2694,7 +3177,7 @@ (if (f64.ne (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 1) ) (f64.const 2.25) @@ -2702,7 +3185,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 28) (i32.const 0) ) @@ -2710,14 +3193,14 @@ ) ) (call $~lib/array/Array#__set - (i32.const 88) + (i32.const 96) (i32.const 0) (f64.const 2.25) ) (if (f64.ne (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 0) ) (f64.const 2.25) @@ -2725,7 +3208,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 30) (i32.const 0) ) diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index bf08ad1d..4c51b1b4 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -7,8 +7,6 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) - (type $iiv (func (param i32 i32))) - (type $iv (func (param i32))) (type $iiI (func (param i32 i32) (result i64))) (type $iiIv (func (param i32 i32 i64))) (type $iif (func (param i32 i32) (result f32))) @@ -25,50 +23,452 @@ (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) (global $std/static-array/i i32 (i32.const 8)) (global $std/static-array/I i32 (i32.const 32)) - (global $std/static-array/f i32 (i32.const 64)) - (global $std/static-array/F i32 (i32.const 88)) - (global $HEAP_BASE i32 (i32.const 192)) + (global $std/static-array/f i32 (i32.const 72)) + (global $std/static-array/F i32 (i32.const 96)) + (global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8)) + (global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816)) + (global $HEAP_BASE i32 (i32.const 272)) (memory $0 1) - (data (i32.const 8) "\14\00\00\00\02\00\00\00\02\00\00\00\01\00\00\00\02\00\00\00") - (data (i32.const 32) ",\00\00\00\02\00\00\00\02\00\00\00\03\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00") - (data (i32.const 64) "L\00\00\00\02\00\00\00\02\00\00\00\00\00\c0?\00\00 @") - (data (i32.const 88) "d\00\00\00\02\00\00\00\02\00\00\00\00\00\00\00\00\00\f4?\00\00\00\00\00\00\02@") - (data (i32.const 116) "\13\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 160) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 8) "\10\00\00\00\02\00\00\00\08\00\00\00\00\00\00\00\01\00\00\00\02\00\00\00") + (data (i32.const 32) "(\00\00\00\02\00\00\00\10\00\00\00\00\00\00\00\03\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data (i32.const 72) "P\00\00\00\02\00\00\00\08\00\00\00\00\00\00\00\00\00\c0?\00\00 @") + (data (i32.const 96) "h\00\00\00\02\00\00\00\10\00\00\00\00\00\00\00\00\00\00\00\00\00\f4?\00\00\00\00\00\00\02@\00\00\00\00\00\00\00\00") + (data (i32.const 136) "\13\00\00\00s\00t\00d\00/\00s\00t\00a\00t\00i\00c\00-\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 180) "\0d\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 212) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") (export "memory" (memory $0)) (start $start) (func $~lib/array/Array#get:length (; 1 ;) (type $ii) (param $0 i32) (result i32) (return - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) ) (func $~lib/array/Array#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) (if (i32.ge_u (get_local $1) - (i32.load offset=4 - (get_local $0) - ) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 64) + (i32.const 37) + ) + (unreachable) ) - (unreachable) ) (return - (i32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result i32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (i32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) ) ) ) ) ) - (func $~lib/allocator/arena/allocate_memory (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32) + (return + (i32.shl + (i32.const 1) + (i32.sub + (i32.const 32) + (i32.clz + (i32.sub + (i32.add + (get_local $0) + (i32.const 8) + ) + (i32.const 1) + ) + ) + ) + ) + ) + ) + (func $~lib/memory/set_memory (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i64) + (if + (i32.eqz + (get_local $2) + ) + (return) + ) + (i32.store8 + (get_local $0) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 1) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 2) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 1) + ) + (get_local $1) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 2) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 3) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 6) + ) + (return) + ) + (i32.store8 + (i32.add + (get_local $0) + (i32.const 3) + ) + (get_local $1) + ) + (i32.store8 + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $1) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (set_local $3 + (i32.and + (i32.sub + (i32.const 0) + (get_local $0) + ) + (i32.const 3) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $3) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) + ) + (set_local $2 + (i32.and + (get_local $2) + (i32.const -4) + ) + ) + (set_local $4 + (i32.mul + (i32.div_u + (i32.const -1) + (i32.const 255) + ) + (get_local $1) + ) + ) + (i32.store + (get_local $0) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 4) + ) + (get_local $4) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 8) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 4) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 12) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 8) + ) + (get_local $4) + ) + (if + (i32.le_u + (get_local $2) + (i32.const 24) + ) + (return) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 12) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 20) + ) + (get_local $4) + ) + (i32.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 28) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 24) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 20) + ) + (get_local $4) + ) + (i32.store + (i32.sub + (i32.add + (get_local $0) + (get_local $2) + ) + (i32.const 16) + ) + (get_local $4) + ) + (set_local $3 + (i32.add + (i32.const 24) + (i32.and + (get_local $0) + (i32.const 4) + ) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (get_local $3) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (get_local $3) + ) + ) + (set_local $5 + (i64.or + (i64.extend_u/i32 + (get_local $4) + ) + (i64.shl + (i64.extend_u/i32 + (get_local $4) + ) + (i64.const 32) + ) + ) + ) + (block $break|0 + (loop $continue|0 + (if + (i32.ge_u + (get_local $2) + (i32.const 32) + ) + (block + (block + (i64.store + (get_local $0) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 16) + ) + (get_local $5) + ) + (i64.store + (i32.add + (get_local $0) + (i32.const 24) + ) + (get_local $5) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 32) + ) + ) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 32) + ) + ) + ) + (br $continue|0) + ) + ) + ) + ) + ) + (func $~lib/allocator/arena/allocate_memory (; 5 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -178,7 +578,41 @@ (i32.const 0) ) ) - (func $~lib/memory/copy_memory (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/arraybuffer/allocUnsafe (; 6 ;) (type $ii) (param $0 i32) (result i32) + (local $1 i32) + (if + (i32.eqz + (i32.le_u + (get_local $0) + (i32.const 1073741816) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 22) + (i32.const 2) + ) + (unreachable) + ) + ) + (set_local $1 + (call $~lib/allocator/arena/allocate_memory + (call $~lib/internal/arraybuffer/computeSize + (get_local $0) + ) + ) + ) + (i32.store + (get_local $1) + (get_local $0) + ) + (return + (get_local $1) + ) + ) + (func $~lib/memory/copy_memory (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1981,7 +2415,7 @@ ) ) ) - (func $~lib/memory/move_memory (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/move_memory (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (if (i32.eq @@ -2304,582 +2738,677 @@ ) ) ) - (func $~lib/allocator/arena/free_memory (; 6 ;) (type $iv) (param $0 i32) - ) - (func $~lib/array/Array#__grow (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/internal/arraybuffer/reallocUnsafe (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - (local $4 i32) (set_local $2 (i32.load (get_local $0) ) ) - (set_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) (if - (i32.eqz - (i32.gt_s - (get_local $1) - (get_local $3) - ) + (i32.gt_s + (get_local $1) + (get_local $2) ) (block - (call $abort - (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) - ) - (unreachable) - ) - ) - (set_local $4 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $4) - (get_local $2) - (i32.mul - (get_local $3) - (i32.const 4) + (if + (i32.eqz + (i32.le_s + (get_local $1) + (i32.const 1073741816) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 32) + (i32.const 4) + ) + (unreachable) ) ) - (call $~lib/allocator/arena/free_memory + (if + (i32.le_s + (get_local $1) + (i32.sub + (call $~lib/internal/arraybuffer/computeSize + (get_local $2) + ) + (i32.const 8) + ) + ) + (block + (i32.store + (get_local $0) + (get_local $1) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + ) + (block + (set_local $3 + (call $~lib/internal/arraybuffer/allocUnsafe + (get_local $1) + ) + ) + (call $~lib/memory/move_memory + (i32.add + (get_local $3) + (i32.const 8) + ) + (i32.add + (get_local $0) + (i32.const 8) + ) + (get_local $2) + ) + (call $~lib/memory/set_memory + (i32.add + (i32.add + (get_local $3) + (i32.const 8) + ) + (get_local $2) + ) + (i32.const 0) + (i32.sub + (get_local $1) + (get_local $2) + ) + ) + (return + (get_local $3) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $1) (get_local $2) ) + (block + (if + (i32.eqz + (i32.ge_s + (get_local $1) + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 212) + (i32.const 56) + (i32.const 4) + ) + (unreachable) + ) + ) + (i32.store + (get_local $0) + (get_local $1) + ) + ) ) ) - (i32.store + (return (get_local $0) - (get_local $4) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) ) ) - (func $~lib/array/Array#__set (; 8 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) + (local $6 i32) + (local $7 i32) (set_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - (if - (i32.ge_s - (get_local $1) - (get_local $3) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $5 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $5) - ) - ) - ) - ) - (i32.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - (get_local $2) - ) - ) - (func $~lib/array/Array#get:length (; 9 ;) (type $ii) (param $0 i32) (result i32) - (return - (i32.load offset=8 - (get_local $0) - ) - ) - ) - (func $~lib/array/Array#__get (; 10 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (return - (i64.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 8) - ) - ) - ) - ) - ) - (func $~lib/array/Array#__grow (; 11 ;) (type $iiv) (param $0 i32) (param $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (set_local $2 (i32.load (get_local $0) ) ) - (set_local $3 + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 2) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $4) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.0 + (set_local $5 + (get_local $3) + ) + (set_local $6 + (get_local $1) + ) + (set_local $7 + (get_local $2) + ) + (i32.store offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $7) + ) + ) + ) + (func $~lib/array/Array#get:length (; 11 ;) (type $ii) (param $0 i32) (result i32) + (return (i32.load offset=4 (get_local $0) ) ) - (if - (i32.eqz - (i32.gt_s - (get_local $1) - (get_local $3) - ) - ) - (block - (call $abort - (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) - ) - (unreachable) - ) - ) - (set_local $4 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 8) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $4) - (get_local $2) - (i32.mul - (get_local $3) - (i32.const 8) - ) - ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) - ) - ) - (i32.store - (get_local $0) - (get_local $4) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) ) - (func $~lib/array/Array#__set (; 12 ;) (type $iiIv) (param $0 i32) (param $1 i32) (param $2 i64) + (func $~lib/array/Array#__get (; 12 ;) (type $iiI) (param $0 i32) (param $1 i32) (result i64) + (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) - (set_local $3 - (i32.load offset=4 - (get_local $0) - ) - ) - (if - (i32.ge_s - (get_local $1) - (get_local $3) - ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $5 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $5) - ) - ) - ) - ) - (i64.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 8) - ) - ) - (get_local $2) - ) - ) - (func $~lib/array/Array#get:length (; 13 ;) (type $ii) (param $0 i32) (result i32) - (return - (i32.load offset=8 - (get_local $0) - ) - ) - ) - (func $~lib/array/Array#__get (; 14 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (return - (f32.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) - ) - ) - ) - ) - ) - (func $~lib/array/Array#__grow (; 15 ;) (type $iiv) (param $0 i32) (param $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) (set_local $2 (i32.load (get_local $0) ) ) (set_local $3 - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 3) ) ) (if - (i32.eqz - (i32.gt_s - (get_local $1) - (get_local $3) - ) + (i32.ge_u + (get_local $1) + (get_local $3) ) (block (call $abort (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) (unreachable) ) ) - (set_local $4 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 4) + (return + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result i64) + (set_local $4 + (get_local $2) ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (i64.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 3) + ) + ) + ) + ) + ) + ) + ) + (func $~lib/array/Array#__set (; 13 ;) (type $iiIv) (param $0 i32) (param $1 i32) (param $2 i64) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i64) + (set_local $3 + (i32.load + (get_local $0) + ) + ) + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 3) ) ) (if - (get_local $2) + (i32.ge_u + (get_local $1) + (get_local $4) + ) (block - (call $~lib/memory/move_memory - (get_local $4) - (get_local $2) - (i32.mul - (get_local $3) - (i32.const 4) + (nop) + (if + (i32.ge_u + (get_local $1) + (i32.const 134217727) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) ) ) - (call $~lib/allocator/arena/free_memory - (get_local $2) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 3) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) ) ) ) - (i32.store - (get_local $0) - (get_local $4) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.0 + (set_local $5 + (get_local $3) + ) + (set_local $6 + (get_local $1) + ) + (set_local $7 + (get_local $2) + ) + (i64.store offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 3) + ) + ) + (get_local $7) + ) ) - (i32.store offset=4 - (get_local $0) - (get_local $1) + ) + (func $~lib/array/Array#get:length (; 14 ;) (type $ii) (param $0 i32) (result i32) + (return + (i32.load offset=4 + (get_local $0) + ) + ) + ) + (func $~lib/array/Array#__get (; 15 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $2 + (i32.load + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 2) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 64) + (i32.const 37) + ) + (unreachable) + ) + ) + (return + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result f32) + (set_local $4 + (get_local $2) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (f32.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) + ) + ) + ) ) ) (func $~lib/array/Array#__set (; 16 ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) (local $3 i32) (local $4 i32) (local $5 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) + (local $6 i32) + (local $7 f32) (set_local $3 - (i32.load offset=4 + (i32.load (get_local $0) ) ) + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 2) + ) + ) (if - (i32.ge_s + (i32.ge_u (get_local $1) + (get_local $4) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $1) + (i32.const 268435454) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 2) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.0 + (set_local $5 (get_local $3) ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $5 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $5) - ) - ) + (set_local $6 + (get_local $1) ) - ) - (f32.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 4) - ) + (set_local $7 + (get_local $2) + ) + (f32.store offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $7) ) - (get_local $2) ) ) (func $~lib/array/Array#get:length (; 17 ;) (type $ii) (param $0 i32) (result i32) (return - (i32.load offset=8 + (i32.load offset=4 (get_local $0) ) ) ) (func $~lib/array/Array#__get (; 18 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) - (if - (i32.ge_u - (get_local $1) - (i32.load offset=4 - (get_local $0) - ) - ) - (unreachable) - ) - (return - (f64.load - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 8) - ) - ) - ) - ) - ) - (func $~lib/array/Array#__grow (; 19 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) (set_local $2 (i32.load (get_local $0) ) ) (set_local $3 - (i32.load offset=4 - (get_local $0) + (i32.shr_u + (i32.load + (get_local $2) + ) + (i32.const 3) ) ) (if - (i32.eqz - (i32.gt_s - (get_local $1) - (get_local $3) - ) + (i32.ge_u + (get_local $1) + (get_local $3) ) (block (call $abort (i32.const 0) - (i32.const 160) - (i32.const 16) - (i32.const 4) + (i32.const 180) + (i32.const 64) + (i32.const 37) ) (unreachable) ) ) - (set_local $4 - (call $~lib/allocator/arena/allocate_memory - (i32.mul - (get_local $1) - (i32.const 8) - ) - ) - ) - (if - (get_local $2) - (block - (call $~lib/memory/move_memory - (get_local $4) + (return + (block $~lib/internal/arraybuffer/loadUnsafe|inlined.0 (result f64) + (set_local $4 (get_local $2) - (i32.mul - (get_local $3) - (i32.const 8) + ) + (set_local $5 + (get_local $1) + ) + (br $~lib/internal/arraybuffer/loadUnsafe|inlined.0 + (f64.load offset=8 + (i32.add + (get_local $4) + (i32.shl + (get_local $5) + (i32.const 3) + ) + ) ) ) - (call $~lib/allocator/arena/free_memory - (get_local $2) - ) ) ) - (i32.store - (get_local $0) - (get_local $4) - ) - (i32.store offset=4 - (get_local $0) - (get_local $1) - ) ) - (func $~lib/array/Array#__set (; 20 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) + (func $~lib/array/Array#__set (; 19 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) (local $3 i32) (local $4 i32) (local $5 i32) - (if - (i32.lt_s - (get_local $1) - (i32.const 0) - ) - (unreachable) - ) + (local $6 i32) + (local $7 f64) (set_local $3 - (i32.load offset=4 + (i32.load (get_local $0) ) ) + (set_local $4 + (i32.shr_u + (i32.load + (get_local $3) + ) + (i32.const 3) + ) + ) (if - (i32.ge_s + (i32.ge_u (get_local $1) + (get_local $4) + ) + (block + (nop) + (if + (i32.ge_u + (get_local $1) + (i32.const 134217727) + ) + (block + (call $abort + (i32.const 0) + (i32.const 180) + (i32.const 75) + (i32.const 41) + ) + (unreachable) + ) + ) + (set_local $3 + (call $~lib/internal/arraybuffer/reallocUnsafe + (get_local $3) + (i32.shl + (i32.add + (get_local $1) + (i32.const 1) + ) + (i32.const 3) + ) + ) + ) + (i32.store + (get_local $0) + (get_local $3) + ) + (i32.store offset=4 + (get_local $0) + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafe|inlined.0 + (set_local $5 (get_local $3) ) - (call $~lib/array/Array#__grow - (get_local $0) - (select - (tee_local $4 - (i32.add - (get_local $1) - (i32.const 1) - ) - ) - (tee_local $5 - (i32.shl - (get_local $3) - (i32.const 1) - ) - ) - (i32.gt_s - (get_local $4) - (get_local $5) - ) - ) + (set_local $6 + (get_local $1) ) - ) - (f64.store - (i32.add - (i32.load - (get_local $0) - ) - (i32.mul - (get_local $1) - (i32.const 8) - ) + (set_local $7 + (get_local $2) + ) + (f64.store offset=8 + (i32.add + (get_local $5) + (i32.shl + (get_local $6) + (i32.const 3) + ) + ) + (get_local $7) ) - (get_local $2) ) ) - (func $start (; 21 ;) (type $v) + (func $start (; 20 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -2907,7 +3436,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 8) (i32.const 0) ) @@ -2927,7 +3456,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 9) (i32.const 0) ) @@ -2947,7 +3476,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 10) (i32.const 0) ) @@ -2972,7 +3501,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 12) (i32.const 0) ) @@ -2991,7 +3520,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 14) (i32.const 0) ) @@ -3011,7 +3540,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 15) (i32.const 0) ) @@ -3031,7 +3560,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 16) (i32.const 0) ) @@ -3056,7 +3585,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 18) (i32.const 0) ) @@ -3067,7 +3596,7 @@ (i32.eqz (i32.eq (call $~lib/array/Array#get:length - (i32.const 64) + (i32.const 72) ) (i32.const 2) ) @@ -3075,7 +3604,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 20) (i32.const 0) ) @@ -3086,7 +3615,7 @@ (i32.eqz (f32.eq (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 0) ) (f32.const 1.5) @@ -3095,7 +3624,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 21) (i32.const 0) ) @@ -3106,7 +3635,7 @@ (i32.eqz (f32.eq (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 1) ) (f32.const 2.5) @@ -3115,7 +3644,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 22) (i32.const 0) ) @@ -3123,7 +3652,7 @@ ) ) (call $~lib/array/Array#__set - (i32.const 64) + (i32.const 72) (i32.const 0) (f32.const 2.5) ) @@ -3131,7 +3660,7 @@ (i32.eqz (f32.eq (call $~lib/array/Array#__get - (i32.const 64) + (i32.const 72) (i32.const 0) ) (f32.const 2.5) @@ -3140,7 +3669,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 24) (i32.const 0) ) @@ -3151,7 +3680,7 @@ (i32.eqz (i32.eq (call $~lib/array/Array#get:length - (i32.const 88) + (i32.const 96) ) (i32.const 2) ) @@ -3159,7 +3688,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 26) (i32.const 0) ) @@ -3170,7 +3699,7 @@ (i32.eqz (f64.eq (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 0) ) (f64.const 1.25) @@ -3179,7 +3708,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 27) (i32.const 0) ) @@ -3190,7 +3719,7 @@ (i32.eqz (f64.eq (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 1) ) (f64.const 2.25) @@ -3199,7 +3728,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 28) (i32.const 0) ) @@ -3207,7 +3736,7 @@ ) ) (call $~lib/array/Array#__set - (i32.const 88) + (i32.const 96) (i32.const 0) (f64.const 2.25) ) @@ -3215,7 +3744,7 @@ (i32.eqz (f64.eq (call $~lib/array/Array#__get - (i32.const 88) + (i32.const 96) (i32.const 0) ) (f64.const 2.25) @@ -3224,7 +3753,7 @@ (block (call $abort (i32.const 0) - (i32.const 116) + (i32.const 136) (i32.const 30) (i32.const 0) ) diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 5194a21c..a535b7d7 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -3725,7 +3725,15 @@ ) (i32.const 1) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 72) + (i32.const 391) + (i32.const 6) + ) + (unreachable) + ) ) (if (i32.and diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index 74b48c58..c7133f22 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -4290,7 +4290,15 @@ ) (i32.const 1) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 72) + (i32.const 391) + (i32.const 6) + ) + (unreachable) + ) ) (if (i32.and diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 551c07be..f75d8a87 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -4,14 +4,17 @@ (type $iii (func (param i32 i32) (result i32))) (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) + (type $iiii (func (param i32 i32 i32) (result i32))) (type $v (func)) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $~lib/allocator/arena/startOffset (mut i32) (i32.const 0)) (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) - (global $HEAP_BASE i32 (i32.const 104)) + (global $std/typedarray/arr (mut i32) (i32.const 0)) + (global $HEAP_BASE i32 (i32.const 164)) (memory $0 1) (data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 44) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 44) "\1b\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 104) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") (export "memory" (memory $0)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -127,7 +130,7 @@ (block (call $abort (i32.const 0) - (i32.const 44) + (i32.const 104) (i32.const 22) (i32.const 2) ) @@ -486,7 +489,15 @@ (get_local $1) (i32.const 1073741816) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (call $~lib/memory/set_memory (i32.add @@ -537,8 +548,13 @@ (get_local $0) ) (func $~lib/internal/typedarray/TypedArray#get:length (; 6 ;) (type $ii) (param $0 i32) (result i32) - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) ) (func $~lib/internal/typedarray/TypedArray#constructor (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) @@ -548,7 +564,15 @@ (get_local $1) (i32.const 536870908) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (call $~lib/memory/set_memory (i32.add @@ -605,8 +629,13 @@ ) (func $~lib/internal/typedarray/TypedArray#get:length (; 8 ;) (type $ii) (param $0 i32) (result i32) (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 1) ) @@ -618,7 +647,15 @@ (get_local $1) (i32.const 268435454) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (call $~lib/memory/set_memory (i32.add @@ -675,8 +712,13 @@ ) (func $~lib/internal/typedarray/TypedArray#get:length (; 10 ;) (type $ii) (param $0 i32) (result i32) (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 2) ) @@ -688,7 +730,15 @@ (get_local $1) (i32.const 134217727) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (call $~lib/memory/set_memory (i32.add @@ -745,8 +795,13 @@ ) (func $~lib/internal/typedarray/TypedArray#get:length (; 12 ;) (type $ii) (param $0 i32) (result i32) (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 3) ) @@ -1308,7 +1363,217 @@ ) ) ) - (func $start (; 14 ;) (type $v) + (func $~lib/internal/typedarray/TypedArray#__set (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (tee_local $3 + (i32.load offset=4 + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 47) + (i32.const 42) + ) + (unreachable) + ) + ) + (i32.store offset=8 + (i32.add + (i32.add + (i32.load + (get_local $0) + ) + (get_local $3) + ) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (get_local $2) + ) + ) + (func $~lib/internal/typedarray/TypedArray#__get (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (if + (i32.ge_u + (get_local $1) + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (tee_local $2 + (i32.load offset=4 + (get_local $0) + ) + ) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 39) + (i32.const 42) + ) + (unreachable) + ) + ) + (i32.load offset=8 + (i32.add + (i32.add + (i32.load + (get_local $0) + ) + (get_local $2) + ) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + ) + ) + (func $~lib/typedarray/Int32Array#subarray (; 16 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (set_local $3 + (get_local $2) + ) + (set_local $4 + (call $~lib/internal/typedarray/TypedArray#get:length + (tee_local $5 + (get_local $0) + ) + ) + ) + (set_local $1 + (if (result i32) + (i32.lt_s + (get_local $1) + (i32.const 0) + ) + (select + (tee_local $2 + (i32.add + (get_local $4) + (get_local $1) + ) + ) + (tee_local $0 + (i32.const 0) + ) + (i32.gt_s + (get_local $2) + (get_local $0) + ) + ) + (select + (tee_local $2 + (get_local $1) + ) + (tee_local $0 + (get_local $4) + ) + (i32.lt_s + (get_local $2) + (get_local $0) + ) + ) + ) + ) + (set_local $3 + (if (result i32) + (i32.lt_s + (get_local $3) + (i32.const 0) + ) + (select + (tee_local $2 + (i32.add + (get_local $4) + (get_local $3) + ) + ) + (tee_local $0 + (get_local $1) + ) + (i32.gt_s + (get_local $2) + (get_local $0) + ) + ) + (select + (tee_local $2 + (select + (tee_local $2 + (get_local $3) + ) + (tee_local $0 + (get_local $4) + ) + (i32.lt_s + (get_local $2) + (get_local $0) + ) + ) + ) + (tee_local $0 + (get_local $1) + ) + (i32.gt_s + (get_local $2) + (get_local $0) + ) + ) + ) + ) + (i32.store + (tee_local $2 + (call $~lib/allocator/arena/allocate_memory + (i32.const 12) + ) + ) + (i32.load + (get_local $5) + ) + ) + (i32.store offset=4 + (get_local $2) + (i32.shl + (get_local $1) + (i32.const 2) + ) + ) + (i32.store offset=8 + (get_local $2) + (i32.shl + (get_local $3) + (i32.const 2) + ) + ) + (get_local $2) + ) + (func $start (; 17 ;) (type $v) (set_global $~lib/allocator/arena/startOffset (i32.and (i32.add @@ -1327,6 +1592,205 @@ (call $std/typedarray/testInstantiate (i32.const 5) ) + (set_global $std/typedarray/arr + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (i32.const 3) + ) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 0) + (i32.const 1) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 1) + (i32.const 2) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 2) + (i32.const 3) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_global $std/typedarray/arr) + ) + (i32.const 3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 74) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.load offset=4 + (get_global $std/typedarray/arr) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 75) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=8 + (get_global $std/typedarray/arr) + ) + (i32.const 12) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 76) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 0) + ) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 77) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 1) + ) + (i32.const 2) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 78) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 2) + ) + (i32.const 3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 79) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/typedarray/arr + (call $~lib/typedarray/Int32Array#subarray + (get_global $std/typedarray/arr) + (i32.const 1) + (i32.const 2) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#get:length + (get_global $std/typedarray/arr) + ) + (i32.const 1) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 82) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=4 + (get_global $std/typedarray/arr) + ) + (i32.const 4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 83) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (i32.load offset=8 + (get_global $std/typedarray/arr) + ) + (i32.const 8) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 84) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.ne + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 0) + ) + (i32.const 2) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 85) + (i32.const 0) + ) + (unreachable) + ) + ) (drop (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0) diff --git a/tests/compiler/std/typedarray.ts b/tests/compiler/std/typedarray.ts index 4a6ba1ca..b7b87a4e 100644 --- a/tests/compiler/std/typedarray.ts +++ b/tests/compiler/std/typedarray.ts @@ -67,6 +67,23 @@ function testInstantiate(len: i32): void { testInstantiate(0); testInstantiate(5); +var arr = new Int32Array(3); +arr[0] = 1; +arr[1] = 2; +arr[2] = 3; +assert(arr.length == 3); +assert(arr.byteOffset == 0); +assert(arr.byteLength == 3 * sizeof()); +assert(arr[0] == 1); +assert(arr[1] == 2); +assert(arr[2] == 3); + +arr = arr.subarray(1, 2); +assert(arr.length == 1); +assert(arr.byteOffset == 1 * sizeof()); +assert(arr.byteLength == 2 * sizeof()); +assert(arr[0] == 2); + import { MAX_BLENGTH } from "internal/arraybuffer"; const MAX_F64LENGTH = MAX_BLENGTH >> alignof(); diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index de00b8d2..41671c66 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -5,6 +5,7 @@ (type $iii (func (param i32 i32) (result i32))) (type $ii (func (param i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) + (type $iiii (func (param i32 i32 i32) (result i32))) (type $v (func)) (import "env" "abort" (func $abort (param i32 i32 i32 i32))) (global $~lib/internal/allocator/AL_BITS i32 (i32.const 3)) @@ -15,11 +16,13 @@ (global $~lib/allocator/arena/offset (mut i32) (i32.const 0)) (global $~lib/internal/arraybuffer/HEADER_SIZE i32 (i32.const 8)) (global $~lib/internal/arraybuffer/MAX_BLENGTH i32 (i32.const 1073741816)) + (global $std/typedarray/arr (mut i32) (i32.const 0)) (global $std/typedarray/MAX_F64LENGTH i32 (i32.const 134217727)) - (global $HEAP_BASE i32 (i32.const 104)) + (global $HEAP_BASE i32 (i32.const 164)) (memory $0 1) (data (i32.const 4) "\11\00\00\00s\00t\00d\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 44) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") + (data (i32.const 44) "\1b\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00t\00y\00p\00e\00d\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 104) "\1c\00\00\00~\00l\00i\00b\00/\00i\00n\00t\00e\00r\00n\00a\00l\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s\00") (export "memory" (memory $0)) (start $start) (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) @@ -163,7 +166,7 @@ (block (call $abort (i32.const 0) - (i32.const 44) + (i32.const 104) (i32.const 22) (i32.const 2) ) @@ -545,7 +548,15 @@ (get_local $1) (i32.const 1073741816) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -611,8 +622,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 6 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 0) ) @@ -629,7 +645,15 @@ (get_local $1) (i32.const 1073741816) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -695,8 +719,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 8 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 0) ) @@ -713,7 +742,15 @@ (get_local $1) (i32.const 536870908) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -779,8 +816,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 10 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 1) ) @@ -797,7 +839,15 @@ (get_local $1) (i32.const 536870908) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -863,8 +913,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 12 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 1) ) @@ -881,7 +936,15 @@ (get_local $1) (i32.const 268435454) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -947,8 +1010,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 14 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 2) ) @@ -965,7 +1033,15 @@ (get_local $1) (i32.const 268435454) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -1031,8 +1107,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 16 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 2) ) @@ -1049,7 +1130,15 @@ (get_local $1) (i32.const 134217727) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -1115,8 +1204,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 18 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 3) ) @@ -1133,7 +1227,15 @@ (get_local $1) (i32.const 134217727) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -1199,8 +1301,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 20 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 3) ) @@ -1217,7 +1324,15 @@ (get_local $1) (i32.const 268435454) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -1283,8 +1398,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 22 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 2) ) @@ -1301,7 +1421,15 @@ (get_local $1) (i32.const 134217727) ) - (unreachable) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 22) + (i32.const 34) + ) + (unreachable) + ) ) (set_local $2 (i32.shl @@ -1367,8 +1495,13 @@ (func $~lib/internal/typedarray/TypedArray#get:length (; 24 ;) (type $ii) (param $0 i32) (result i32) (return (i32.shr_s - (i32.load offset=8 - (get_local $0) + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (i32.load offset=4 + (get_local $0) + ) ) (i32.const 3) ) @@ -2046,7 +2179,281 @@ ) ) ) - (func $start (; 26 ;) (type $v) + (func $~lib/internal/typedarray/TypedArray#__set (; 26 ;) (type $iiiv) (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 $8 i32) + (set_local $3 + (i32.load offset=4 + (get_local $0) + ) + ) + (set_local $4 + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (get_local $3) + ) + (i32.const 2) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $4) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 47) + (i32.const 42) + ) + (unreachable) + ) + ) + (block $~lib/internal/arraybuffer/storeUnsafeWithOffset|inlined.0 + (set_local $5 + (i32.load + (get_local $0) + ) + ) + (set_local $6 + (get_local $1) + ) + (set_local $7 + (get_local $2) + ) + (set_local $8 + (get_local $3) + ) + (i32.store offset=8 + (i32.add + (i32.add + (get_local $5) + (get_local $8) + ) + (i32.shl + (get_local $6) + (i32.const 2) + ) + ) + (get_local $7) + ) + ) + ) + (func $~lib/internal/typedarray/TypedArray#__get (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (set_local $2 + (i32.load offset=4 + (get_local $0) + ) + ) + (set_local $3 + (i32.shr_u + (i32.sub + (i32.load offset=8 + (get_local $0) + ) + (get_local $2) + ) + (i32.const 2) + ) + ) + (if + (i32.ge_u + (get_local $1) + (get_local $3) + ) + (block + (call $abort + (i32.const 0) + (i32.const 44) + (i32.const 39) + (i32.const 42) + ) + (unreachable) + ) + ) + (return + (block $~lib/internal/arraybuffer/loadUnsafeWithOffset|inlined.0 (result i32) + (set_local $4 + (i32.load + (get_local $0) + ) + ) + (set_local $5 + (get_local $1) + ) + (set_local $6 + (get_local $2) + ) + (br $~lib/internal/arraybuffer/loadUnsafeWithOffset|inlined.0 + (i32.load offset=8 + (i32.add + (i32.add + (get_local $4) + (get_local $6) + ) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) + ) + ) + ) + ) + ) + (func $~lib/typedarray/Int32Array#subarray (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (return + (block $~lib/internal/typedarray/TypedArray#subarray|inlined.0 (result i32) + (set_local $3 + (get_local $0) + ) + (set_local $4 + (get_local $1) + ) + (set_local $5 + (get_local $2) + ) + (set_local $6 + (call $~lib/internal/typedarray/TypedArray#get:length + (get_local $3) + ) + ) + (if + (i32.lt_s + (get_local $4) + (i32.const 0) + ) + (set_local $4 + (select + (tee_local $7 + (i32.add + (get_local $6) + (get_local $4) + ) + ) + (tee_local $8 + (i32.const 0) + ) + (i32.gt_s + (get_local $7) + (get_local $8) + ) + ) + ) + (set_local $4 + (select + (tee_local $7 + (get_local $4) + ) + (tee_local $8 + (get_local $6) + ) + (i32.lt_s + (get_local $7) + (get_local $8) + ) + ) + ) + ) + (if + (i32.lt_s + (get_local $5) + (i32.const 0) + ) + (set_local $5 + (select + (tee_local $7 + (i32.add + (get_local $6) + (get_local $5) + ) + ) + (tee_local $8 + (get_local $4) + ) + (i32.gt_s + (get_local $7) + (get_local $8) + ) + ) + ) + (set_local $5 + (select + (tee_local $7 + (select + (tee_local $7 + (get_local $5) + ) + (tee_local $8 + (get_local $6) + ) + (i32.lt_s + (get_local $7) + (get_local $8) + ) + ) + ) + (tee_local $8 + (get_local $4) + ) + (i32.gt_s + (get_local $7) + (get_local $8) + ) + ) + ) + ) + (set_local $7 + (call $~lib/allocator/arena/allocate_memory + (i32.const 12) + ) + ) + (i32.store + (get_local $7) + (i32.load + (get_local $3) + ) + ) + (i32.store offset=4 + (get_local $7) + (i32.shl + (get_local $4) + (i32.const 2) + ) + ) + (i32.store offset=8 + (get_local $7) + (i32.shl + (get_local $5) + (i32.const 2) + ) + ) + (br $~lib/internal/typedarray/TypedArray#subarray|inlined.0 + (get_local $7) + ) + ) + ) + ) + (func $start (; 29 ;) (type $v) (if (i32.eqz (i32.eq @@ -2238,6 +2645,237 @@ (call $std/typedarray/testInstantiate (i32.const 5) ) + (set_global $std/typedarray/arr + (call $~lib/internal/typedarray/TypedArray#constructor + (i32.const 0) + (i32.const 3) + ) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 0) + (i32.const 1) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 1) + (i32.const 2) + ) + (call $~lib/internal/typedarray/TypedArray#__set + (get_global $std/typedarray/arr) + (i32.const 2) + (i32.const 3) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_global $std/typedarray/arr) + ) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 74) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=4 + (get_global $std/typedarray/arr) + ) + (i32.const 0) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 75) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=8 + (get_global $std/typedarray/arr) + ) + (i32.mul + (i32.const 3) + (i32.const 4) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 76) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 0) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 77) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 1) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 78) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 2) + ) + (i32.const 3) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 79) + (i32.const 0) + ) + (unreachable) + ) + ) + (set_global $std/typedarray/arr + (call $~lib/typedarray/Int32Array#subarray + (get_global $std/typedarray/arr) + (i32.const 1) + (i32.const 2) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#get:length + (get_global $std/typedarray/arr) + ) + (i32.const 1) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 82) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=4 + (get_global $std/typedarray/arr) + ) + (i32.mul + (i32.const 1) + (i32.const 4) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 83) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (i32.load offset=8 + (get_global $std/typedarray/arr) + ) + (i32.mul + (i32.const 2) + (i32.const 4) + ) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 84) + (i32.const 0) + ) + (unreachable) + ) + ) + (if + (i32.eqz + (i32.eq + (call $~lib/internal/typedarray/TypedArray#__get + (get_global $std/typedarray/arr) + (i32.const 0) + ) + (i32.const 2) + ) + ) + (block + (call $abort + (i32.const 0) + (i32.const 4) + (i32.const 85) + (i32.const 0) + ) + (unreachable) + ) + ) (drop (call $~lib/internal/typedarray/TypedArray#constructor (i32.const 0)