From 7ce570961a7739cb25433c93ed7c517aa19f3354 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sat, 14 Sep 2019 17:02:22 -0400 Subject: [PATCH 01/47] temp --- package-lock.json | 30 +++++++++++++++++++++++++++--- tests/compiler/interface.json | 5 +++++ tests/compiler/interface.ts | 18 ++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/compiler/interface.json create mode 100644 tests/compiler/interface.ts diff --git a/package-lock.json b/package-lock.json index fccff050c9..1b5308d711 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1077,6 +1077,14 @@ "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } } }, "crypto-browserify": { @@ -2766,6 +2774,14 @@ "requires": { "pify": "^4.0.1", "semver": "^5.6.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } } }, "make-error": { @@ -3700,9 +3716,9 @@ } }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", "dev": true }, "serialize-javascript": { @@ -4227,6 +4243,14 @@ "semver": "^5.3.0", "tslib": "^1.8.0", "tsutils": "^2.29.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } } }, "tsutils": { diff --git a/tests/compiler/interface.json b/tests/compiler/interface.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/interface.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts new file mode 100644 index 0000000000..06ac29338a --- /dev/null +++ b/tests/compiler/interface.ts @@ -0,0 +1,18 @@ + +interface IFoo { + foo(i: i32): i32; +} + +class AFoo implements IFoo { + i: i32 = 41; + + foo(i: i32): i32 { + return this.i + i; + } +} + +let aFoo = new AFoo(); + +function passAnInterface(foo: IFoo): void { + assert(foo.foo(1) == 42); +} \ No newline at end of file From 08f6dfec54f0f609aae62eb26e6086c3592c4d7b Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 18 Sep 2019 12:43:28 -0400 Subject: [PATCH 02/47] compiles --- src/ast.ts | 45 ++++++++++++++ src/compiler.ts | 117 +++++++++++++++++++++++++++++++++--- src/program.ts | 100 ++++++++++++++++++++++++++---- src/resolver.ts | 12 ++-- src/util/collections.ts | 17 ++++++ std/portable/index.d.ts | 4 +- tests/compiler.js | 2 +- tests/compiler/interface.ts | 4 +- 8 files changed, 274 insertions(+), 27 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 6dc0ede3ce..e449f78814 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1063,6 +1063,10 @@ export abstract class Node { // types +interface Comparable { + equals(other: Comparable): bool; +} + export abstract class TypeNode extends Node { // kind varies @@ -1099,6 +1103,15 @@ export abstract class TypeNode extends Node { } return false; } + + abstract equals(node: TypeNode): bool; + + static arrayEquals(node: Comparable[] | null, other: Comparable[] | null): bool { + if (node == null && other == null) return true; + if (node == null || other == null) return false; + if (node.length != other.length) return false; + return node.map((value, i) => value.equals(other[i])).every(x => x); + } } /** Represents a type name. */ @@ -1109,6 +1122,13 @@ export class TypeName extends Node { identifier: IdentifierExpression; /** Next part of the type name or `null` if this is the last part. */ next: TypeName | null; + + equals(node: TypeName): bool { + if (node.identifier.symbol !== this.identifier.symbol) return false; + if (node.next == null && this.next == null) return true; + if (node.next == null || this.next == null) return false; + return this.next.equals(node.next); + } } /** Represents a named type. */ @@ -1119,6 +1139,12 @@ export class NamedTypeNode extends TypeNode { name: TypeName; /** Type argument references. */ typeArguments: TypeNode[] | null; + + equals(node: NamedTypeNode): bool { + if (!this.name.equals(node.name)) return false; + return TypeNode.arrayEquals(this.typeArguments, node.typeArguments); + + } } /** Represents a function type. */ @@ -1131,6 +1157,18 @@ export class FunctionTypeNode extends TypeNode { returnType: TypeNode; /** Explicitly provided this type, if any. */ explicitThisType: NamedTypeNode | null; // can't be a function + + equals(node: FunctionTypeNode): bool { + if (!TypeNode.arrayEquals(this.parameterTypes, node.parameterTypes)) return false; + if (!this.returnType.equals(node.returnType)) return false; + if ((this.explicitThisType == null && node.explicitThisType == null)) return true; + if (this.explicitThisType == null || node.explicitThisType == null) return false; + return true; + } + + get parameterTypes(): TypeNode[] { + return this.parameters.map(param => param.type); + } } /** Represents a type parameter. */ @@ -1143,6 +1181,13 @@ export class TypeParameterNode extends Node { extendsType: NamedTypeNode | null; // can't be a function /** Default type if omitted, if any. */ defaultType: NamedTypeNode | null; // can't be a function + + equals(node: TypeParameterNode): bool { + if (this.name != node.name) return false; + if ((this.extendsType == null && node.extendsType == null)) return true; + if (this.extendsType == null || node.extendsType == null) return false; + return true; + } } /** Represents the kind of a parameter. */ diff --git a/src/compiler.ts b/src/compiler.ts index 3d617dbd9b..da58a9945f 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -307,6 +307,8 @@ export class Compiler extends DiagnosticEmitter { runtimeFeatures: RuntimeFeatures = RuntimeFeatures.NONE; /** Expressions known to have skipped an autorelease. Usually function returns. */ skippedAutoreleases: Set = new Set(); + /** Classes that implement an interface */ + implementers: Class[] = []; /** Compiles a {@link Program} to a {@link Module} using the specified options. */ static compile(program: Program, options: Options | null = null): Module { @@ -447,6 +449,10 @@ export class Compiler extends DiagnosticEmitter { // import memory if requested (default memory is named '0' by Binaryen) if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory); + // set up virtual table + this.compileVirtualTable(); + + // set up function table var functionTable = this.functionTable; module.setFunctionTable(functionTable.length, 0xffffffff, functionTable); @@ -459,6 +465,7 @@ export class Compiler extends DiagnosticEmitter { for (let file of this.program.filesByName.values()) { if (file.source.sourceKind == SourceKind.USER_ENTRY) this.ensureModuleExports(file); } + console.log(functionTable.join(",\n")); return module; } @@ -1305,7 +1312,58 @@ export class Compiler extends DiagnosticEmitter { typesToNativeTypes(instance.additionalLocals), flatten(module, stmts, instance.signature.returnType.toNativeType()) ); + // Virtual Methods + } else if (instance.is( CommonFlags.VIRTUAL)) { + let func: Function = instance; + let signature = func.signature; + let typeRef = this.ensureFunctionType( + signature.parameterTypes, + signature.returnType, + signature.thisType + ); + let loadMethodID = module.i32(signature.id); + // let target = this.compiler.program.instancesByName("virtual"); + let loadClass = module.load( + 4, + false, + module.binary( + BinaryOp.SubI32, + module.local_get(0, NativeType.I32), + module.i32(8) + ), + NativeType.I32 + ); + let callVirtual = module.call( + "~lib/virtual", + [loadMethodID, loadClass], + NativeType.I32 + ); + // module.removeFunction(member.internalName); + let callIndirect = module.call_indirect( + callVirtual, + func.localsByIndex.map(local => + module.local_get(local.index, local.type.toNativeType()) + ), + + Signature.makeSignatureString( + func.signature.parameterTypes, + func.signature.returnType, + func.signature.thisType + ) + ); + + let body = module.block( + null, + [callIndirect], + func.signature.returnType.toNativeType() + ); + + funcRef = module.addFunction(instance.internalName, + typeRef, + null, + body + ); // imported function } else { if (!instance.is(CommonFlags.AMBIENT)) { @@ -1314,18 +1372,21 @@ export class Compiler extends DiagnosticEmitter { instance.identifierNode.range ); } - + instance.set(CommonFlags.MODULE_IMPORT); mangleImportName(instance, instance.declaration); // TODO: check for duplicates - + // create the import module.addFunctionImport( instance.internalName, mangleImportName_moduleName, mangleImportName_elementName, typeRef - ); - funcRef = module.getFunction(instance.internalName); + ); + } + funcRef = module.getFunction(instance.internalName); + if (instance.prototype.isBound && (instance.parent).prototype.implementsNodes) { + this.ensureFunctionTableEntry(instance); } instance.finalize(module, funcRef); @@ -1436,6 +1497,9 @@ export class Compiler extends DiagnosticEmitter { } } } + if (instance.prototype.implementsNodes) { + this.implementers.push(instance); + } return true; } @@ -1445,11 +1509,11 @@ export class Compiler extends DiagnosticEmitter { contextualTypeArguments: Map | null = null, alternativeReportNode: Node | null = null ): void { - // TODO - this.error( - DiagnosticCode.Not_implemented, - declaration.range - ); + // TODO Compile functions to use + // this.error( + // DiagnosticCode.Operation_not_supported, + // declaration.range + // ); } // === Memory =================================================================================== @@ -6196,6 +6260,11 @@ export class Compiler extends DiagnosticEmitter { } var parameterTypes = signature.parameterTypes; for (let i = 0; i < numArguments; ++i, ++index) { + if (parameterTypes[i].is(TypeFlags.REFERENCE)){ + + } + let arg_type = this.resolver.resolveExpression(argumentExpressions[i], this.currentFlow); + operands[index] = this.compileExpression(argumentExpressions[i], parameterTypes[i], Constraints.CONV_IMPLICIT ); @@ -9117,6 +9186,35 @@ export class Compiler extends DiagnosticEmitter { return module.block(label, conditions, NativeType.I32); } + compileVirtualTable(): void { + const interfaces = this.program.interfaces; + const implementers: ClassPrototype[] = this.program.queuedImplements; + const program: Program = this.program; + const getFunc = (funcP: FunctionPrototype): Function => { + if (!program.instancesByName.has(funcP.internalName)) { + this.compileElement(funcP); + } + return program.instancesByName.get(funcP.internalName)!; + }; + const methods: Function[] = []; + debugger; + // for (const _class of implementers) { + // methods.concat(_class.instanceMethods.map(getFunc) + // .filter(func => { + // return interfaces.some(_interface => { + // return _interface.prototype.instanceMethods.map(getFunc) + // .some(ifunc => func.signature.id == ifunc.signature.id ) + // }) + // })) + // } + const relooper = this.module.createRelooper(); + var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null); + + + // let body = this.module. + // this.module.addFunction("~lib/_virtual", typeRef, null, ); + + } } // helpers @@ -9197,3 +9295,4 @@ export function flatten(module: Module, stmts: ExpressionRef[], type: NativeType : type ); } + diff --git a/src/program.ts b/src/program.ts index 3bdd75a847..986ea353fe 100644 --- a/src/program.ts +++ b/src/program.ts @@ -90,7 +90,9 @@ import { writeI16, writeI32, writeF32, - writeF64 + writeF64, + filter, + map } from "./util"; import { @@ -400,6 +402,8 @@ export class Program extends DiagnosticEmitter { managedClasses: Map = new Map(); /** A set of unique function signatures contained in the program, by id. */ uniqueSignatures: Signature[] = new Array(0); + /** Classes that implement interfaces */ + queuedImplements = new Array(); // standard references @@ -493,6 +497,20 @@ export class Program extends DiagnosticEmitter { return null; } + get interfaces(): Interface[] { + return this.getInstanceByKind(ElementKind.INTERFACE); + } + + getInstanceByKind(kind: ElementKind): Element[] { + const res = []; + for (const element of this.instancesByName.values()) { + if (element.kind == kind) { + res.push(element); + } + } + return res; + } + /** Writes a common runtime header to the specified buffer. */ writeRuntimeHeader(buffer: Uint8Array, offset: i32, classInstance: Class, payloadSize: u32): void { // BLOCK { @@ -700,7 +718,7 @@ export class Program extends DiagnosticEmitter { var queuedExports = new Map>(); var queuedExportsStar = new Map(); var queuedExtends = new Array(); - var queuedImplements = new Array(); + var queuedImplements = this.queuedImplements; // initialize relevant declaration-like statements of the entire program for (let i = 0, k = this.sources.length; i < k; ++i) { @@ -1261,12 +1279,12 @@ export class Program extends DiagnosticEmitter { } } else if (numImplementsTypes) { // remember classes that implement interfaces - for (let i = 0; i < numImplementsTypes; ++i) { - this.warning( - DiagnosticCode.Not_implemented, - implementsTypes[i].range - ); - } + // for (let i = 0; i < numImplementsTypes; ++i) { + // this.warning( // TODO: not yet supported + // DiagnosticCode.Operation_not_supported, + // implementsTypes[i].range + // ); + // } queuedImplements.push(element); } } @@ -3132,6 +3150,12 @@ export class ClassPrototype extends DeclaredElement { /** Already resolved instances. */ instances: Map | null = null; + /** Instance Methods */ + get instanceMethods(): FunctionPrototype[] { + if (!this.instanceMembers) return []; + return filter(this.instanceMembers.values(), mem => mem.kind == ElementKind.FUNCTION_PROTOTYPE); + } + constructor( /** Simple name. */ name: string, @@ -3355,6 +3379,32 @@ export class Class extends TypedElement { /** 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; + if (target.kind == ElementKind.INTERFACE) { + if (current.prototype.implementsNodes) { + return current.prototype.implementsNodes.some((element) => element.name.identifier.symbol == target.name) + } else { + return false; + } + // const members = (target).prototype.instanceMembers; + // if (members == null) return true; // Is an empty interface always castable? + // let curr_members = current.prototype.instanceMembers; + // if (curr_members == null) return false; // Interface is non-empty but class is. + // for (const interface_member of members.values()) { + // let hasMember = false; + // for (const class_member of curr_members.values()) { + // if (interface_member.kind == ElementKind.FUNCTION && + // class_member.kind == ElementKind.FUNCTION && + // (interface_member).signature.id == ( class_member).signature.id ) { + // hasMember = true; + // break; + // } + // } + // if (!hasMember) { + // return false; + // } + // } + // return true; + } do if (current == target) return true; while (current = current.base); return false; @@ -3597,13 +3647,13 @@ export class InterfacePrototype extends ClassPrototype { // FIXME /** A resolved interface. */ export class Interface extends Class { // FIXME - + implementers: Set = new Set(); /** Constructs a new interface. */ constructor( nameInclTypeParameters: string, prototype: InterfacePrototype, - typeArguments: Type[] = [], - base: Interface | null = null + typeArguments: Type[] | null = [], + base: Interface | Class | null = null // interface can extend classes in typescript ) { super( nameInclTypeParameters, @@ -3613,6 +3663,34 @@ export class Interface extends Class { // FIXME true ); } + + addImplementer(_class: Class): void { + this.implementers.add(_class); + } + + checkClass(_class: Class): bool { + return this.prototype.instanceMethods.reduce((acc, ifunc) => + (this.getFunc(_class, ifunc) != null ) && acc, true); + } + + private getFunc(_class: Class, ifunc: FunctionPrototype): FunctionPrototype | null { + const methods = _class.prototype.instanceMethods; + const index = methods.findIndex(func => (func.internalName == ifunc.internalName && ( + func.functionTypeNode.equals(ifunc.functionTypeNode) && + TypeNode.arrayEquals(func.typeParameterNodes, ifunc.typeParameterNodes) + ))); + if (index > 0){ + return methods[index]; + } + return null; + } + + getFuncPrototypeImplementation(ifunc: Function): FunctionPrototype[] { + return map(this.implementers, _class => this.getFunc(_class, ifunc.prototype)) + .filter(func => func != null); + } + + } /** Registers a concrete element with a program. */ diff --git a/src/resolver.ts b/src/resolver.ts index 550806c5e2..bb6fef12f7 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -27,7 +27,9 @@ import { TypedElement, FunctionTarget, IndexSignature, - isTypedElement + isTypedElement, + InterfacePrototype, + Interface } from "./program"; import { @@ -234,7 +236,7 @@ export class Resolver extends DiagnosticEmitter { } // Handle classes - if (element.kind == ElementKind.CLASS_PROTOTYPE) { + if (element.kind == ElementKind.CLASS_PROTOTYPE || element.kind == ElementKind.INTERFACE_PROTOTYPE) { let instance = this.resolveClassInclTypeArguments( element, typeArgumentNodes, @@ -2449,7 +2451,7 @@ export class Resolver extends DiagnosticEmitter { // Instance method prototypes are pre-bound to their concrete class as their parent if (prototype.is(CommonFlags.INSTANCE)) { - assert(actualParent.kind == ElementKind.CLASS); + assert(actualParent.kind == ElementKind.CLASS || actualParent.kind == ElementKind.INTERFACE); classInstance = actualParent; // check if this exact concrete class and function combination is known already @@ -2709,7 +2711,9 @@ export class Resolver extends DiagnosticEmitter { // Construct the instance and remember that it has been resolved already var nameInclTypeParamters = prototype.name; if (instanceKey.length) nameInclTypeParamters += "<" + instanceKey + ">"; - instance = new Class(nameInclTypeParamters, prototype, typeArguments, baseClass); + instance = ((prototype instanceof InterfacePrototype) ? + new Interface(nameInclTypeParamters, prototype, typeArguments, baseClass) : + new Class(nameInclTypeParamters, prototype, typeArguments, baseClass)); instance.contextualTypeArguments = ctxTypes; prototype.setResolvedInstance(instanceKey, instance); diff --git a/src/util/collections.ts b/src/util/collections.ts index f854d6af7f..f9cfbdbd52 100644 --- a/src/util/collections.ts +++ b/src/util/collections.ts @@ -26,3 +26,20 @@ export function makeMap(original: Map | null = null, overrides: Map(iter: Iterable, func: (t: T) => bool): T[] { + const res: T[] = []; + for (let i of iter) { + if (func(i)) { + res.push(i); + } + } + return res; +} +export function map(iter: Iterable, func: (t: T) => R): R[] { + const res: R[] = []; + for (let i of iter) { + res.push(func(i)); + } + return res; +} diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index cb44b20854..c013634bc6 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -565,7 +565,9 @@ interface Iterable { [Symbol.iterator](): Iterator; } -interface Iterator {} +//TODO: interface Iterator {} +// Breaks +interface Iterator {} interface IMath { readonly E: f64; diff --git a/tests/compiler.js b/tests/compiler.js index 82c0c3b772..be5bbffa66 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -142,7 +142,7 @@ function runTest(basename) { var cmd = [ basename + ".ts", "--baseDir", basedir, - "--validate", + // "--validate", "--measure", "--debug", "--textFile" // -> stdout diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index 06ac29338a..b265590425 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -15,4 +15,6 @@ let aFoo = new AFoo(); function passAnInterface(foo: IFoo): void { assert(foo.foo(1) == 42); -} \ No newline at end of file +} + +passAnInterface(aFoo); \ No newline at end of file From 6b58579924fff9d434db570062035e64ec5bb975 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 20 Sep 2019 14:14:07 -0400 Subject: [PATCH 03/47] Works but virtual table is hard coded --- src/compiler.ts | 65 +++++--- src/program.ts | 67 ++++---- src/resolver.ts | 3 +- tests/compiler/interface.optimized.wat | 130 +++++++++++++++ tests/compiler/interface.untouched.wat | 209 +++++++++++++++++++++++++ tests/compiler/interface.wat | 209 +++++++++++++++++++++++++ 6 files changed, 622 insertions(+), 61 deletions(-) create mode 100644 tests/compiler/interface.optimized.wat create mode 100644 tests/compiler/interface.untouched.wat create mode 100644 tests/compiler/interface.wat diff --git a/src/compiler.ts b/src/compiler.ts index da58a9945f..59bffbac19 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -80,7 +80,8 @@ import { PropertyPrototype, IndexSignature, File, - mangleInternalName + mangleInternalName, + Interface } from "./program"; import { @@ -452,7 +453,6 @@ export class Compiler extends DiagnosticEmitter { // set up virtual table this.compileVirtualTable(); - // set up function table var functionTable = this.functionTable; module.setFunctionTable(functionTable.length, 0xffffffff, functionTable); @@ -465,7 +465,6 @@ export class Compiler extends DiagnosticEmitter { for (let file of this.program.filesByName.values()) { if (file.source.sourceKind == SourceKind.USER_ENTRY) this.ensureModuleExports(file); } - console.log(functionTable.join(",\n")); return module; } @@ -1334,7 +1333,7 @@ export class Compiler extends DiagnosticEmitter { NativeType.I32 ); let callVirtual = module.call( - "~lib/virtual", + "~virtual", [loadMethodID, loadClass], NativeType.I32 ); @@ -3005,6 +3004,14 @@ export class Compiler extends DiagnosticEmitter { } } } + // Check if a converting to an Interface + if (toType.is(TypeFlags.REFERENCE)) { + assert(toType.classReference != null && toType.classReference != null); + if (toType.classReference!.kind == ElementKind.INTERFACE) { + (toType.classReference!).implementers.add(fromType.classReference!); + } + + } if (fromType.is(TypeFlags.FLOAT)) { @@ -6260,7 +6267,7 @@ export class Compiler extends DiagnosticEmitter { } var parameterTypes = signature.parameterTypes; for (let i = 0; i < numArguments; ++i, ++index) { - if (parameterTypes[i].is(TypeFlags.REFERENCE)){ + if (parameterTypes[i].is(TypeFlags.REFERENCE)) { } let arg_type = this.resolver.resolveExpression(argumentExpressions[i], this.currentFlow); @@ -9188,31 +9195,39 @@ export class Compiler extends DiagnosticEmitter { compileVirtualTable(): void { const interfaces = this.program.interfaces; - const implementers: ClassPrototype[] = this.program.queuedImplements; - const program: Program = this.program; - const getFunc = (funcP: FunctionPrototype): Function => { - if (!program.instancesByName.has(funcP.internalName)) { - this.compileElement(funcP); - } - return program.instancesByName.get(funcP.internalName)!; - }; - const methods: Function[] = []; - debugger; - // for (const _class of implementers) { - // methods.concat(_class.instanceMethods.map(getFunc) - // .filter(func => { - // return interfaces.some(_interface => { - // return _interface.prototype.instanceMethods.map(getFunc) - // .some(ifunc => func.signature.id == ifunc.signature.id ) - // }) - // })) - // } + const methods: Map = new Map(); + for (let _interface of interfaces) { + for (let func of _interface.methodInstances) { + const id = func.signature.id; + if (!methods.has(id)) { + methods.set(id, []); + } + const newFuncs: Function[] = _interface.getFuncPrototypeImplementation(func).map( + // tslint:disable-next-line: as-types + funcP => { + const newFunc = this.resolver.resolveFunction(funcP, null, func.contextualTypeArguments); + if (newFunc == null) { + throw new Error(`Couldn't resolve ${funcP.name}`); + } + this.compileFunction(newFunc); + this.ensureFunctionTableEntry(newFunc); + return newFunc; + } + ); + methods.get(id)!.concat(newFuncs); + } + } + const relooper = this.module.createRelooper(); + debugger; + for (const [id, funcs] of methods) { + + } var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null); // let body = this.module. - // this.module.addFunction("~lib/_virtual", typeRef, null, ); + this.module.addFunction("~virtual", typeRef, null, this.module.i32(1)); } } diff --git a/src/program.ts b/src/program.ts index 986ea353fe..ad042151d1 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3380,30 +3380,7 @@ export class Class extends TypedElement { isAssignableTo(target: Class): bool { var current: Class | null = this; if (target.kind == ElementKind.INTERFACE) { - if (current.prototype.implementsNodes) { - return current.prototype.implementsNodes.some((element) => element.name.identifier.symbol == target.name) - } else { - return false; - } - // const members = (target).prototype.instanceMembers; - // if (members == null) return true; // Is an empty interface always castable? - // let curr_members = current.prototype.instanceMembers; - // if (curr_members == null) return false; // Interface is non-empty but class is. - // for (const interface_member of members.values()) { - // let hasMember = false; - // for (const class_member of curr_members.values()) { - // if (interface_member.kind == ElementKind.FUNCTION && - // class_member.kind == ElementKind.FUNCTION && - // (interface_member).signature.id == ( class_member).signature.id ) { - // hasMember = true; - // break; - // } - // } - // if (!hasMember) { - // return false; - // } - // } - // return true; + return (target).checkClass(this); } do if (current == target) return true; while (current = current.base); @@ -3664,32 +3641,52 @@ export class Interface extends Class { // FIXME ); } + get methods(): FunctionPrototype[] { + if (this.members == null) return []; + return filter(this.members.values(), v => v.kind == ElementKind.FUNCTION_PROTOTYPE) + } + + get methodInstances(): Function[] { + var funcs: Function[] = []; + for (let func of this.methods) { + if (func.instances == null) continue; + map(func.instances.values(), (func: Function): void => { + if (funcs.findIndex(f => f.signature.id == func.signature.id) < 0) { + funcs.push(func); + } + }); + } + return funcs; + } + addImplementer(_class: Class): void { this.implementers.add(_class); } checkClass(_class: Class): bool { - return this.prototype.instanceMethods.reduce((acc, ifunc) => + return this.methods.reduce((acc, ifunc) => (this.getFunc(_class, ifunc) != null ) && acc, true); } private getFunc(_class: Class, ifunc: FunctionPrototype): FunctionPrototype | null { - const methods = _class.prototype.instanceMethods; - const index = methods.findIndex(func => (func.internalName == ifunc.internalName && ( - func.functionTypeNode.equals(ifunc.functionTypeNode) && - TypeNode.arrayEquals(func.typeParameterNodes, ifunc.typeParameterNodes) - ))); - if (index > 0){ - return methods[index]; - } - return null; + if (_class.members == null) return null; + return _class.members.get(ifunc.name); } getFuncPrototypeImplementation(ifunc: Function): FunctionPrototype[] { - return map(this.implementers, _class => this.getFunc(_class, ifunc.prototype)) + return map(this.implementers, + _class => this.getFunc(_class, ifunc.prototype)) .filter(func => func != null); } + get methodsToCompile(): FunctionPrototype[] { + var funcs: FunctionPrototype[] = []; + for (let func of this.methodInstances) { + funcs.concat(this.getFuncPrototypeImplementation(func)); + } + return funcs; + } + } diff --git a/src/resolver.ts b/src/resolver.ts index bb6fef12f7..a3ea5b542e 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2439,7 +2439,7 @@ export class Resolver extends DiagnosticEmitter { /** Type arguments provided. */ typeArguments: Type[] | null, /** Contextual types, i.e. `T`. */ - ctxTypes: Map = makeMap(), + ctxTypes: Map | null = makeMap(), /** How to proceed with eventual diagnostics. */ reportMode: ReportMode = ReportMode.REPORT ): Function | null { @@ -2448,6 +2448,7 @@ export class Resolver extends DiagnosticEmitter { : prototype.parent; var classInstance: Class | null = null; // if an instance method var instanceKey = typeArguments ? typesToString(typeArguments) : ""; + ctxTypes = ctxTypes || makeMap(); // Instance method prototypes are pre-bound to their concrete class as their parent if (prototype.is(CommonFlags.INSTANCE)) { diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat new file mode 100644 index 0000000000..21ad1be700 --- /dev/null +++ b/tests/compiler/interface.optimized.wat @@ -0,0 +1,130 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (type $FUNCSIG$i (func (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") + (table $0 2 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface/aFoo (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$i) (result i32) + (local $0 i32) + (local $1 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const -1 + i32.store offset=4 + local.get $0 + i32.const 3 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $1 + ) + (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + drop + local.get $0 + i32.const 1 + call $interface/AFoo#foo + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 17 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 4 ;) (type $FUNCSIG$v) + (local $0 i32) + i32.const 48 + global.set $~lib/rt/stub/startOffset + i32.const 48 + global.set $~lib/rt/stub/offset + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 41 + i32.store + local.get $0 + global.set $interface/aFoo + global.get $interface/aFoo + call $interface/passAnInterface + ) + (func $interface/AFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $null (; 6 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat new file mode 100644 index 0000000000..13ce7eca74 --- /dev/null +++ b/tests/compiler/interface.untouched.wat @@ -0,0 +1,209 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") + (table $0 2 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface/aFoo (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 48)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $interface/AFoo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 41 + i32.store + local.get $0 + ) + (func $interface/IFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.const 18 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iii) + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $interface/passAnInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/stub/__retain + drop + local.get $0 + i32.const 1 + call $interface/IFoo#foo + i32.const 42 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 17 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:interface (; 8 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $interface/AFoo#constructor + global.set $interface/aFoo + global.get $interface/aFoo + call $interface/passAnInterface + ) + (func $start (; 9 ;) (type $FUNCSIG$v) + call $start:interface + ) + (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + i32.const 1 + ) + (func $null (; 12 ;) (type $FUNCSIG$v) + ) +) diff --git a/tests/compiler/interface.wat b/tests/compiler/interface.wat new file mode 100644 index 0000000000..13ce7eca74 --- /dev/null +++ b/tests/compiler/interface.wat @@ -0,0 +1,209 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") + (table $0 2 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface/aFoo (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 48)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $interface/AFoo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 41 + i32.store + local.get $0 + ) + (func $interface/IFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.const 18 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iii) + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $interface/passAnInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/stub/__retain + drop + local.get $0 + i32.const 1 + call $interface/IFoo#foo + i32.const 42 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 17 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:interface (; 8 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $interface/AFoo#constructor + global.set $interface/aFoo + global.get $interface/aFoo + call $interface/passAnInterface + ) + (func $start (; 9 ;) (type $FUNCSIG$v) + call $start:interface + ) + (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + i32.const 1 + ) + (func $null (; 12 ;) (type $FUNCSIG$v) + ) +) From f704437ed47ee9d557c3752c3ce96407ce046464 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 13:52:43 -0400 Subject: [PATCH 04/47] Added relooper table and if cases --- src/compiler.ts | 155 ++++++++++++++++--------- src/program.ts | 4 +- tests/compiler/interface.optimized.wat | 68 +++++++++-- tests/compiler/interface.ts | 7 ++ tests/compiler/interface.untouched.wat | 114 ++++++++++++++---- 5 files changed, 260 insertions(+), 88 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 59bffbac19..33375c86e3 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -43,7 +43,8 @@ import { getLocalSetIndex, FeatureFlags, needsExplicitUnreachable, - getLocalSetValue + getLocalSetValue, + RelooperBlockRef } from "./module"; import { @@ -1313,55 +1314,10 @@ export class Compiler extends DiagnosticEmitter { ); // Virtual Methods } else if (instance.is( CommonFlags.VIRTUAL)) { - let func: Function = instance; - let signature = func.signature; - let typeRef = this.ensureFunctionType( - signature.parameterTypes, - signature.returnType, - signature.thisType - ); - let loadMethodID = module.i32(signature.id); - // let target = this.compiler.program.instancesByName("virtual"); - let loadClass = module.load( - 4, - false, - module.binary( - BinaryOp.SubI32, - module.local_get(0, NativeType.I32), - module.i32(8) - ), - NativeType.I32 - ); - let callVirtual = module.call( - "~virtual", - [loadMethodID, loadClass], - NativeType.I32 - ); - // module.removeFunction(member.internalName); - - let callIndirect = module.call_indirect( - callVirtual, - func.localsByIndex.map(local => - module.local_get(local.index, local.type.toNativeType()) - ), - - Signature.makeSignatureString( - func.signature.parameterTypes, - func.signature.returnType, - func.signature.thisType - ) - ); - - let body = module.block( - null, - [callIndirect], - func.signature.returnType.toNativeType() - ); - funcRef = module.addFunction(instance.internalName, typeRef, null, - body + module.nop() ); // imported function } else { @@ -9195,45 +9151,128 @@ export class Compiler extends DiagnosticEmitter { compileVirtualTable(): void { const interfaces = this.program.interfaces; - const methods: Map = new Map(); + const instanceMethods: Map> = new Map(); + const interfaceMethods: Map = new Map(); + // Gather all instatiated interface methods for (let _interface of interfaces) { for (let func of _interface.methodInstances) { const id = func.signature.id; - if (!methods.has(id)) { - methods.set(id, []); + if (!interfaceMethods.has(id)) { + interfaceMethods.set(id, []); + } + interfaceMethods.get(id)!.push(func); + if (!instanceMethods.has(id)) { + instanceMethods.set(id, new Map()); } - const newFuncs: Function[] = _interface.getFuncPrototypeImplementation(func).map( + const currentMap = instanceMethods.get(id)!; + _interface.getFuncImplementations(func).map( // tslint:disable-next-line: as-types funcP => { + // TODO: Better way to pass contextual type info const newFunc = this.resolver.resolveFunction(funcP, null, func.contextualTypeArguments); if (newFunc == null) { throw new Error(`Couldn't resolve ${funcP.name}`); } this.compileFunction(newFunc); this.ensureFunctionTableEntry(newFunc); + currentMap.set((newFunc.parent).id, newFunc); return newFunc; } ); - methods.get(id)!.concat(newFuncs); } } + const module = this.module; + // Create relooper to build table const relooper = this.module.createRelooper(); - debugger; - for (const [id, funcs] of methods) { - - } + const iFuncs: [number, Map][] = Array.from(instanceMethods.entries()); + const methodBlocks: RelooperBlockRef[] = []; + const getArg = (i: i32): ExpressionRef => module.local_get(i, Type.i32.toNativeType()); + // Condition to switch on + const first = relooper.addBlockWithSwitch(module.nop(), getArg(0)); + const zero = relooper.addBlock(module.drop(module.i32(0))); + + for (let index: i32 = 0; index < iFuncs.length; index++) { + const [funcID, classes] = iFuncs[index]; + // Compile the interface methods with index + for (const iFunc of interfaceMethods.get(funcID)!) { + iFunc.finalize(module, this.compileInterfaceMethod(iFunc, index)); + } + const innerBlock = relooper.addBlock(module.nop()); + relooper.addBranchForSwitch(first, innerBlock, [index]); + for (const [classID, func] of classes.entries()) { + const methodCase = relooper.addBlock(module.return(module.i32(func.functionTableIndex))); + const condition = module.binary(BinaryOp.EqI32, getArg(1), module.i32(classID)); + relooper.addBranch(innerBlock, methodCase, condition); + } + relooper.addBranch(innerBlock, zero, 0, module.unreachable()); + } + relooper.addBranchForSwitch(first, zero, [], module.unreachable()); + var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null); + const body = module.block( + null, + [relooper.renderAndDispose(first, 0), module.i32(0)], + Type.u32.toNativeType() + );; + const hardCoded = this.module.i32(1); + this.module.addFunction("~virtual", typeRef, null, body); - // let body = this.module. - this.module.addFunction("~virtual", typeRef, null, this.module.i32(1)); + } + compileInterfaceMethod(func: Function, methodID: i32): ExpressionRef { + const signature = func.signature; + const module = this.module; + const typeRef = this.ensureFunctionType( + signature.parameterTypes, + signature.returnType, + signature.thisType + ); + const loadMethodID = module.i32(methodID); + // let target = this.compiler.program.instancesByName("virtual"); + const loadClass = module.load( + 4, + false, + module.binary( + BinaryOp.SubI32, + module.local_get(0, NativeType.I32), + module.i32(8) + ), + NativeType.I32 + ); + const callVirtual = module.call( + "~virtual", + [loadMethodID, loadClass], + NativeType.I32 + ); + // module.removeFunction(member.internalName); + + const callIndirect = module.call_indirect( + callVirtual, + func.localsByIndex.map(local => + module.local_get(local.index, local.type.toNativeType()) + ), + Signature.makeSignatureString( + func.signature.parameterTypes, + func.signature.returnType, + func.signature.thisType + ) + ); + + const body = module.block( + null, + [callIndirect], + func.signature.returnType.toNativeType() + ); + module.removeFunction(func.internalName); + return module.addFunction(func.internalName, typeRef, null, body); } } // helpers + function mangleImportName( element: Element, declaration: DeclarationStatement diff --git a/src/program.ts b/src/program.ts index ad042151d1..74a7f920b9 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3673,7 +3673,7 @@ export class Interface extends Class { // FIXME return _class.members.get(ifunc.name); } - getFuncPrototypeImplementation(ifunc: Function): FunctionPrototype[] { + getFuncImplementations(ifunc: Function): FunctionPrototype[] { return map(this.implementers, _class => this.getFunc(_class, ifunc.prototype)) .filter(func => func != null); @@ -3682,7 +3682,7 @@ export class Interface extends Class { // FIXME get methodsToCompile(): FunctionPrototype[] { var funcs: FunctionPrototype[] = []; for (let func of this.methodInstances) { - funcs.concat(this.getFuncPrototypeImplementation(func)); + funcs.concat(this.getFuncImplementations(func)); } return funcs; } diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 21ad1be700..4a708d838c 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -2,13 +2,14 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") - (table $0 2 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo) + (table $0 3 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -84,20 +85,41 @@ local.get $1 ) (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + i32.const 1 + i32.const 0 local.get $0 i32.const 8 i32.sub i32.load - drop + call $~virtual + call_indirect (type $FUNCSIG$iii) + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 23 + i32.const 2 + call $~lib/builtins/abort + unreachable + end local.get $0 i32.const 1 - call $interface/AFoo#foo - i32.const 42 + i32.const 3 + i32.const 1 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iiii) + i32.const 4 i32.ne if i32.const 0 i32.const 24 - i32.const 17 + i32.const 24 i32.const 2 call $~lib/builtins/abort unreachable @@ -124,7 +146,39 @@ local.get $1 i32.add ) - (func $null (; 6 ;) (type $FUNCSIG$v) + (func $interface/AFoo#faa (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + block $switch$1$default + block $switch$1$case$5 + block $switch$1$case$3 + local.get $0 + br_table $switch$1$case$3 $switch$1$case$5 $switch$1$default + end + local.get $1 + i32.const 3 + i32.ne + if + unreachable + end + i32.const 1 + return + end + local.get $1 + i32.const 3 + i32.ne + if + unreachable + end + i32.const 2 + return + end + unreachable + ) + (func $null (; 8 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index b265590425..74ff465645 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -1,6 +1,7 @@ interface IFoo { foo(i: i32): i32; + faa(i: i32, i2: i32): i32; } class AFoo implements IFoo { @@ -9,12 +10,18 @@ class AFoo implements IFoo { foo(i: i32): i32 { return this.i + i; } + + faa(i: i32, i2: i32): i32 { + return i + i2; + } + } let aFoo = new AFoo(); function passAnInterface(foo: IFoo): void { assert(foo.foo(1) == 42); + assert(foo.faa(1,3) == 4); } passAnInterface(aFoo); \ No newline at end of file diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 13ce7eca74..35d23073ac 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -3,12 +3,13 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 2 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo) + (table $0 3 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -140,21 +141,10 @@ i32.store local.get $0 ) - (func $interface/IFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - local.get $1 - i32.const 18 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iii) - ) - (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/stub/__release (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $interface/passAnInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/passAnInterface (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 call $~lib/rt/stub/__retain drop @@ -167,7 +157,22 @@ if i32.const 0 i32.const 24 - i32.const 17 + i32.const 23 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 1 + i32.const 3 + call $interface/IFoo#faa + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 24 i32.const 2 call $~lib/builtins/abort unreachable @@ -175,7 +180,7 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:interface (; 8 ;) (type $FUNCSIG$v) + (func $start:interface (; 7 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -192,18 +197,85 @@ global.get $interface/aFoo call $interface/passAnInterface ) - (func $start (; 9 ;) (type $FUNCSIG$v) + (func $start (; 8 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#faa (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface/IFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.const 0 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iii) + ) + (func $interface/IFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $0 + local.get $1 + local.get $2 i32.const 1 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iiii) + ) + (func $~virtual (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + block $block$2$break + block $switch$1$default + block $switch$1$case$5 + block $switch$1$case$3 + local.get $0 + br_table $switch$1$case$3 $switch$1$case$5 $switch$1$default + end + block $block$4$break + local.get $1 + i32.const 3 + i32.eq + if + br $block$4$break + else + unreachable + end + unreachable + end + i32.const 1 + return + end + block $block$6$break + local.get $1 + i32.const 3 + i32.eq + if + br $block$6$break + else + unreachable + end + unreachable + end + i32.const 2 + return + end + unreachable + end + i32.const 0 + drop + i32.const 0 ) - (func $null (; 12 ;) (type $FUNCSIG$v) + (func $null (; 14 ;) (type $FUNCSIG$v) ) ) From 3864d7e81bcfb72f70b657c8437eb6fbcd730709 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 16:00:49 -0400 Subject: [PATCH 05/47] Fixed tests --- src/compiler.ts | 10 +++------- src/types.ts | 5 +++++ std/portable/index.d.ts | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 33375c86e3..f07d8eaf77 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2961,8 +2961,8 @@ export class Compiler extends DiagnosticEmitter { } } // Check if a converting to an Interface - if (toType.is(TypeFlags.REFERENCE)) { - assert(toType.classReference != null && toType.classReference != null); + if (toType.is(TypeFlags.REFERENCE) && !toType.isFunction) { + assert(toType.classReference != null && fromType.classReference != null); if (toType.classReference!.kind == ElementKind.INTERFACE) { (toType.classReference!).implementers.add(fromType.classReference!); } @@ -6223,11 +6223,6 @@ export class Compiler extends DiagnosticEmitter { } var parameterTypes = signature.parameterTypes; for (let i = 0; i < numArguments; ++i, ++index) { - if (parameterTypes[i].is(TypeFlags.REFERENCE)) { - - } - let arg_type = this.resolver.resolveExpression(argumentExpressions[i], this.currentFlow); - operands[index] = this.compileExpression(argumentExpressions[i], parameterTypes[i], Constraints.CONV_IMPLICIT ); @@ -9151,6 +9146,7 @@ export class Compiler extends DiagnosticEmitter { compileVirtualTable(): void { const interfaces = this.program.interfaces; + if (interfaces.length == 0) return; //Don't create table if no interfaces present const instanceMethods: Map> = new Map(); const interfaceMethods: Map = new Map(); // Gather all instatiated interface methods diff --git a/src/types.ts b/src/types.ts index f60fa20b4a..1266988091 100644 --- a/src/types.ts +++ b/src/types.ts @@ -173,6 +173,11 @@ export class Type { return classReference !== null && classReference.hasDecorator(DecoratorFlags.UNMANAGED); } + get isFunction(): bool { + var signature = this.signatureReference; + return signature != null && this.is(TypeFlags.REFERENCE); + } + /** Computes the sign-extending shift in the target type. */ computeSmallIntegerShift(targetType: Type): u32 { return targetType.size - this.size; diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index c013634bc6..2a589b72fe 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -567,7 +567,7 @@ interface Iterable { //TODO: interface Iterator {} // Breaks -interface Iterator {} +interface Iterator {} interface IMath { readonly E: f64; From 2904951362b4789650911fbff23c3e99e7c917e4 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 16:20:32 -0400 Subject: [PATCH 06/47] Update arrayEquals --- src/ast.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index e449f78814..cf51970b87 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1107,10 +1107,14 @@ export abstract class TypeNode extends Node { abstract equals(node: TypeNode): bool; static arrayEquals(node: Comparable[] | null, other: Comparable[] | null): bool { - if (node == null && other == null) return true; - if (node == null || other == null) return false; - if (node.length != other.length) return false; - return node.map((value, i) => value.equals(other[i])).every(x => x); + if (node == other) return true; + if (!node || !other) return false; + const len = other.length; + if (node.length !== len) return false; + for (let i = 0; i < len; i++) { + if (!node[i].equals(other[i])) return false; + } + return true; } } From e09ce146e0b909f34ec173b49a6c2608afe9c102 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 20:41:27 -0400 Subject: [PATCH 07/47] Test email again --- src/ast.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index cf51970b87..a1af43a586 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1103,7 +1103,8 @@ export abstract class TypeNode extends Node { } return false; } - + + /** Method for determine type equality. */ abstract equals(node: TypeNode): bool; static arrayEquals(node: Comparable[] | null, other: Comparable[] | null): bool { @@ -1143,7 +1144,6 @@ export class NamedTypeNode extends TypeNode { name: TypeName; /** Type argument references. */ typeArguments: TypeNode[] | null; - equals(node: NamedTypeNode): bool { if (!this.name.equals(node.name)) return false; return TypeNode.arrayEquals(this.typeArguments, node.typeArguments); From e58342f13ae0dea83e13f20859a87ce48705bf4f Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 20:44:27 -0400 Subject: [PATCH 08/47] Adding Email to Notice to pass test --- NOTICE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NOTICE b/NOTICE index 709141a353..ce175709fb 100644 --- a/NOTICE +++ b/NOTICE @@ -13,7 +13,7 @@ under the licensing terms detailed in LICENSE: * Joshua Tenner * Nidin Vinayakan <01@01alchemist.com> * Aaron Turner -* Willem Wyndham +* Willem Wyndham or * Bowen Wang * Emil Laine From 2a17582e52b966f1333087f895654238239b74b5 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 20:54:35 -0400 Subject: [PATCH 09/47] Add test for structurally interface --- src/compiler.ts | 14 ++-- tests/compiler/interface.optimized.wat | 77 +++++++++++++++------ tests/compiler/interface.ts | 19 ++++- tests/compiler/interface.untouched.wat | 96 +++++++++++++++++++------- 4 files changed, 149 insertions(+), 57 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index f07d8eaf77..f05a7b28cb 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1327,10 +1327,9 @@ export class Compiler extends DiagnosticEmitter { instance.identifierNode.range ); } - instance.set(CommonFlags.MODULE_IMPORT); mangleImportName(instance, instance.declaration); // TODO: check for duplicates - + // create the import module.addFunctionImport( instance.internalName, @@ -1464,7 +1463,7 @@ export class Compiler extends DiagnosticEmitter { contextualTypeArguments: Map | null = null, alternativeReportNode: Node | null = null ): void { - // TODO Compile functions to use + // TODO Compile functions to use // this.error( // DiagnosticCode.Operation_not_supported, // declaration.range @@ -9191,10 +9190,11 @@ export class Compiler extends DiagnosticEmitter { for (let index: i32 = 0; index < iFuncs.length; index++) { const [funcID, classes] = iFuncs[index]; // Compile the interface methods with index - for (const iFunc of interfaceMethods.get(funcID)!) { + for (const iFunc of interfaceMethods.get(funcID)!) { iFunc.finalize(module, this.compileInterfaceMethod(iFunc, index)); } const innerBlock = relooper.addBlock(module.nop()); + // Add brach for method relooper.addBranchForSwitch(first, innerBlock, [index]); for (const [classID, func] of classes.entries()) { const methodCase = relooper.addBlock(module.return(module.i32(func.functionTableIndex))); @@ -9211,7 +9211,7 @@ export class Compiler extends DiagnosticEmitter { null, [relooper.renderAndDispose(first, 0), module.i32(0)], Type.u32.toNativeType() - );; + ); const hardCoded = this.module.i32(1); this.module.addFunction("~virtual", typeRef, null, body); @@ -9243,7 +9243,7 @@ export class Compiler extends DiagnosticEmitter { NativeType.I32 ); // module.removeFunction(member.internalName); - + const callIndirect = module.call_indirect( callVirtual, func.localsByIndex.map(local => @@ -9255,7 +9255,7 @@ export class Compiler extends DiagnosticEmitter { func.signature.thisType ) ); - + const body = module.block( null, [callIndirect], diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 4a708d838c..c69eb1d94a 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -4,15 +4,16 @@ (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") - (table $0 3 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#faa) + (table $0 5 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) + (global $interface/sFoo (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) @@ -57,32 +58,32 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) + (local $2 i32) global.get $~lib/rt/stub/offset i32.const 16 i32.add - local.tee $1 + local.tee $2 i32.const 16 i32.add call $~lib/rt/stub/maybeGrowMemory - local.get $1 + local.get $2 i32.const 16 i32.sub - local.tee $0 + local.tee $1 i32.const 16 i32.store - local.get $0 + local.get $1 i32.const -1 i32.store offset=4 + local.get $1 local.get $0 - i32.const 3 i32.store offset=8 - local.get $0 + local.get $1 i32.const 4 i32.store offset=12 - local.get $1 + local.get $2 ) (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 @@ -99,7 +100,7 @@ if i32.const 0 i32.const 24 - i32.const 23 + i32.const 37 i32.const 2 call $~lib/builtins/abort unreachable @@ -119,7 +120,7 @@ if i32.const 0 i32.const 24 - i32.const 24 + i32.const 38 i32.const 2 call $~lib/builtins/abort unreachable @@ -131,14 +132,24 @@ global.set $~lib/rt/stub/startOffset i32.const 48 global.set $~lib/rt/stub/offset + i32.const 3 call $~lib/rt/stub/__alloc local.tee $0 i32.const 41 i32.store local.get $0 global.set $interface/aFoo + i32.const 4 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 41 + i32.store + local.get $0 + global.set $interface/sFoo global.get $interface/aFoo call $interface/passAnInterface + global.get $interface/sFoo + call $interface/passAnInterface ) (func $interface/AFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 @@ -153,28 +164,50 @@ ) (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $switch$1$default - block $switch$1$case$5 + block $switch$1$case$6 block $switch$1$case$3 local.get $0 - br_table $switch$1$case$3 $switch$1$case$5 $switch$1$default + br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default end local.get $1 i32.const 3 - i32.ne + i32.eq if + i32.const 1 + return + else + local.get $1 + i32.const 4 + i32.eq + if + i32.const 2 + return + else + unreachable + end unreachable end - i32.const 1 - return + unreachable end local.get $1 i32.const 3 - i32.ne + i32.eq if + i32.const 3 + return + else + local.get $1 + i32.const 4 + i32.eq + if + i32.const 4 + return + else + unreachable + end unreachable end - i32.const 2 - return + unreachable end unreachable ) diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index 74ff465645..fbeb938a39 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -17,11 +17,26 @@ class AFoo implements IFoo { } -let aFoo = new AFoo(); +class StructurallyImplementsIFoo { + i: i32 = 41; + + foo(i: i32): i32 { + return this.i + i; + } + + faa(i: i32, i2: i32): i32 { + return i + i2; + } +} + +const aFoo = new AFoo(); +const sFoo = new StructurallyImplementsIFoo(); + function passAnInterface(foo: IFoo): void { assert(foo.foo(1) == 42); assert(foo.faa(1,3) == 4); } -passAnInterface(aFoo); \ No newline at end of file +passAnInterface(aFoo); +passAnInterface(sFoo); diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 35d23073ac..9cc1f64fa3 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -8,11 +8,12 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 3 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#faa) + (table $0 5 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) + (global $interface/sFoo (mut i32) (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 48)) (export "memory" (memory $0)) (start $start) @@ -141,10 +142,25 @@ i32.store local.get $0 ) - (func $~lib/rt/stub/__release (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/StructurallyImplementsIFoo#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 41 + i32.store + local.get $0 + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $interface/passAnInterface (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/passAnInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 call $~lib/rt/stub/__retain drop @@ -157,7 +173,7 @@ if i32.const 0 i32.const 24 - i32.const 23 + i32.const 37 i32.const 2 call $~lib/builtins/abort unreachable @@ -172,7 +188,7 @@ if i32.const 0 i32.const 24 - i32.const 24 + i32.const 38 i32.const 2 call $~lib/builtins/abort unreachable @@ -180,7 +196,7 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:interface (; 7 ;) (type $FUNCSIG$v) + (func $start:interface (; 8 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -194,24 +210,40 @@ i32.const 0 call $interface/AFoo#constructor global.set $interface/aFoo + i32.const 0 + call $interface/StructurallyImplementsIFoo#constructor + global.set $interface/sFoo global.get $interface/aFoo call $interface/passAnInterface + global.get $interface/sFoo + call $interface/passAnInterface ) - (func $start (; 8 ;) (type $FUNCSIG$v) + (func $start (; 9 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/AFoo#faa (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/IFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#faa (; 13 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface/IFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.const 0 @@ -222,7 +254,7 @@ call $~virtual call_indirect (type $FUNCSIG$iii) ) - (func $interface/IFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 local.get $1 local.get $2 @@ -234,41 +266,53 @@ call $~virtual call_indirect (type $FUNCSIG$iiii) ) - (func $~virtual (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~virtual (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $block$2$break block $switch$1$default - block $switch$1$case$5 + block $switch$1$case$6 block $switch$1$case$3 local.get $0 - br_table $switch$1$case$3 $switch$1$case$5 $switch$1$default + br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default end - block $block$4$break + local.get $1 + i32.const 3 + i32.eq + if + i32.const 1 + return + else local.get $1 - i32.const 3 + i32.const 4 i32.eq if - br $block$4$break + i32.const 2 + return else unreachable end unreachable end - i32.const 1 - return + unreachable end - block $block$6$break - local.get $1 + local.get $1 + i32.const 3 + i32.eq + if i32.const 3 + return + else + local.get $1 + i32.const 4 i32.eq if - br $block$6$break + i32.const 4 + return else unreachable end unreachable end - i32.const 2 - return + unreachable end unreachable end @@ -276,6 +320,6 @@ drop i32.const 0 ) - (func $null (; 14 ;) (type $FUNCSIG$v) + (func $null (; 17 ;) (type $FUNCSIG$v) ) ) From a3aef9c9d809ffefc7b2c1c901b42811a462fdae Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 22 Sep 2019 21:10:26 -0400 Subject: [PATCH 10/47] Improve type checking TODO: add better error messages --- src/program.ts | 14 ++- .../{interface.json => interface-fail.json} | 0 tests/compiler/interface-fail.optimized.wat | 96 +++++++++++++++++++ tests/compiler/interface-fail.ts | 22 +++++ tests/compiler/interface-fail.untouched.wat | 0 5 files changed, 129 insertions(+), 3 deletions(-) rename tests/compiler/{interface.json => interface-fail.json} (100%) create mode 100644 tests/compiler/interface-fail.optimized.wat create mode 100644 tests/compiler/interface-fail.ts create mode 100644 tests/compiler/interface-fail.untouched.wat diff --git a/src/program.ts b/src/program.ts index 74a7f920b9..d3e8b64e82 100644 --- a/src/program.ts +++ b/src/program.ts @@ -2767,6 +2767,11 @@ export class FunctionPrototype extends DeclaredElement { lookup(name: string): Element | null { return this.parent.lookup(name); } + + equals(func: FunctionPrototype): bool { + return this.functionTypeNode.equals(func.functionTypeNode) && + TypeNode.arrayEquals(func.typeParameterNodes, this.typeParameterNodes); + } } /** A resolved function. */ @@ -3379,7 +3384,7 @@ export class Class extends TypedElement { /** 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; - if (target.kind == ElementKind.INTERFACE) { + if (target.kind == ElementKind.INTERFACE) { return (target).checkClass(this); } do if (current == target) return true; @@ -3664,8 +3669,11 @@ export class Interface extends Class { // FIXME } checkClass(_class: Class): bool { - return this.methods.reduce((acc, ifunc) => - (this.getFunc(_class, ifunc) != null ) && acc, true); + return this.methods.reduce((acc, ifunc) => { + let func = this.getFunc(_class, ifunc); + if (func == null) return false; + return ifunc.equals(func) && acc; + }, true); } private getFunc(_class: Class, ifunc: FunctionPrototype): FunctionPrototype | null { diff --git a/tests/compiler/interface.json b/tests/compiler/interface-fail.json similarity index 100% rename from tests/compiler/interface.json rename to tests/compiler/interface-fail.json diff --git a/tests/compiler/interface-fail.optimized.wat b/tests/compiler/interface-fail.optimized.wat new file mode 100644 index 0000000000..08abb26ffe --- /dev/null +++ b/tests/compiler/interface-fail.optimized.wat @@ -0,0 +1,96 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$v (func)) + (type $FUNCSIG$i (func (result i32))) + (memory $0 0) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-fail/aFoo (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 0 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$i) (result i32) + (local $0 i32) + (local $1 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const -1 + i32.store offset=4 + local.get $0 + i32.const 4 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $1 + ) + (func $start (; 2 ;) (type $FUNCSIG$v) + (local $0 i32) + i32.const 16 + global.set $~lib/rt/stub/startOffset + i32.const 16 + global.set $~lib/rt/stub/offset + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 41 + i32.store + local.get $0 + global.set $interface-fail/aFoo + ) + (func $null (; 3 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts new file mode 100644 index 0000000000..76c6b7b9de --- /dev/null +++ b/tests/compiler/interface-fail.ts @@ -0,0 +1,22 @@ + +interface IFoo { + foo(i: i32): i32; +} + +class BadFoo implements IFoo { + i: i32 = 41; + + foo(i: i32): string { + return "hello"; + } + + faa(i: i32, i2: i32): i32 { + return i + i2; + } + +} + + +const aFoo: IFoo = new BadFoo(); + + diff --git a/tests/compiler/interface-fail.untouched.wat b/tests/compiler/interface-fail.untouched.wat new file mode 100644 index 0000000000..e69de29bb2 From 99403b8158e5e9cfb5a2670cb89cce1d2e6e6f99 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 23 Sep 2019 12:20:56 -0400 Subject: [PATCH 11/47] Added error messages --- src/ast.ts | 4 +- src/compiler.ts | 67 +++++++++++++++++++++++------ src/diagnosticMessages.generated.ts | 4 ++ src/diagnosticMessages.json | 2 + src/program.ts | 28 ++++++------ src/resolver.ts | 4 +- src/types.ts | 7 ++- tests/compiler/interface-fail.json | 23 +++++++++- tests/compiler/interface-fail.ts | 13 +++--- tests/compiler/interface.json | 5 +++ 10 files changed, 116 insertions(+), 41 deletions(-) create mode 100644 tests/compiler/interface.json diff --git a/src/ast.ts b/src/ast.ts index a1af43a586..f687f91603 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1103,7 +1103,7 @@ export abstract class TypeNode extends Node { } return false; } - + /** Method for determine type equality. */ abstract equals(node: TypeNode): bool; @@ -1171,7 +1171,7 @@ export class FunctionTypeNode extends TypeNode { } get parameterTypes(): TypeNode[] { - return this.parameters.map(param => param.type); + return this.parameters.map((param: ParameterNode): TypeNode => param.type); } } diff --git a/src/compiler.ts b/src/compiler.ts index f05a7b28cb..8cf7ff5f9d 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2944,7 +2944,60 @@ export class Compiler extends DiagnosticEmitter { if (this.currentFlow.isNonnull(expr, fromType)) fromType = fromType.nonNullableType; - if (!fromType.isAssignableTo(toType)) { + // Check if a converting to an Interface + if (toType.isInterface && !toType.isFunction) { + if (!fromType.isManaged || fromType.classReference == null) { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + reportNode.range, + fromType.toString(), + toType.toString()); + }else { + const _interface = (toType.classReference!); + let _class = fromType.classReference!; + let incorrectMethods = _interface.checkClass(_class); + if (incorrectMethods.length == 0) { + _interface.implementers.add(fromType.classReference!); + } else { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + reportNode.range, + fromType.toString(), + toType.toString()); + let missingMethods = false; + // tslint:disable-next-line: as-types + incorrectMethods.forEach(ifunc => { + if (_class.members == null || !_class.members.has(ifunc.name)) { + if (!missingMethods) { + missingMethods = true; + this.error( + DiagnosticCode.Class_0_incorrectly_implements_interface_1, + _class.identifierNode.range, + fromType.toString(), + toType.toString() + ); + } + this.error( + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + _class.identifierNode.range, + ifunc.name, + fromType.toString(), + toType.toString() + ); + } else { + let otherFunc = _class.members.get(ifunc.name)!; + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + otherFunc.identifierNode.range, + _class.name + "." + otherFunc.name, + _interface.name + "." + ifunc.name); + } + }); + } + + } + } + else if (!fromType.isAssignableTo(toType)) { if (!explicit) { if (fromType.nonNullableType == toType) { this.error( @@ -2959,14 +3012,6 @@ export class Compiler extends DiagnosticEmitter { } } } - // Check if a converting to an Interface - if (toType.is(TypeFlags.REFERENCE) && !toType.isFunction) { - assert(toType.classReference != null && fromType.classReference != null); - if (toType.classReference!.kind == ElementKind.INTERFACE) { - (toType.classReference!).implementers.add(fromType.classReference!); - } - - } if (fromType.is(TypeFlags.FLOAT)) { @@ -9246,7 +9291,7 @@ export class Compiler extends DiagnosticEmitter { const callIndirect = module.call_indirect( callVirtual, - func.localsByIndex.map(local => + func.localsByIndex.map((local: Local): usize => module.local_get(local.index, local.type.toNativeType()) ), Signature.makeSignatureString( @@ -9268,7 +9313,6 @@ export class Compiler extends DiagnosticEmitter { // helpers - function mangleImportName( element: Element, declaration: DeclarationStatement @@ -9345,4 +9389,3 @@ export function flatten(module: Module, stmts: ExpressionRef[], type: NativeType : type ); } - diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index abe278a10f..fbb00cd7af 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -119,6 +119,7 @@ export enum DiagnosticCode { Multiple_constructor_implementations_are_not_allowed = 2392, Duplicate_function_implementation = 2393, Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local = 2395, + Class_0_incorrectly_implements_interface_1 = 2420, A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged = 2434, The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly = 2453, Type_0_has_no_property_1 = 2460, @@ -139,6 +140,7 @@ export enum DiagnosticCode { Namespace_0_has_no_exported_member_1 = 2694, Required_type_parameters_may_not_follow_optional_type_parameters = 2706, Duplicate_property_0 = 2718, + Property_0_is_missing_in_type_1_but_required_in_type_2 = 2741, Type_0_has_no_call_signatures = 2757, File_0_not_found = 6054, Numeric_separators_are_not_allowed_here = 6188, @@ -262,6 +264,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 2392: return "Multiple constructor implementations are not allowed."; case 2393: return "Duplicate function implementation."; case 2395: return "Individual declarations in merged declaration '{0}' must be all exported or all local."; + case 2420: return "Class '{0}' incorrectly implements interface '{1}'."; case 2434: return "A namespace declaration cannot be located prior to a class or function with which it is merged."; case 2453: return "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly."; case 2460: return "Type '{0}' has no property '{1}'."; @@ -282,6 +285,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 2694: return "Namespace '{0}' has no exported member '{1}'."; case 2706: return "Required type parameters may not follow optional type parameters."; case 2718: return "Duplicate property '{0}'."; + case 2741: return "Property '{0}' is missing in type '{1}' but required in type '{2}'."; case 2757: return "Type '{0}' has no call signatures."; case 6054: return "File '{0}' not found."; case 6188: return "Numeric separators are not allowed here."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index 8ee257ddb0..2c22e20025 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -114,6 +114,7 @@ "Multiple constructor implementations are not allowed.": 2392, "Duplicate function implementation.": 2393, "Individual declarations in merged declaration '{0}' must be all exported or all local.": 2395, + "Class '{0}' incorrectly implements interface '{1}'.": 2420, "A namespace declaration cannot be located prior to a class or function with which it is merged.": 2434, "The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly.": 2453, "Type '{0}' has no property '{1}'.": 2460, @@ -134,6 +135,7 @@ "Namespace '{0}' has no exported member '{1}'.": 2694, "Required type parameters may not follow optional type parameters.": 2706, "Duplicate property '{0}'.": 2718, + "Property '{0}' is missing in type '{1}' but required in type '{2}'.": 2741, "Type '{0}' has no call signatures.": 2757, "File '{0}' not found.": 6054, diff --git a/src/program.ts b/src/program.ts index d3e8b64e82..f8a42caa33 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3158,7 +3158,7 @@ export class ClassPrototype extends DeclaredElement { /** Instance Methods */ get instanceMethods(): FunctionPrototype[] { if (!this.instanceMembers) return []; - return filter(this.instanceMembers.values(), mem => mem.kind == ElementKind.FUNCTION_PROTOTYPE); + return filter(this.instanceMembers.values(), (mem: Element): bool => mem.kind == ElementKind.FUNCTION_PROTOTYPE); } constructor( @@ -3384,8 +3384,8 @@ export class Class extends TypedElement { /** 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; - if (target.kind == ElementKind.INTERFACE) { - return (target).checkClass(this); + if (target.kind == ElementKind.INTERFACE) { + return true; } do if (current == target) return true; while (current = current.base); @@ -3648,7 +3648,8 @@ export class Interface extends Class { // FIXME get methods(): FunctionPrototype[] { if (this.members == null) return []; - return filter(this.members.values(), v => v.kind == ElementKind.FUNCTION_PROTOTYPE) + return filter(this.members.values(), + (v: DeclaredElement): bool => v.kind == ElementKind.FUNCTION_PROTOTYPE); } get methodInstances(): Function[] { @@ -3656,7 +3657,7 @@ export class Interface extends Class { // FIXME for (let func of this.methods) { if (func.instances == null) continue; map(func.instances.values(), (func: Function): void => { - if (funcs.findIndex(f => f.signature.id == func.signature.id) < 0) { + if (funcs.findIndex((f: Function): bool => f.signature.id == func.signature.id) < 0) { funcs.push(func); } }); @@ -3668,12 +3669,13 @@ export class Interface extends Class { // FIXME this.implementers.add(_class); } - checkClass(_class: Class): bool { - return this.methods.reduce((acc, ifunc) => { + checkClass(_class: Class): FunctionPrototype[] { + const res = []; + for (const ifunc of this.methods) { let func = this.getFunc(_class, ifunc); - if (func == null) return false; - return ifunc.equals(func) && acc; - }, true); + if (func == null || !(ifunc.equals(func))) res.push(ifunc); + } + return res; } private getFunc(_class: Class, ifunc: FunctionPrototype): FunctionPrototype | null { @@ -3683,8 +3685,8 @@ export class Interface extends Class { // FIXME getFuncImplementations(ifunc: Function): FunctionPrototype[] { return map(this.implementers, - _class => this.getFunc(_class, ifunc.prototype)) - .filter(func => func != null); + (_class: Class): FunctionPrototype | null => this.getFunc(_class, ifunc.prototype)) + .filter((func: FunctionPrototype): bool => func != null); } get methodsToCompile(): FunctionPrototype[] { @@ -3694,8 +3696,6 @@ export class Interface extends Class { // FIXME } return funcs; } - - } /** Registers a concrete element with a program. */ diff --git a/src/resolver.ts b/src/resolver.ts index a3ea5b542e..30d3cf64e8 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -2712,8 +2712,8 @@ export class Resolver extends DiagnosticEmitter { // Construct the instance and remember that it has been resolved already var nameInclTypeParamters = prototype.name; if (instanceKey.length) nameInclTypeParamters += "<" + instanceKey + ">"; - instance = ((prototype instanceof InterfacePrototype) ? - new Interface(nameInclTypeParamters, prototype, typeArguments, baseClass) : + instance = ((prototype instanceof InterfacePrototype) ? + new Interface(nameInclTypeParamters, prototype, typeArguments, baseClass) : new Class(nameInclTypeParamters, prototype, typeArguments, baseClass)); instance.contextualTypeArguments = ctxTypes; prototype.setResolvedInstance(instanceKey, instance); diff --git a/src/types.ts b/src/types.ts index 1266988091..6c165fd8d4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,7 +7,8 @@ import { Class, FunctionTarget, Program, - DecoratorFlags + DecoratorFlags, + ElementKind } from "./program"; import { @@ -178,6 +179,10 @@ export class Type { return signature != null && this.is(TypeFlags.REFERENCE); } + get isInterface(): bool { + return this.classReference != null && this.classReference.kind == ElementKind.INTERFACE; + } + /** Computes the sign-extending shift in the target type. */ computeSmallIntegerShift(targetType: Type): u32 { return targetType.size - this.size; diff --git a/tests/compiler/interface-fail.json b/tests/compiler/interface-fail.json index b1da366ff4..ca85490838 100644 --- a/tests/compiler/interface-fail.json +++ b/tests/compiler/interface-fail.json @@ -1,5 +1,24 @@ { "asc_flags": [ "--runtime none" - ] -} \ No newline at end of file + ], + "stderr": [ + "TS2322: Type 'interface-fail/BadFoo' is not assignable to type 'interface-fail/IFoo'.", + "const aBadFoo: IFoo = new BadFoo();", + "TS2420: Class 'interface-fail/BadFoo' incorrectly implements interface 'interface-fail/IFoo'.", + "class BadFoo implements IFoo {", + "TS2741: Property 'foo' is missing in type 'interface-fail/BadFoo' but required in type 'interface-fail/IFoo'.", + "class BadFoo implements IFoo {", + "TS2322: Type 'BadFoo.faa' is not assignable to type 'IFoo.faa'.", + "faa(i: i32, i2: i32): i32 {", + "TS2322: Type 'interface-fail/AnotherBadFoo' is not assignable to type 'interface-fail/IFoo'.", + "const anotherBadFoo: IFoo = new AnotherBadFoo();", + "TS2420: Class 'interface-fail/AnotherBadFoo' incorrectly implements interface 'interface-fail/IFoo'.", + "class AnotherBadFoo {}", + "TS2741: Property 'foo' is missing in type 'interface-fail/AnotherBadFoo' but required in type 'interface-fail/IFoo'.", + "class AnotherBadFoo {}", + "TS2741: Property 'faa' is missing in type 'interface-fail/AnotherBadFoo' but required in type 'interface-fail/IFoo'.", + "class AnotherBadFoo {}", + "TS2322: Type 'i32' is not assignable to type 'interface-fail/IFoo'.", + "const intFoo: IFoo = 5;"] + } \ No newline at end of file diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index 76c6b7b9de..0b0373f33b 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -1,14 +1,10 @@ interface IFoo { foo(i: i32): i32; + faa(i: i32, i2: i32): string; } class BadFoo implements IFoo { - i: i32 = 41; - - foo(i: i32): string { - return "hello"; - } faa(i: i32, i2: i32): i32 { return i + i2; @@ -16,7 +12,8 @@ class BadFoo implements IFoo { } +class AnotherBadFoo {} -const aFoo: IFoo = new BadFoo(); - - +const aBadFoo: IFoo = new BadFoo(); +const anotherBadFoo: IFoo = new AnotherBadFoo(); +const intFoo: IFoo = 5; diff --git a/tests/compiler/interface.json b/tests/compiler/interface.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/interface.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file From 21c0227b25afa4e08c80282095db9d724005658b Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 23 Sep 2019 12:28:09 -0400 Subject: [PATCH 12/47] Reduce number of unreachable instructions --- src/compiler.ts | 8 ++++---- tests/compiler.js | 2 +- tests/compiler/interface.optimized.wat | 20 ++++++-------------- tests/compiler/interface.untouched.wat | 10 ++++------ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 8cf7ff5f9d..be4ca63c43 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9230,7 +9230,7 @@ export class Compiler extends DiagnosticEmitter { const getArg = (i: i32): ExpressionRef => module.local_get(i, Type.i32.toNativeType()); // Condition to switch on const first = relooper.addBlockWithSwitch(module.nop(), getArg(0)); - const zero = relooper.addBlock(module.drop(module.i32(0))); + const zero = relooper.addBlock(module.nop()); for (let index: i32 = 0; index < iFuncs.length; index++) { const [funcID, classes] = iFuncs[index]; @@ -9246,15 +9246,15 @@ export class Compiler extends DiagnosticEmitter { const condition = module.binary(BinaryOp.EqI32, getArg(1), module.i32(classID)); relooper.addBranch(innerBlock, methodCase, condition); } - relooper.addBranch(innerBlock, zero, 0, module.unreachable()); + relooper.addBranch(innerBlock, zero); } - relooper.addBranchForSwitch(first, zero, [], module.unreachable()); + relooper.addBranchForSwitch(first, zero, []); var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null); const body = module.block( null, - [relooper.renderAndDispose(first, 0), module.i32(0)], + [relooper.renderAndDispose(first, 0), module.unreachable(), module.i32(0)], Type.u32.toNativeType() ); const hardCoded = this.module.i32(1); diff --git a/tests/compiler.js b/tests/compiler.js index be5bbffa66..82c0c3b772 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -142,7 +142,7 @@ function runTest(basename) { var cmd = [ basename + ".ts", "--baseDir", basedir, - // "--validate", + "--validate", "--measure", "--debug", "--textFile" // -> stdout diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index c69eb1d94a..f7f5bf8778 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -163,11 +163,11 @@ i32.add ) (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - block $switch$1$default + block $block$2$break block $switch$1$case$6 block $switch$1$case$3 local.get $0 - br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default + br_table $switch$1$case$3 $switch$1$case$6 $block$2$break end local.get $1 i32.const 3 @@ -178,14 +178,10 @@ else local.get $1 i32.const 4 - i32.eq - if - i32.const 2 - return - else - unreachable - end - unreachable + i32.ne + br_if $block$2$break + i32.const 2 + return end unreachable end @@ -202,12 +198,8 @@ if i32.const 4 return - else - unreachable end - unreachable end - unreachable end unreachable ) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 9cc1f64fa3..00d619ef6e 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -288,7 +288,7 @@ i32.const 2 return else - unreachable + br $block$2$break end unreachable end @@ -308,17 +308,15 @@ i32.const 4 return else - unreachable + br $block$2$break end unreachable end unreachable end - unreachable + br $block$2$break end - i32.const 0 - drop - i32.const 0 + unreachable ) (func $null (; 17 ;) (type $FUNCSIG$v) ) From e5d198c7147bdeac0e1423ad89e5e8185d264e47 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 23 Sep 2019 12:45:02 -0400 Subject: [PATCH 13/47] remove file [skip ci] --- tests/compiler/interface.wat | 209 ----------------------------------- 1 file changed, 209 deletions(-) delete mode 100644 tests/compiler/interface.wat diff --git a/tests/compiler/interface.wat b/tests/compiler/interface.wat deleted file mode 100644 index 13ce7eca74..0000000000 --- a/tests/compiler/interface.wat +++ /dev/null @@ -1,209 +0,0 @@ -(module - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$v (func)) - (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (memory $0 1) - (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 2 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo) - (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) - (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $interface/aFoo (mut i32) (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 48)) - (export "memory" (memory $0)) - (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - memory.size - local.set $1 - local.get $1 - i32.const 16 - i32.shl - local.set $2 - local.get $0 - local.get $2 - i32.gt_u - if - local.get $0 - local.get $2 - i32.sub - i32.const 65535 - i32.add - i32.const 65535 - i32.const -1 - i32.xor - i32.and - i32.const 16 - i32.shr_u - local.set $3 - local.get $1 - local.tee $4 - local.get $3 - local.tee $5 - local.get $4 - local.get $5 - i32.gt_s - select - local.set $4 - local.get $4 - memory.grow - i32.const 0 - i32.lt_s - if - local.get $3 - memory.grow - i32.const 0 - i32.lt_s - if - unreachable - end - end - end - local.get $0 - global.set $~lib/rt/stub/offset - ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 - i32.const 1073741808 - i32.gt_u - if - unreachable - end - global.get $~lib/rt/stub/offset - i32.const 16 - i32.add - local.set $2 - local.get $0 - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - local.tee $3 - i32.const 16 - local.tee $4 - local.get $3 - local.get $4 - i32.gt_u - select - local.set $5 - local.get $2 - local.get $5 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $2 - i32.const 16 - i32.sub - local.set $6 - local.get $6 - local.get $5 - i32.store - local.get $6 - i32.const -1 - i32.store offset=4 - local.get $6 - local.get $1 - i32.store offset=8 - local.get $6 - local.get $0 - i32.store offset=12 - local.get $2 - ) - (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - ) - (func $interface/AFoo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 4 - i32.const 3 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - i32.const 41 - i32.store - local.get $0 - ) - (func $interface/IFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - local.get $1 - i32.const 18 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iii) - ) - (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) - nop - ) - (func $interface/passAnInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) - local.get $0 - call $~lib/rt/stub/__retain - drop - local.get $0 - i32.const 1 - call $interface/IFoo#foo - i32.const 42 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 17 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $0 - call $~lib/rt/stub/__release - ) - (func $start:interface (; 8 ;) (type $FUNCSIG$v) - global.get $~lib/heap/__heap_base - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - global.set $~lib/rt/stub/startOffset - global.get $~lib/rt/stub/startOffset - global.set $~lib/rt/stub/offset - i32.const 0 - call $interface/AFoo#constructor - global.set $interface/aFoo - global.get $interface/aFoo - call $interface/passAnInterface - ) - (func $start (; 9 ;) (type $FUNCSIG$v) - call $start:interface - ) - (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add - ) - (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - i32.const 1 - ) - (func $null (; 12 ;) (type $FUNCSIG$v) - ) -) From 5fb758f82cde1c377fbba49ed0f0d9cfe17e01db Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 23 Sep 2019 19:53:13 -0400 Subject: [PATCH 14/47] Remove map and iterator usage --- src/ast.ts | 6 +++++- src/compiler.ts | 57 ++++++++++++++++++++++++++----------------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index f687f91603..ba917a7d3c 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1171,7 +1171,11 @@ export class FunctionTypeNode extends TypeNode { } get parameterTypes(): TypeNode[] { - return this.parameters.map((param: ParameterNode): TypeNode => param.type); + const res: TypeNode[] = []; + for (let i: i32 = 0 ; i < this.parameters.length; i++) { + res.push(this.parameters[i].type); + } + return res; } } diff --git a/src/compiler.ts b/src/compiler.ts index be4ca63c43..6d32484746 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2952,7 +2952,7 @@ export class Compiler extends DiagnosticEmitter { reportNode.range, fromType.toString(), toType.toString()); - }else { + } else { const _interface = (toType.classReference!); let _class = fromType.classReference!; let incorrectMethods = _interface.checkClass(_class); @@ -2966,7 +2966,8 @@ export class Compiler extends DiagnosticEmitter { toType.toString()); let missingMethods = false; // tslint:disable-next-line: as-types - incorrectMethods.forEach(ifunc => { + for (let i: i32 = 0; i < incorrectMethods.length; i++) { + const ifunc = incorrectMethods[i]; if (_class.members == null || !_class.members.has(ifunc.name)) { if (!missingMethods) { missingMethods = true; @@ -2992,7 +2993,7 @@ export class Compiler extends DiagnosticEmitter { _class.name + "." + otherFunc.name, _interface.name + "." + ifunc.name); } - }); + } } } @@ -9194,8 +9195,11 @@ export class Compiler extends DiagnosticEmitter { const instanceMethods: Map> = new Map(); const interfaceMethods: Map = new Map(); // Gather all instatiated interface methods - for (let _interface of interfaces) { - for (let func of _interface.methodInstances) { + + for (let i: i32 = 0; i < interfaces.length; i++) { + const _interface = interfaces[i]; + for (let j: i32 = 0; j < _interface.methodInstances.length; j++) { + const func = _interface.methodInstances[j]; const id = func.signature.id; if (!interfaceMethods.has(id)) { interfaceMethods.set(id, []); @@ -9205,20 +9209,18 @@ export class Compiler extends DiagnosticEmitter { instanceMethods.set(id, new Map()); } const currentMap = instanceMethods.get(id)!; - _interface.getFuncImplementations(func).map( - // tslint:disable-next-line: as-types - funcP => { - // TODO: Better way to pass contextual type info - const newFunc = this.resolver.resolveFunction(funcP, null, func.contextualTypeArguments); - if (newFunc == null) { - throw new Error(`Couldn't resolve ${funcP.name}`); - } - this.compileFunction(newFunc); - this.ensureFunctionTableEntry(newFunc); - currentMap.set((newFunc.parent).id, newFunc); - return newFunc; + const methods = _interface.getFuncImplementations(func); + for (let k: i32 = 0; k < methods.length; k++) { + const funcP = methods[k]; + // TODO: Better way to pass contextual type info + const newFunc = this.resolver.resolveFunction(funcP, null, func.contextualTypeArguments); + if (newFunc == null) { + throw new Error(`Couldn't resolve ${funcP.name}`); + } + this.compileFunction(newFunc); + this.ensureFunctionTableEntry(newFunc); + currentMap.set((newFunc.parent).id, newFunc); } - ); } } @@ -9235,7 +9237,9 @@ export class Compiler extends DiagnosticEmitter { for (let index: i32 = 0; index < iFuncs.length; index++) { const [funcID, classes] = iFuncs[index]; // Compile the interface methods with index - for (const iFunc of interfaceMethods.get(funcID)!) { + const IFuncs = interfaceMethods.get(funcID)!; + for (let i: i32 = 0; i < IFuncs.length; i++) { + const iFunc = IFuncs[i]; iFunc.finalize(module, this.compileInterfaceMethod(iFunc, index)); } const innerBlock = relooper.addBlock(module.nop()); @@ -9288,17 +9292,16 @@ export class Compiler extends DiagnosticEmitter { NativeType.I32 ); // module.removeFunction(member.internalName); + const locals: usize[] = []; + for (let i: i32 = 0; i < func.localsByIndex.length; i++) { + const local = func.localsByIndex[i]; + locals.push(module.local_get(local.index, local.type.toNativeType())); + } const callIndirect = module.call_indirect( callVirtual, - func.localsByIndex.map((local: Local): usize => - module.local_get(local.index, local.type.toNativeType()) - ), - Signature.makeSignatureString( - func.signature.parameterTypes, - func.signature.returnType, - func.signature.thisType - ) + locals, + func.signature.toSignatureString() ); const body = module.block( From 839aa137b972c43054b43d330378f5f258794a5f Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 1 Oct 2019 13:01:15 -0400 Subject: [PATCH 15/47] Type checking improved, but virtual table needs work --- src/compiler.ts | 168 ++++++++++++++++++------- tests/compiler/interface-fail.ts | 15 +++ tests/compiler/interface.optimized.wat | 105 ++-------------- tests/compiler/interface.untouched.wat | 80 +----------- 4 files changed, 152 insertions(+), 216 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 6d32484746..8f6dea5f0d 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -82,7 +82,10 @@ import { IndexSignature, File, mangleInternalName, - Interface + Interface, + TypedElement, + FieldPrototype, + DeclaredElement } from "./program"; import { @@ -2953,49 +2956,7 @@ export class Compiler extends DiagnosticEmitter { fromType.toString(), toType.toString()); } else { - const _interface = (toType.classReference!); - let _class = fromType.classReference!; - let incorrectMethods = _interface.checkClass(_class); - if (incorrectMethods.length == 0) { - _interface.implementers.add(fromType.classReference!); - } else { - this.error( - DiagnosticCode.Type_0_is_not_assignable_to_type_1, - reportNode.range, - fromType.toString(), - toType.toString()); - let missingMethods = false; - // tslint:disable-next-line: as-types - for (let i: i32 = 0; i < incorrectMethods.length; i++) { - const ifunc = incorrectMethods[i]; - if (_class.members == null || !_class.members.has(ifunc.name)) { - if (!missingMethods) { - missingMethods = true; - this.error( - DiagnosticCode.Class_0_incorrectly_implements_interface_1, - _class.identifierNode.range, - fromType.toString(), - toType.toString() - ); - } - this.error( - DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, - _class.identifierNode.range, - ifunc.name, - fromType.toString(), - toType.toString() - ); - } else { - let otherFunc = _class.members.get(ifunc.name)!; - this.error( - DiagnosticCode.Type_0_is_not_assignable_to_type_1, - otherFunc.identifierNode.range, - _class.name + "." + otherFunc.name, - _interface.name + "." + ifunc.name); - } - } - } - + this.checkInterfaceImplementation(toType, fromType, reportNode); } } else if (!fromType.isAssignableTo(toType)) { @@ -9312,6 +9273,125 @@ export class Compiler extends DiagnosticEmitter { module.removeFunction(func.internalName); return module.addFunction(func.internalName, typeRef, null, body); } + + checkInterfaceImplementation(toType: Type, fromType: Type, reportNode: Node): void { + const _interface = (toType.classReference!); + const _class = fromType.classReference!; + var imems: Map; + var mems: Map; + if (_interface.prototype.instanceMembers == null) { + return; + } else { + imems = _interface.prototype.instanceMembers; + if (_class.prototype.instanceMembers == null) { + // All members missing + + return; + } else { + mems = _class.prototype.instanceMembers; + } + } + var error = false; + var incorrectMember = false; + for (const [name, imem] of imems.entries()) { + error = error || incorrectMember; + incorrectMember = true; + let mem = mems.get(name); + if (mem == null) { + // Error! + this.error( + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + _class.identifierNode.range, + name, + _class.name, + _interface.name + ); + continue; + } + if (imem.kind != mem.kind) { + // Interfaces can't have properties + if (!(mem.kind == ElementKind.PROPERTY_PROTOTYPE && imem.kind == ElementKind.FIELD_PROTOTYPE)) { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + (mem).declaration.range, + mem.name, + name); + continue; + } + // Error + } + let from: Type = Type.void, to: Type = Type.void; + switch (mem.kind){ + case ElementKind.FIELD_PROTOTYPE: { + from = this.resolver.resolveType((mem).typeNode!, _class)!; + to = this.resolver.resolveType((imem).typeNode!, _interface)!; + break; + } + case ElementKind.FUNCTION_PROTOTYPE: { + let func = (mem); + mem.parent = _class; + imem.parent = _interface; + from = this.resolver.resolveType(func.functionTypeNode, func, _class.contextualTypeArguments)!;//, ReportMode.REPORT, false)!.type; + to = this.resolver.resolveType((imem).functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!; + break; + } + case ElementKind.PROPERTY_PROTOTYPE: { + const property = mem; + const iproperty = imem; + if (!iproperty.is(CommonFlags.READONLY)) { + if (property.setterPrototype == null) { + this.error( + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + _class.identifierNode.range, + "set " + name, + _class.name, + _interface.name + ); + error = true; + // Error + break; + } + } + if (property.getterPrototype == null) { + this.error( + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + _class.identifierNode.range, + "get " + name, + _class.name, + _interface.name + ); + continue; + // Error + } + from = this.resolver.resolveType(property.getterPrototype.functionTypeNode, property.getterPrototype, _class.contextualTypeArguments, ReportMode.REPORT)!; + to = this.resolver.resolveType((imem).typeNode!, _interface)!; + } + default: { + // Error + continue; + } + } + if (!from.isAssignableTo(to)) { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + (mem).declaration.range, + from.toString(), + to.toString() + ); + continue; + // Error + } + incorrectMember = false; + } + if (error) { + this.error( + DiagnosticCode.Class_0_incorrectly_implements_interface_1, + _class.identifierNode.range, + fromType.toString(), + toType.toString() + ); + } + } } // helpers diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index 0b0373f33b..91548b256d 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -17,3 +17,18 @@ class AnotherBadFoo {} const aBadFoo: IFoo = new BadFoo(); const anotherBadFoo: IFoo = new AnotherBadFoo(); const intFoo: IFoo = 5; + +interface Properties { + val: i32; +} + +class BadProps implements Properties { + private _val: i32 = 0; + set val(newVal: i32) { + this._val = newVal; + } +} + +const badProp = new BadProps(); + +const val = badProp.val; diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index f7f5bf8778..6dfa29d7aa 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -1,22 +1,16 @@ (module - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$ii (func (param i32) (result i32))) - (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") - (table $0 5 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) (global $interface/sFoo (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/stub/maybeGrowMemory (; 0 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -58,7 +52,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset @@ -85,48 +79,15 @@ i32.store offset=12 local.get $2 ) - (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) - local.get $0 - i32.const 1 - i32.const 0 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iii) - i32.const 42 - i32.ne - if - i32.const 0 - i32.const 24 - i32.const 37 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $0 - i32.const 1 - i32.const 3 - i32.const 1 + (func $interface/passAnInterface (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 i32.const 8 i32.sub i32.load - call $~virtual - call_indirect (type $FUNCSIG$iiii) - i32.const 4 - i32.ne - if - i32.const 0 - i32.const 24 - i32.const 38 - i32.const 2 - call $~lib/builtins/abort - unreachable - end + drop + unreachable ) - (func $start (; 4 ;) (type $FUNCSIG$v) + (func $start (; 3 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 48 global.set $~lib/rt/stub/startOffset @@ -151,59 +112,7 @@ global.get $interface/sFoo call $interface/passAnInterface ) - (func $interface/AFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add - ) - (func $interface/AFoo#faa (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - block $block$2$break - block $switch$1$case$6 - block $switch$1$case$3 - local.get $0 - br_table $switch$1$case$3 $switch$1$case$6 $block$2$break - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 1 - return - else - local.get $1 - i32.const 4 - i32.ne - br_if $block$2$break - i32.const 2 - return - end - unreachable - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 3 - return - else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 4 - return - end - end - end - unreachable - ) - (func $null (; 8 ;) (type $FUNCSIG$v) + (func $null (; 4 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 00d619ef6e..4e68e3c16d 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -8,8 +8,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 5 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) + (table $0 1 funcref) + (elem (i32.const 0) $null) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -221,29 +221,7 @@ (func $start (; 9 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add - ) - (func $interface/StructurallyImplementsIFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add - ) - (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $interface/StructurallyImplementsIFoo#faa (; 13 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $interface/IFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/IFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.const 0 @@ -254,7 +232,7 @@ call $~virtual call_indirect (type $FUNCSIG$iii) ) - (func $interface/IFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 local.get $1 local.get $2 @@ -266,58 +244,12 @@ call $~virtual call_indirect (type $FUNCSIG$iiii) ) - (func $~virtual (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~virtual (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $block$2$break - block $switch$1$default - block $switch$1$case$6 - block $switch$1$case$3 - local.get $0 - br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 1 - return - else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 2 - return - else - br $block$2$break - end - unreachable - end - unreachable - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 3 - return - else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 4 - return - else - br $block$2$break - end - unreachable - end - unreachable - end br $block$2$break end unreachable ) - (func $null (; 17 ;) (type $FUNCSIG$v) + (func $null (; 13 ;) (type $FUNCSIG$v) ) ) From 099cb111174a6688ccaef673dd1ce77bfc5e87a7 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 1 Oct 2019 18:38:06 -0400 Subject: [PATCH 16/47] Better type checking and virtual table works Still need to move logic into the interface methods. --- src/compiler.ts | 48 +++++------ tests/compiler/interface-fail.json | 48 +++++++---- tests/compiler/interface.optimized.wat | 105 +++++++++++++++++++++++-- tests/compiler/interface.untouched.wat | 80 +++++++++++++++++-- 4 files changed, 232 insertions(+), 49 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 8f6dea5f0d..9eba29b1f5 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2956,7 +2956,15 @@ export class Compiler extends DiagnosticEmitter { fromType.toString(), toType.toString()); } else { - this.checkInterfaceImplementation(toType, fromType, reportNode); + if (this.checkInterfaceImplementation(toType, fromType, reportNode)){ + (toType.classReference).implementers.add(fromType.classReference); + } else { + this.error( + DiagnosticCode.Type_0_is_not_assignable_to_type_1, + reportNode.range, + fromType.toString(), + toType.toString()); + } } } else if (!fromType.isAssignableTo(toType)) { @@ -9274,30 +9282,23 @@ export class Compiler extends DiagnosticEmitter { return module.addFunction(func.internalName, typeRef, null, body); } - checkInterfaceImplementation(toType: Type, fromType: Type, reportNode: Node): void { + checkInterfaceImplementation(toType: Type, fromType: Type, reportNode: Node): bool { const _interface = (toType.classReference!); const _class = fromType.classReference!; var imems: Map; - var mems: Map; + var mems: Map | null; if (_interface.prototype.instanceMembers == null) { - return; - } else { - imems = _interface.prototype.instanceMembers; - if (_class.prototype.instanceMembers == null) { - // All members missing - - return; - } else { - mems = _class.prototype.instanceMembers; - } + return true; } + imems = _interface.prototype.instanceMembers; + mems = _class.prototype.instanceMembers; + var error = false; var incorrectMember = false; for (const [name, imem] of imems.entries()) { error = error || incorrectMember; incorrectMember = true; - let mem = mems.get(name); - if (mem == null) { + if (mems == null || mems.get(name) == null) { // Error! this.error( DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, @@ -9308,6 +9309,7 @@ export class Compiler extends DiagnosticEmitter { ); continue; } + let mem = mems.get(name)!; if (imem.kind != mem.kind) { // Interfaces can't have properties if (!(mem.kind == ElementKind.PROPERTY_PROTOTYPE && imem.kind == ElementKind.FIELD_PROTOTYPE)) { @@ -9378,19 +9380,21 @@ export class Compiler extends DiagnosticEmitter { from.toString(), to.toString() ); - continue; - // Error - } - incorrectMember = false; + continue; + // Error + } + incorrectMember = false; } + error = error || incorrectMember;// case where contiune skips the last check. if (error) { this.error( DiagnosticCode.Class_0_incorrectly_implements_interface_1, _class.identifierNode.range, - fromType.toString(), - toType.toString() - ); + fromType.toString(), + toType.toString() + ); } + return !error; } } diff --git a/tests/compiler/interface-fail.json b/tests/compiler/interface-fail.json index ca85490838..c02bb175b9 100644 --- a/tests/compiler/interface-fail.json +++ b/tests/compiler/interface-fail.json @@ -3,22 +3,42 @@ "--runtime none" ], "stderr": [ - "TS2322: Type 'interface-fail/BadFoo' is not assignable to type 'interface-fail/IFoo'.", - "const aBadFoo: IFoo = new BadFoo();", - "TS2420: Class 'interface-fail/BadFoo' incorrectly implements interface 'interface-fail/IFoo'.", - "class BadFoo implements IFoo {", - "TS2741: Property 'foo' is missing in type 'interface-fail/BadFoo' but required in type 'interface-fail/IFoo'.", - "class BadFoo implements IFoo {", - "TS2322: Type 'BadFoo.faa' is not assignable to type 'IFoo.faa'.", - "faa(i: i32, i2: i32): i32 {", - "TS2322: Type 'interface-fail/AnotherBadFoo' is not assignable to type 'interface-fail/IFoo'.", - "const anotherBadFoo: IFoo = new AnotherBadFoo();", - "TS2420: Class 'interface-fail/AnotherBadFoo' incorrectly implements interface 'interface-fail/IFoo'.", + "TS2741: Property 'foo' is missing in type 'BadFoo' but required in type 'IFoo'.", + "class BadFoo implements IFoo {", + + "TS2322: Type '(i: i32, i2: i32) => i32' is not assignable to type '(i: i32, i2: i32) => ~lib/string/String'.", + "class BadFoo implements IFoo {", + + "TS2420: Class 'interface-fail/BadFoo' incorrectly implements interface 'interface-fail/IFoo'.", + "class BadFoo implements IFoo {", + + "TS2322: Type 'interface-fail/BadFoo' is not assignable to type 'interface-fail/IFoo'.", + "const aBadFoo: IFoo = new BadFoo();", + + "TS2741: Property 'foo' is missing in type 'AnotherBadFoo' but required in type 'IFoo'.", "class AnotherBadFoo {}", - "TS2741: Property 'foo' is missing in type 'interface-fail/AnotherBadFoo' but required in type 'interface-fail/IFoo'.", + + "TS2741: Property 'faa' is missing in type 'AnotherBadFoo' but required in type 'IFoo'.", "class AnotherBadFoo {}", - "TS2741: Property 'faa' is missing in type 'interface-fail/AnotherBadFoo' but required in type 'interface-fail/IFoo'.", + + "TS2420: Class 'interface-fail/AnotherBadFoo' incorrectly implements interface 'interface-fail/IFoo'.", "class AnotherBadFoo {}", + + "TS2322: Type 'interface-fail/AnotherBadFoo' is not assignable to type 'interface-fail/IFoo'.", + "const anotherBadFoo: IFoo = new AnotherBadFoo();", + "TS2322: Type 'i32' is not assignable to type 'interface-fail/IFoo'.", - "const intFoo: IFoo = 5;"] + "const intFoo: IFoo = 5;", + + "TS2741: Property 'get val' is missing in type 'BadProps' but required in type 'Properties'.", + "class BadProps implements Properties {", + + "TS2420: Class 'interface-fail/BadProps' incorrectly implements interface 'interface-fail/Properties'.", + "class BadProps implements Properties {", + + "TS2322: Type 'interface-fail/BadProps' is not assignable to type 'interface-fail/Properties'.", + "const badProp = new BadProps();" + + +] } \ No newline at end of file diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 6dfa29d7aa..f7f5bf8778 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -1,16 +1,22 @@ (module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (type $FUNCSIG$ii (func (param i32) (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") + (table $0 5 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) (global $interface/sFoo (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 0 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -52,7 +58,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset @@ -79,15 +85,48 @@ i32.store offset=12 local.get $2 ) - (func $interface/passAnInterface (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + i32.const 1 + i32.const 0 local.get $0 i32.const 8 i32.sub i32.load - drop - unreachable + call $~virtual + call_indirect (type $FUNCSIG$iii) + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 37 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 1 + i32.const 3 + i32.const 1 + local.get $0 + i32.const 8 + i32.sub + i32.load + call $~virtual + call_indirect (type $FUNCSIG$iiii) + i32.const 4 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 38 + i32.const 2 + call $~lib/builtins/abort + unreachable + end ) - (func $start (; 3 ;) (type $FUNCSIG$v) + (func $start (; 4 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 48 global.set $~lib/rt/stub/startOffset @@ -112,7 +151,59 @@ global.get $interface/sFoo call $interface/passAnInterface ) - (func $null (; 4 ;) (type $FUNCSIG$v) + (func $interface/AFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface/AFoo#faa (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + block $block$2$break + block $switch$1$case$6 + block $switch$1$case$3 + local.get $0 + br_table $switch$1$case$3 $switch$1$case$6 $block$2$break + end + local.get $1 + i32.const 3 + i32.eq + if + i32.const 1 + return + else + local.get $1 + i32.const 4 + i32.ne + br_if $block$2$break + i32.const 2 + return + end + unreachable + end + local.get $1 + i32.const 3 + i32.eq + if + i32.const 3 + return + else + local.get $1 + i32.const 4 + i32.eq + if + i32.const 4 + return + end + end + end + unreachable + ) + (func $null (; 8 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 4e68e3c16d..00d619ef6e 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -8,8 +8,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 1 funcref) - (elem (i32.const 0) $null) + (table $0 5 funcref) + (elem (i32.const 0) $null $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -221,7 +221,29 @@ (func $start (; 9 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/IFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface/StructurallyImplementsIFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface/StructurallyImplementsIFoo#faa (; 13 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface/IFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.const 0 @@ -232,7 +254,7 @@ call $~virtual call_indirect (type $FUNCSIG$iii) ) - (func $interface/IFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 local.get $1 local.get $2 @@ -244,12 +266,58 @@ call $~virtual call_indirect (type $FUNCSIG$iiii) ) - (func $~virtual (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~virtual (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $block$2$break + block $switch$1$default + block $switch$1$case$6 + block $switch$1$case$3 + local.get $0 + br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default + end + local.get $1 + i32.const 3 + i32.eq + if + i32.const 1 + return + else + local.get $1 + i32.const 4 + i32.eq + if + i32.const 2 + return + else + br $block$2$break + end + unreachable + end + unreachable + end + local.get $1 + i32.const 3 + i32.eq + if + i32.const 3 + return + else + local.get $1 + i32.const 4 + i32.eq + if + i32.const 4 + return + else + br $block$2$break + end + unreachable + end + unreachable + end br $block$2$break end unreachable ) - (func $null (; 13 ;) (type $FUNCSIG$v) + (func $null (; 17 ;) (type $FUNCSIG$v) ) ) From 712d4001204f78124bfee1058a9d1a09b568ba05 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 2 Oct 2019 12:31:05 -0400 Subject: [PATCH 17/47] Add from to portable definition Soon to add iterator --- src/compiler.ts | 4 ++-- std/portable/index.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 9eba29b1f5..56a258f99e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -2956,7 +2956,7 @@ export class Compiler extends DiagnosticEmitter { fromType.toString(), toType.toString()); } else { - if (this.checkInterfaceImplementation(toType, fromType, reportNode)){ + if (this.checkInterfaceImplementation(toType, fromType, reportNode)) { (toType.classReference).implementers.add(fromType.classReference); } else { this.error( @@ -9292,7 +9292,7 @@ export class Compiler extends DiagnosticEmitter { } imems = _interface.prototype.instanceMembers; mems = _class.prototype.instanceMembers; - + var error = false; var incorrectMember = false; for (const [name, imem] of imems.entries()) { diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index 2a589b72fe..0cf2e1ec2b 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -379,7 +379,7 @@ declare class DataView { declare class Array { static isArray(value: any): value is Array; - + static from(iter: Iterable): Array; [key: number]: T; length: i32; constructor(capacity?: i32); From b7e592bba9e6e68974c19c8df9a7dca2e2bfdf86 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 2 Dec 2019 11:56:58 -0500 Subject: [PATCH 18/47] Added Properties and Fields --- src/compiler.ts | 125 ++++++++++++++++++++----- src/program.ts | 51 +++++++++- src/resolver.ts | 1 + src/util/collections.ts | 4 + tests/compiler/interface-fail.ts | 30 ++++-- tests/compiler/interface.optimized.wat | 125 ++++++++++++++++++++----- tests/compiler/interface.ts | 13 ++- tests/compiler/interface.untouched.wat | 100 ++++++++++++++++---- 8 files changed, 370 insertions(+), 79 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index b0aa11e6cd..8604d2f048 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1152,6 +1152,12 @@ export class Compiler extends DiagnosticEmitter { return typeRef; } + ensureSignature(signature: Signature): FunctionTypeRef { + return this.ensureFunctionType(signature.parameterTypes, + signature.returnType, + signature.thisType); + } + /** Either reuses or creates the event type matching the specified name. */ ensureEventType( name: string, @@ -9168,6 +9174,7 @@ export class Compiler extends DiagnosticEmitter { for (let i: i32 = 0; i < interfaces.length; i++) { const _interface = interfaces[i]; + this.compileInterfaceProperties(_interface); for (let j: i32 = 0; j < _interface.methodInstances.length; j++) { const func = _interface.methodInstances[j]; const id = func.signature.id; @@ -9198,7 +9205,6 @@ export class Compiler extends DiagnosticEmitter { // Create relooper to build table const relooper = this.module.createRelooper(); const iFuncs: [number, Map][] = Array.from(instanceMethods.entries()); - const methodBlocks: RelooperBlockRef[] = []; const getArg = (i: i32): ExpressionRef => module.local_get(i, Type.i32.toNativeType()); // Condition to switch on const first = relooper.addBlockWithSwitch(module.nop(), getArg(0)); @@ -9231,7 +9237,6 @@ export class Compiler extends DiagnosticEmitter { [relooper.renderAndDispose(first, 0), module.unreachable(), module.i32(0)], Type.u32.toNativeType() ); - const hardCoded = this.module.i32(1); this.module.addFunction("~virtual", typeRef, null, body); } @@ -9239,26 +9244,13 @@ export class Compiler extends DiagnosticEmitter { compileInterfaceMethod(func: Function, methodID: i32): ExpressionRef { const signature = func.signature; const module = this.module; - const typeRef = this.ensureFunctionType( - signature.parameterTypes, - signature.returnType, - signature.thisType - ); + const typeRef = this.ensureSignature(signature); const loadMethodID = module.i32(methodID); // let target = this.compiler.program.instancesByName("virtual"); - const loadClass = module.load( - 4, - false, - module.binary( - BinaryOp.SubI32, - module.local_get(0, NativeType.I32), - module.i32(8) - ), - NativeType.I32 - ); + const callVirtual = module.call( "~virtual", - [loadMethodID, loadClass], + [loadMethodID, loadClassID(module)], NativeType.I32 ); // module.removeFunction(member.internalName); @@ -9313,7 +9305,8 @@ export class Compiler extends DiagnosticEmitter { let mem = mems.get(name)!; if (imem.kind != mem.kind) { // Interfaces can't have properties - if (!(mem.kind == ElementKind.PROPERTY_PROTOTYPE && imem.kind == ElementKind.FIELD_PROTOTYPE)) { + if ((mem.kind != ElementKind.PROPERTY_PROTOTYPE && mem.kind != ElementKind.FIELD_PROTOTYPE) && + (imem.kind == ElementKind.PROPERTY)) { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, (mem).declaration.range, @@ -9324,10 +9317,10 @@ export class Compiler extends DiagnosticEmitter { // Error } let from: Type = Type.void, to: Type = Type.void; - switch (mem.kind){ + switch (mem.kind) { case ElementKind.FIELD_PROTOTYPE: { from = this.resolver.resolveType((mem).typeNode!, _class)!; - to = this.resolver.resolveType((imem).typeNode!, _interface)!; + to = this.resolver.resolveType((imem).getterPrototype!.functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!.signatureReference!.returnType; break; } case ElementKind.FUNCTION_PROTOTYPE: { @@ -9340,7 +9333,7 @@ export class Compiler extends DiagnosticEmitter { } case ElementKind.PROPERTY_PROTOTYPE: { const property = mem; - const iproperty = imem; + const iproperty = imem; if (!iproperty.is(CommonFlags.READONLY)) { if (property.setterPrototype == null) { this.error( @@ -9367,7 +9360,8 @@ export class Compiler extends DiagnosticEmitter { // Error } from = this.resolver.resolveType(property.getterPrototype.functionTypeNode, property.getterPrototype, _class.contextualTypeArguments, ReportMode.REPORT)!; - to = this.resolver.resolveType((imem).typeNode!, _interface)!; + to = this.resolver.resolveType(iproperty.getterPrototype!.functionTypeNode, iproperty.getterPrototype!, _interface.contextualTypeArguments, ReportMode.REPORT)!; + break; } default: { // Error @@ -9397,12 +9391,97 @@ export class Compiler extends DiagnosticEmitter { } return !error; } + + compileInterfaceProperties(_interface: Interface): void { + const module = this.module; + const iprops = _interface.props; + const classes = Array.from(_interface.implementers); + + for (let i = 0; i < iprops.length; i++) { + const iprop = iprops[i]; + const returnType = iprop.getterInstance!.signature.returnType.toNativeType(); + const typeRef = this.ensureSignature(iprop.getterInstance!.signature); + + const relooper = this.module.createRelooper(); + + // Condition to switch on + const first = relooper.addBlock(module.local_set(1, loadClassID(module))); + const last = relooper.addBlock(module.unreachable()); + relooper.addBranch(first, last); + for (let c = 0; c < classes.length; c ++) { + const _class = classes[c]; + const prop = _class.members!.get(iprop.name)!; + let expr: ExpressionRef; + let thisExpr = loadClassArg(module, 0); + if (prop.kind == ElementKind.PROPERTY) { + let p = prop; + let getter = p.getterInstance!; + this.compileFunction(getter); + expr = module.call(getter.internalName, [thisExpr], getter.signature.returnType.toNativeType()); + }else if(prop.kind == ElementKind.FIELD) { + let target = prop; + assert((target).memoryOffset >= 0); + this.currentType = (target).type; + expr = module.load( + (target).type.byteSize, + (target).type.is(TypeFlags.SIGNED | TypeFlags.INTEGER), + thisExpr, + (target).type.toNativeType(), + (target).memoryOffset) + } else { + throw Error("Class " + classes[c].name + " must have property " + prop.name); + } + const returnBlock = relooper.addBlock(expr); + const loadLocal = loadClassArg(module, 1); + const classID = module.i32(_class.id); + relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); + } + // Remove the nop standin + module.removeFunction(iprop.getterInstance!.internalName); + module.addFunction(iprop.getterInstance!.internalName, typeRef, [NativeType.I32], relooper.renderAndDispose(first, 0)); + } + } } // helpers const v128_zero = new Uint8Array(16); +/* Useful for adding to the end of a block that needs a type even if there is an unreachable(); */ +export function defaulType(nativeType: NativeType, module: Module): ExpressionRef { + switch(nativeType){ + case NativeType.I64: return module.i64(0); + case NativeType.F32: return module.f32(0); + case NativeType.F64: return module.f64(0); + case NativeType.V128: return module.v128(new Uint8Array); + case NativeType.I32: + case NativeType.Anyref: + case NativeType.Auto: + default: { + return module.i32(0); + } + + } + +} + +function loadClassArg(module: Module, index: number): ExpressionRef { + return module.local_get(index, Type.i32.toNativeType()); +} + +function loadClassID(module: Module): ExpressionRef { + return module.load( + 4, + false, + module.binary( + BinaryOp.SubI32, + module.local_get(0, NativeType.I32), + module.i32(8) + ), + NativeType.I32 + ); +} + function mangleImportName( element: Element, declaration: DeclarationStatement diff --git a/src/program.ts b/src/program.ts index e20b9ad17b..9748f62cfc 100644 --- a/src/program.ts +++ b/src/program.ts @@ -76,7 +76,8 @@ import { ExportDefaultStatement, Token, - ParameterNode + ParameterNode, + ParameterKind } from "./ast"; import { @@ -92,7 +93,8 @@ import { writeF32, writeF64, filter, - map + map, + notNull } from "./util"; import { @@ -1841,8 +1843,29 @@ export class Program extends DiagnosticEmitter { ); if (!parent.add(name, element)) return null; var memberDeclarations = declaration.members; + var instanceDeclarations = new Array(); + /** + * Must convert field declarations to property declarations + */ for (let i = 0, k = memberDeclarations.length; i < k; ++i) { let memberDeclaration = memberDeclarations[i]; + if (memberDeclaration.kind == NodeKind.FIELDDECLARATION){ + let fieldDecl = memberDeclaration; + if (!fieldDecl.is(CommonFlags.READONLY)){ + const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range) + const signature = Node.createFunctionType([param], Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); + instanceDeclarations.push(Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range)); + } + const signature = Node.createFunctionType([], fieldDecl.type || Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); + memberDeclaration = Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range); + }else if (memberDeclaration.kind == NodeKind.METHODDECLARATION && + (memberDeclaration.is(CommonFlags.GET) || memberDeclaration.is(CommonFlags.SET))) { + //TODO check that you can't have a property in an interface + } + instanceDeclarations.push(memberDeclaration); + } + for (let i = 0, k = instanceDeclarations.length; i < k; ++i) { + let memberDeclaration = instanceDeclarations[i]; switch (memberDeclaration.kind) { case NodeKind.FIELDDECLARATION: { this.initializeField(memberDeclaration, element); @@ -3688,12 +3711,21 @@ export class Interface extends Class { // FIXME ); } + get memberValues(): Iterable { + if (this.members != null) return this.members.values(); + return []; + } + get methods(): FunctionPrototype[] { if (this.members == null) return []; return filter(this.members.values(), (v: DeclaredElement): bool => v.kind == ElementKind.FUNCTION_PROTOTYPE); } + get props(): Property[] { + return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY); + } + get methodInstances(): Function[] { var funcs: Function[] = []; for (let func of this.methods) { @@ -3725,10 +3757,19 @@ export class Interface extends Class { // FIXME return _class.members.get(ifunc.name); } + private getProp(_class: Class, iprop: PropertyPrototype): PropertyPrototype | null { + if (_class.members == null) return null; + return _class.members.get(iprop.name); + } + + getPropImplementations(iprop: Property): PropertyPrototype[] { + return map(this.implementers, _class => this.getProp(_class, iprop.prototype)) + .filter(notNull); + } + getFuncImplementations(ifunc: Function): FunctionPrototype[] { - return map(this.implementers, - (_class: Class): FunctionPrototype | null => this.getFunc(_class, ifunc.prototype)) - .filter((func: FunctionPrototype): bool => func != null); + return map(this.implementers, _class => this.getFunc(_class, ifunc.prototype)) + .filter(notNull); } get methodsToCompile(): FunctionPrototype[] { diff --git a/src/resolver.ts b/src/resolver.ts index 49fb32e9a6..1c7c40cf40 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -1378,6 +1378,7 @@ export class Resolver extends DiagnosticEmitter { // Look up the member within switch (target.kind) { case ElementKind.CLASS_PROTOTYPE: + case ElementKind.INTERFACE: case ElementKind.CLASS: { do { let members = target.members; diff --git a/src/util/collections.ts b/src/util/collections.ts index f9cfbdbd52..2470f7072b 100644 --- a/src/util/collections.ts +++ b/src/util/collections.ts @@ -43,3 +43,7 @@ export function map(iter: Iterable, func: (t: T) => R): R[] { } return res; } + +export function notNull(t: T): bool { + return t != null; +} diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index 91548b256d..b5f6004fbc 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -1,11 +1,16 @@ -interface IFoo { +interface IFooBad { foo(i: i32): i32; faa(i: i32, i2: i32): string; } -class BadFoo implements IFoo { - +class BadFoo implements IFooBad { + /** + Property 'faa' in type 'BadFoo' is not assignable to the same property in base type 'IFooBad'. + Type '(i: number, i2: number) => number' is not assignable to type '(i: number, i2: number) => string'. + Type 'number' is not assignable to type 'string'. + */ + //@ts-ignore faa(i: i32, i2: i32): i32 { return i + i2; } @@ -13,10 +18,21 @@ class BadFoo implements IFoo { } class AnotherBadFoo {} - -const aBadFoo: IFoo = new BadFoo(); -const anotherBadFoo: IFoo = new AnotherBadFoo(); -const intFoo: IFoo = 5; +/** + Property 'foo' is missing in type 'BadFoo' but required in type 'IFooBad'. + */ +//@ts-ignore +const aBadFoo: IFooBad = new BadFoo(); +/* + Type 'AnotherBadFoo' is missing the following properties from type 'IFooBad': foo, faa +*/ +//@ts-ignore +const anotherBadFoo: IFooBad = new AnotherBadFoo(); +/* + Type 'number' is not assignable to type 'IFooBad'. +*/ +//@ts-ignore +const intFoo: IFooBad = 5; interface Properties { val: i32; diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index f7f5bf8778..3567e7b7bf 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -1,15 +1,16 @@ (module (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") - (table $0 5 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) + (table $0 6 funcref) + (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -58,32 +59,50 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end global.get $~lib/rt/stub/offset i32.const 16 i32.add + local.tee $3 + local.get $0 + i32.const 15 + i32.add + i32.const -16 + i32.and local.tee $2 i32.const 16 + local.get $2 + i32.const 16 + i32.gt_u + select + local.tee $4 i32.add call $~lib/rt/stub/maybeGrowMemory - local.get $2 + local.get $3 i32.const 16 i32.sub - local.tee $1 - i32.const 16 + local.tee $2 + local.get $4 i32.store - local.get $1 + local.get $2 i32.const -1 i32.store offset=4 + local.get $2 local.get $1 - local.get $0 i32.store offset=8 - local.get $1 - i32.const 4 - i32.store offset=12 local.get $2 + local.get $0 + i32.store offset=12 + local.get $3 ) (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 @@ -100,7 +119,7 @@ if i32.const 0 i32.const 24 - i32.const 37 + i32.const 41 i32.const 2 call $~lib/builtins/abort unreachable @@ -120,18 +139,37 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $interface/expectX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $interface/IFoo#get:x + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 49 i32.const 2 call $~lib/builtins/abort unreachable end ) - (func $start (; 4 ;) (type $FUNCSIG$v) + (func $start:interface (; 5 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 48 global.set $~lib/rt/stub/startOffset i32.const 48 global.set $~lib/rt/stub/offset + i32.const 4 i32.const 3 call $~lib/rt/stub/__alloc local.tee $0 @@ -139,30 +177,69 @@ i32.store local.get $0 global.set $interface/aFoo + i32.const 5 i32.const 4 call $~lib/rt/stub/__alloc local.tee $0 i32.const 41 i32.store local.get $0 + i32.const 0 + i32.store8 offset=4 + local.get $0 global.set $interface/sFoo global.get $interface/aFoo call $interface/passAnInterface global.get $interface/sFoo call $interface/passAnInterface + global.get $interface/aFoo + i32.const 1 + call $interface/expectX + global.get $interface/sFoo + i32.const 0 + call $interface/expectX + ) + (func $start (; 6 ;) (type $FUNCSIG$v) + call $start:interface ) - (func $interface/AFoo#foo (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#get:x (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface/IFoo#get:x (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load8_u offset=4 + else + unreachable + end + end + ) + (func $interface/AFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/AFoo#faa (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/AFoo#faa (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $block$2$break block $switch$1$case$6 block $switch$1$case$3 @@ -173,14 +250,14 @@ i32.const 3 i32.eq if - i32.const 1 + i32.const 2 return else local.get $1 i32.const 4 i32.ne br_if $block$2$break - i32.const 2 + i32.const 3 return end unreachable @@ -189,21 +266,21 @@ i32.const 3 i32.eq if - i32.const 3 + i32.const 4 return else local.get $1 i32.const 4 i32.eq if - i32.const 4 + i32.const 5 return end end end unreachable ) - (func $null (; 8 ;) (type $FUNCSIG$v) + (func $null (; 12 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index fbeb938a39..53ea21f38f 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -2,10 +2,13 @@ interface IFoo { foo(i: i32): i32; faa(i: i32, i2: i32): i32; + readonly x: bool; } class AFoo implements IFoo { i: i32 = 41; + get x(): bool{ return true; } + set x(b: bool){} foo(i: i32): i32 { return this.i + i; @@ -19,7 +22,8 @@ class AFoo implements IFoo { class StructurallyImplementsIFoo { i: i32 = 41; - + x: bool = false; + foo(i: i32): i32 { return this.i + i; } @@ -40,3 +44,10 @@ function passAnInterface(foo: IFoo): void { passAnInterface(aFoo); passAnInterface(sFoo); + +function expectX(foo: IFoo, x: bool): void { + assert(foo.x == x); +} + +expectX(aFoo, true); +expectX(sFoo, false); diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 282ae7fea1..5120879643 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -4,12 +4,13 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 5 funcref) - (elem (i32.const 0) $null $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) + (table $0 6 funcref) + (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -146,7 +147,7 @@ local.get $0 i32.eqz if - i32.const 4 + i32.const 5 i32.const 4 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain @@ -156,6 +157,9 @@ i32.const 41 i32.store local.get $0 + i32.const 0 + i32.store8 offset=4 + local.get $0 ) (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) nop @@ -173,7 +177,7 @@ if i32.const 0 i32.const 24 - i32.const 37 + i32.const 41 i32.const 2 call $~lib/builtins/abort unreachable @@ -188,7 +192,31 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $interface/expectX (; 8 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $interface/IFoo#get:x + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 49 i32.const 2 call $~lib/builtins/abort unreachable @@ -196,7 +224,7 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:interface (; 8 ;) (type $FUNCSIG$v) + (func $start:interface (; 9 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -217,33 +245,67 @@ call $interface/passAnInterface global.get $interface/sFoo call $interface/passAnInterface + global.get $interface/aFoo + i32.const 1 + call $interface/expectX + global.get $interface/sFoo + i32.const 0 + call $interface/expectX ) - (func $start (; 9 ;) (type $FUNCSIG$v) + (func $start (; 10 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#get:x (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface/IFoo#get:x (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface/AFoo#get:x + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load8_u offset=4 + else + unreachable + end + end + ) + (func $interface/AFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/StructurallyImplementsIFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/AFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/StructurallyImplementsIFoo#faa (; 13 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/IFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/IFoo#foo (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.const 0 @@ -254,7 +316,7 @@ call $~virtual call_indirect (type $FUNCSIG$iii) ) - (func $interface/IFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 local.get $1 local.get $2 @@ -266,7 +328,7 @@ call $~virtual call_indirect (type $FUNCSIG$iiii) ) - (func $~virtual (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~virtual (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) block $block$2$break block $switch$1$default block $switch$1$case$6 @@ -278,14 +340,14 @@ i32.const 3 i32.eq if - i32.const 1 + i32.const 2 return else local.get $1 i32.const 4 i32.eq if - i32.const 2 + i32.const 3 return else br $block$2$break @@ -298,14 +360,14 @@ i32.const 3 i32.eq if - i32.const 3 + i32.const 4 return else local.get $1 i32.const 4 i32.eq if - i32.const 4 + i32.const 5 return else br $block$2$break @@ -318,6 +380,6 @@ end unreachable ) - (func $null (; 17 ;) (type $FUNCSIG$v) + (func $null (; 20 ;) (type $FUNCSIG$v) ) ) From 694d77ee7693f732ef25a984d5c1769996d1f302 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 2 Dec 2019 12:26:11 -0500 Subject: [PATCH 19/47] Removed virtual table function Now each interface method handles the class switch --- src/compiler.ts | 177 +++++++++---------------- tests/compiler/interface.optimized.wat | 108 ++++++++------- tests/compiler/interface.untouched.wat | 121 +++++++---------- 3 files changed, 169 insertions(+), 237 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 8604d2f048..cb890dc064 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -460,7 +460,7 @@ export class Compiler extends DiagnosticEmitter { if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory); // set up virtual table - this.compileVirtualTable(); + this.compileInterfaces(); // set up function table var functionTable = this.functionTable; @@ -9165,116 +9165,6 @@ export class Compiler extends DiagnosticEmitter { return module.block(label, conditions, NativeType.I32); } - compileVirtualTable(): void { - const interfaces = this.program.interfaces; - if (interfaces.length == 0) return; //Don't create table if no interfaces present - const instanceMethods: Map> = new Map(); - const interfaceMethods: Map = new Map(); - // Gather all instatiated interface methods - - for (let i: i32 = 0; i < interfaces.length; i++) { - const _interface = interfaces[i]; - this.compileInterfaceProperties(_interface); - for (let j: i32 = 0; j < _interface.methodInstances.length; j++) { - const func = _interface.methodInstances[j]; - const id = func.signature.id; - if (!interfaceMethods.has(id)) { - interfaceMethods.set(id, []); - } - interfaceMethods.get(id)!.push(func); - if (!instanceMethods.has(id)) { - instanceMethods.set(id, new Map()); - } - const currentMap = instanceMethods.get(id)!; - const methods = _interface.getFuncImplementations(func); - for (let k: i32 = 0; k < methods.length; k++) { - const funcP = methods[k]; - // TODO: Better way to pass contextual type info - const newFunc = this.resolver.resolveFunction(funcP, null, func.contextualTypeArguments); - if (newFunc == null) { - throw new Error(`Couldn't resolve ${funcP.name}`); - } - this.compileFunction(newFunc); - this.ensureFunctionTableEntry(newFunc); - currentMap.set((newFunc.parent).id, newFunc); - } - } - } - - const module = this.module; - // Create relooper to build table - const relooper = this.module.createRelooper(); - const iFuncs: [number, Map][] = Array.from(instanceMethods.entries()); - const getArg = (i: i32): ExpressionRef => module.local_get(i, Type.i32.toNativeType()); - // Condition to switch on - const first = relooper.addBlockWithSwitch(module.nop(), getArg(0)); - const zero = relooper.addBlock(module.nop()); - - for (let index: i32 = 0; index < iFuncs.length; index++) { - const [funcID, classes] = iFuncs[index]; - // Compile the interface methods with index - const IFuncs = interfaceMethods.get(funcID)!; - for (let i: i32 = 0; i < IFuncs.length; i++) { - const iFunc = IFuncs[i]; - iFunc.finalize(module, this.compileInterfaceMethod(iFunc, index)); - } - const innerBlock = relooper.addBlock(module.nop()); - // Add brach for method - relooper.addBranchForSwitch(first, innerBlock, [index]); - for (const [classID, func] of classes.entries()) { - const methodCase = relooper.addBlock(module.return(module.i32(func.functionTableIndex))); - const condition = module.binary(BinaryOp.EqI32, getArg(1), module.i32(classID)); - relooper.addBranch(innerBlock, methodCase, condition); - } - relooper.addBranch(innerBlock, zero); - } - relooper.addBranchForSwitch(first, zero, []); - - var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null); - - const body = module.block( - null, - [relooper.renderAndDispose(first, 0), module.unreachable(), module.i32(0)], - Type.u32.toNativeType() - ); - this.module.addFunction("~virtual", typeRef, null, body); - - } - - compileInterfaceMethod(func: Function, methodID: i32): ExpressionRef { - const signature = func.signature; - const module = this.module; - const typeRef = this.ensureSignature(signature); - const loadMethodID = module.i32(methodID); - // let target = this.compiler.program.instancesByName("virtual"); - - const callVirtual = module.call( - "~virtual", - [loadMethodID, loadClassID(module)], - NativeType.I32 - ); - // module.removeFunction(member.internalName); - const locals: usize[] = []; - for (let i: i32 = 0; i < func.localsByIndex.length; i++) { - const local = func.localsByIndex[i]; - locals.push(module.local_get(local.index, local.type.toNativeType())); - } - - const callIndirect = module.call_indirect( - callVirtual, - locals, - func.signature.toSignatureString() - ); - - const body = module.block( - null, - [callIndirect], - func.signature.returnType.toNativeType() - ); - module.removeFunction(func.internalName); - return module.addFunction(func.internalName, typeRef, null, body); - } - checkInterfaceImplementation(toType: Type, fromType: Type, reportNode: Node): bool { const _interface = (toType.classReference!); const _class = fromType.classReference!; @@ -9392,6 +9282,71 @@ export class Compiler extends DiagnosticEmitter { return !error; } + compileInterfaces(): void { + const interfaces = this.program.interfaces; + for (let i: i32 = 0; i < interfaces.length; i++) { + const _interface = interfaces[i]; + this.compileInterfaceProperties(_interface); + this.compileInterfaceMethods(_interface); + } + } + + compileInterfaceMethods(_interface: Interface): void { + const module = this.module; + const ifuncs = _interface.methodInstances; + const classes = Array.from(_interface.implementers); + + for (let i = 0; i < ifuncs.length; i++) { + const ifunc = ifuncs[i]; + const classIDLocal = ifunc.addLocal(Type.i32); + const returnType = ifunc!.signature.returnType.toNativeType(); + const typeRef = this.ensureSignature(ifunc!.signature); + + const relooper = this.module.createRelooper(); + + // Condition to switch on + const first = relooper.addBlock(module.local_set(classIDLocal.index, loadClassID(module))); + const last = relooper.addBlock(module.unreachable()); + relooper.addBranch(first, last); + + for (let c = 0; c < classes.length; c ++) { + const _class = classes[c]; + let prop = _class.members!.get(ifunc.name)!; + let expr: ExpressionRef; + let thisExpr = loadClassArg(module, 0); + switch (prop.kind){ + case ElementKind.FUNCTION_PROTOTYPE: { + let p = prop; + let newFunc = this.resolver.resolveFunction(p, null, ifunc.contextualTypeArguments); + if (newFunc == null) { + throw new Error(`Couldn't resolve ${p.name}`); + } + prop = newFunc; + } + case ElementKind.FUNCTION:{ + this.compileFunction( prop); + break + } + default: + throw Error("Class " + classes[c].name + " must have property " + prop.name); + } + const locals: usize[] = []; + for (let i: i32 = 0; i < classIDLocal.index; i++) { + const local = ifunc.localsByIndex[i]; + locals.push(module.local_get(local.index, local.type.toNativeType())); + } + const callExpr = module.call(prop.internalName, locals, returnType) + const returnBlock = relooper.addBlock(callExpr); + const loadLocal = loadClassArg(module, classIDLocal.index); + const classID = module.i32(_class.id); + relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); + } + // Remove the nop standin + module.removeFunction(ifunc.internalName); + module.addFunction(ifunc.internalName, typeRef, [NativeType.I32], relooper.renderAndDispose(first, 0)); + } + } + compileInterfaceProperties(_interface: Interface): void { const module = this.module; const iprops = _interface.props; diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 3567e7b7bf..879f292373 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -9,8 +9,6 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s") - (table $0 6 funcref) - (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/AFoo#foo $interface/AFoo#faa $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -106,14 +104,7 @@ ) (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - i32.const 1 - i32.const 0 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iii) + call $interface/IFoo#foo i32.const 42 i32.ne if @@ -125,15 +116,7 @@ unreachable end local.get $0 - i32.const 1 - i32.const 3 - i32.const 1 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iiii) + call $interface/IFoo#faa i32.const 4 i32.ne if @@ -234,53 +217,66 @@ local.get $1 i32.add ) - (func $interface/AFoo#faa (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#foo (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + call $interface/AFoo#foo + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + call $interface/AFoo#foo + else + unreachable + end + end + ) + (func $interface/AFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $~virtual (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - block $block$2$break - block $switch$1$case$6 - block $switch$1$case$3 - local.get $0 - br_table $switch$1$case$3 $switch$1$case$6 $block$2$break - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 2 - return - else - local.get $1 - i32.const 4 - i32.ne - br_if $block$2$break - i32.const 3 - return - end - unreachable - end - local.get $1 + (func $interface/IFoo#faa (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + i32.const 1 i32.const 3 + call $interface/AFoo#faa + else + local.get $1 + i32.const 4 i32.eq - if - i32.const 4 - return + if (result i32) + local.get $0 + i32.const 1 + i32.const 3 + call $interface/AFoo#faa else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 5 - return - end + unreachable end end - unreachable ) - (func $null (; 12 ;) (type $FUNCSIG$v) + (func $null (; 13 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 5120879643..1398e6ee1d 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -9,8 +9,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 6 funcref) - (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/StructurallyImplementsIFoo#foo $interface/AFoo#faa $interface/StructurallyImplementsIFoo#faa) + (table $0 4 funcref) + (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -295,91 +295,72 @@ local.get $1 i32.add ) - (func $interface/AFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 + (func $interface/IFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $2 local.get $2 - i32.add + i32.const 3 + i32.eq + if (result i32) + local.get $0 + local.get $1 + call $interface/AFoo#foo + else + local.get $2 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + local.get $1 + call $interface/StructurallyImplementsIFoo#foo + else + unreachable + end + end ) - (func $interface/StructurallyImplementsIFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/AFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/IFoo#foo (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 + (func $interface/StructurallyImplementsIFoo#faa (; 17 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 - i32.const 0 - local.get $0 - i32.const 8 - i32.sub - i32.load - call $~virtual - call_indirect (type $FUNCSIG$iii) + local.get $2 + i32.add ) (func $interface/IFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $0 - local.get $1 - local.get $2 - i32.const 1 + (local $3 i32) local.get $0 i32.const 8 i32.sub i32.load - call $~virtual - call_indirect (type $FUNCSIG$iiii) - ) - (func $~virtual (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - block $block$2$break - block $switch$1$default - block $switch$1$case$6 - block $switch$1$case$3 - local.get $0 - br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default - end - local.get $1 - i32.const 3 - i32.eq - if - i32.const 2 - return - else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 3 - return - else - br $block$2$break - end - unreachable - end - unreachable - end + local.set $3 + local.get $3 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + local.get $1 + local.get $2 + call $interface/AFoo#faa + else + local.get $3 + i32.const 4 + i32.eq + if (result i32) + local.get $0 local.get $1 - i32.const 3 - i32.eq - if - i32.const 4 - return - else - local.get $1 - i32.const 4 - i32.eq - if - i32.const 5 - return - else - br $block$2$break - end - unreachable - end + local.get $2 + call $interface/StructurallyImplementsIFoo#faa + else unreachable end - br $block$2$break end - unreachable ) - (func $null (; 20 ;) (type $FUNCSIG$v) + (func $null (; 19 ;) (type $FUNCSIG$v) ) ) From 6c29e9c2642e56da3c030340add6e8a73201d3aa Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 4 Dec 2019 10:30:00 -0500 Subject: [PATCH 20/47] Fixed fail test Have issues for global property access. --- src/program.ts | 2 +- tests/compiler/interface-fail.json | 28 ++++++++++++++-------------- tests/compiler/interface-fail.ts | 7 ++++++- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/program.ts b/src/program.ts index 9748f62cfc..ad14506e35 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1854,7 +1854,7 @@ export class Program extends DiagnosticEmitter { if (!fieldDecl.is(CommonFlags.READONLY)){ const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range) const signature = Node.createFunctionType([param], Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); - instanceDeclarations.push(Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range)); + instanceDeclarations.push(Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.SET, fieldDecl.range)); } const signature = Node.createFunctionType([], fieldDecl.type || Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); memberDeclaration = Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range); diff --git a/tests/compiler/interface-fail.json b/tests/compiler/interface-fail.json index c02bb175b9..0c23e3fea4 100644 --- a/tests/compiler/interface-fail.json +++ b/tests/compiler/interface-fail.json @@ -3,32 +3,32 @@ "--runtime none" ], "stderr": [ - "TS2741: Property 'foo' is missing in type 'BadFoo' but required in type 'IFoo'.", - "class BadFoo implements IFoo {", + "TS2741: Property 'foo' is missing in type 'BadFoo' but required in type 'IFooBad'.", + "class BadFoo implements IFooBad {", "TS2322: Type '(i: i32, i2: i32) => i32' is not assignable to type '(i: i32, i2: i32) => ~lib/string/String'.", - "class BadFoo implements IFoo {", + "class BadFoo implements IFooBad {", - "TS2420: Class 'interface-fail/BadFoo' incorrectly implements interface 'interface-fail/IFoo'.", - "class BadFoo implements IFoo {", + "TS2420: Class 'interface-fail/BadFoo' incorrectly implements interface 'interface-fail/IFooBad'.", + "class BadFoo implements IFooBad {", - "TS2322: Type 'interface-fail/BadFoo' is not assignable to type 'interface-fail/IFoo'.", - "const aBadFoo: IFoo = new BadFoo();", + "TS2322: Type 'interface-fail/BadFoo' is not assignable to type 'interface-fail/IFooBad'.", + "const aBadFoo: IFooBad = new BadFoo();", - "TS2741: Property 'foo' is missing in type 'AnotherBadFoo' but required in type 'IFoo'.", + "TS2741: Property 'foo' is missing in type 'AnotherBadFoo' but required in type 'IFooBad'.", "class AnotherBadFoo {}", - "TS2741: Property 'faa' is missing in type 'AnotherBadFoo' but required in type 'IFoo'.", + "TS2741: Property 'faa' is missing in type 'AnotherBadFoo' but required in type 'IFooBad'.", "class AnotherBadFoo {}", - "TS2420: Class 'interface-fail/AnotherBadFoo' incorrectly implements interface 'interface-fail/IFoo'.", + "TS2420: Class 'interface-fail/AnotherBadFoo' incorrectly implements interface 'interface-fail/IFooBad'.", "class AnotherBadFoo {}", - "TS2322: Type 'interface-fail/AnotherBadFoo' is not assignable to type 'interface-fail/IFoo'.", - "const anotherBadFoo: IFoo = new AnotherBadFoo();", + "TS2322: Type 'interface-fail/AnotherBadFoo' is not assignable to type 'interface-fail/IFooBad'.", + "const anotherBadFoo: IFooBad = new AnotherBadFoo();", - "TS2322: Type 'i32' is not assignable to type 'interface-fail/IFoo'.", - "const intFoo: IFoo = 5;", + "TS2322: Type 'i32' is not assignable to type 'interface-fail/IFooBad'.", + "const intFoo: IFooBad = 5;", "TS2741: Property 'get val' is missing in type 'BadProps' but required in type 'Properties'.", "class BadProps implements Properties {", diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index b5f6004fbc..073056ceae 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -47,4 +47,9 @@ class BadProps implements Properties { const badProp = new BadProps(); -const val = badProp.val; + +function badFunc(prop: Properties): void { + const val = prop.val; +} + +badFunc(badProp); \ No newline at end of file From 932d8ac54a28fef0ad35748c7ce95e66f43080e3 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 4 Dec 2019 11:02:51 -0500 Subject: [PATCH 21/47] Add global getter example. --- tests/compiler/interface.optimized.wat | 19 +++++++++++++++++++ tests/compiler/interface.ts | 4 ++++ tests/compiler/interface.untouched.wat | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 879f292373..b5b70f11d3 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -13,6 +13,8 @@ (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) (global $interface/sFoo (mut i32) (i32.const 0)) + (global $interface/iFoo (mut i32) (i32.const 0)) + (global $interface/ibool (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) @@ -181,6 +183,23 @@ global.get $interface/sFoo i32.const 0 call $interface/expectX + global.get $interface/aFoo + global.set $interface/iFoo + global.get $interface/iFoo + call $interface/IFoo#get:x + i32.const 0 + i32.ne + global.set $interface/ibool + global.get $interface/ibool + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end ) (func $start (; 6 ;) (type $FUNCSIG$v) call $start:interface diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index 53ea21f38f..85a10a4234 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -51,3 +51,7 @@ function expectX(foo: IFoo, x: bool): void { expectX(aFoo, true); expectX(sFoo, false); + +const iFoo = aFoo; +const ibool = iFoo.x; +assert(ibool) \ No newline at end of file diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 1398e6ee1d..502404101b 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -15,6 +15,8 @@ (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) (global $interface/sFoo (mut i32) (i32.const 0)) + (global $interface/iFoo (mut i32) (i32.const 0)) + (global $interface/ibool (mut i32) (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 48)) (export "memory" (memory $0)) (start $start) @@ -251,6 +253,24 @@ global.get $interface/sFoo i32.const 0 call $interface/expectX + global.get $interface/aFoo + call $~lib/rt/stub/__retain + global.set $interface/iFoo + global.get $interface/iFoo + call $interface/IFoo#get:x + i32.const 0 + i32.ne + global.set $interface/ibool + global.get $interface/ibool + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end ) (func $start (; 10 ;) (type $FUNCSIG$v) call $start:interface From bec5f7ce479e2cc61bbdd0edb1b14bd07939e885 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 4 Dec 2019 14:11:25 -0500 Subject: [PATCH 22/47] Can handle setters --- src/compiler.ts | 76 +++- src/program.ts | 8 +- tests/compiler/interface-fail.ts | 2 +- tests/compiler/interface-generic.json | 5 + .../compiler/interface-generic.optimized.wat | 301 ++++++++++++++ tests/compiler/interface-generic.ts | 57 +++ .../compiler/interface-generic.untouched.wat | 386 ++++++++++++++++++ tests/compiler/interface.optimized.wat | 106 ++--- tests/compiler/interface.ts | 14 +- tests/compiler/interface.untouched.wat | 79 +++- 10 files changed, 948 insertions(+), 86 deletions(-) create mode 100644 tests/compiler/interface-generic.json create mode 100644 tests/compiler/interface-generic.optimized.wat create mode 100644 tests/compiler/interface-generic.ts create mode 100644 tests/compiler/interface-generic.untouched.wat diff --git a/src/compiler.ts b/src/compiler.ts index cb890dc064..cf56d94131 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9287,6 +9287,7 @@ export class Compiler extends DiagnosticEmitter { for (let i: i32 = 0; i < interfaces.length; i++) { const _interface = interfaces[i]; this.compileInterfaceProperties(_interface); + this.compileInterfacePropertiesSetters(_interface); this.compileInterfaceMethods(_interface); } } @@ -9312,8 +9313,6 @@ export class Compiler extends DiagnosticEmitter { for (let c = 0; c < classes.length; c ++) { const _class = classes[c]; let prop = _class.members!.get(ifunc.name)!; - let expr: ExpressionRef; - let thisExpr = loadClassArg(module, 0); switch (prop.kind){ case ElementKind.FUNCTION_PROTOTYPE: { let p = prop; @@ -9349,7 +9348,7 @@ export class Compiler extends DiagnosticEmitter { compileInterfaceProperties(_interface: Interface): void { const module = this.module; - const iprops = _interface.props; + const iprops = _interface.getters; const classes = Array.from(_interface.implementers); for (let i = 0; i < iprops.length; i++) { @@ -9393,8 +9392,77 @@ export class Compiler extends DiagnosticEmitter { } // Remove the nop standin module.removeFunction(iprop.getterInstance!.internalName); - module.addFunction(iprop.getterInstance!.internalName, typeRef, [NativeType.I32], relooper.renderAndDispose(first, 0)); + module.addFunction(iprop.getterInstance!.internalName, typeRef, [this.nativeUsizeType], relooper.renderAndDispose(first, 0)); + } + } + + compileInterfacePropertiesSetters(_interface: Interface): void { + const module = this.module; + const iprops = _interface.setters; + const classes = Array.from(_interface.implementers); + + for (let i = 0; i < iprops.length; i++) { + const iprop = iprops[i]; + const relooper = this.module.createRelooper(); + const setter = iprop.setterInstance!; + const classIDIndex = setter.localsByIndex.length; + const typeRef = this.ensureSignature(setter.signature); + + // Condition to switch on + const first = relooper.addBlock(module.local_set(classIDIndex, loadClassID(module))); + const last = relooper.addBlock(module.unreachable()); + relooper.addBranch(first, last); + + for (let c = 0; c < classes.length; c++) { + let _class = classes[c]; + const prop = _class.members!.get(iprop.name)!; + let expr: ExpressionRef; + let thisExpr = this.loadClassArg(0); + if (prop.kind == ElementKind.PROPERTY) { + let p = prop; + let setter = p.setterInstance!; + this.compileFunction(setter); + expr = module.call(setter.internalName, + [thisExpr, this.module.local_get(1, p.type.toNativeType())], + setter.signature.returnType.toNativeType()); + }else if(prop.kind == ElementKind.FIELD) { + let field = prop; + var type = field.type; + var nativeType = type.toNativeType(); + var usizeType = this.options.usizeType; + var nativeSizeType = usizeType.toNativeType(); + var valueExpr = module.local_get(1, nativeType); + expr = module.store( + type.byteSize, + module.local_get(0, nativeSizeType), + valueExpr, + nativeType, + field.memoryOffset + ) + } else { + throw Error("Class " + classes[c].name + " must have property " + prop.name); + } + const returnBlock = relooper.addBlock(expr); + const loadLocal = this.loadClassArg(classIDIndex); + const classID = module.i32(_class.id); + relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); + } + // Remove the nop standin + module.removeFunction(setter.internalName); + module.addFunction(setter.internalName, + typeRef, + [this.nativeUsizeType], + relooper.renderAndDispose(first, 0)); } + + } + + loadClassArg(index: i32): ExpressionRef { + return this.module.local_get(index, this.options.usizeType.toNativeType()); + } + + get nativeUsizeType(): NativeType { + return this.options.usizeType.toNativeType(); } } diff --git a/src/program.ts b/src/program.ts index ad14506e35..8eac99041b 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3722,8 +3722,12 @@ export class Interface extends Class { // FIXME (v: DeclaredElement): bool => v.kind == ElementKind.FUNCTION_PROTOTYPE); } - get props(): Property[] { - return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY); + get getters(): Property[] { + return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY && (v).getterInstance != null); + } + + get setters(): Property[] { + return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY && (v).setterInstance != null); } get methodInstances(): Function[] { diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index 073056ceae..db8969e1f4 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -47,7 +47,7 @@ class BadProps implements Properties { const badProp = new BadProps(); - +const val = badProp.val; function badFunc(prop: Properties): void { const val = prop.val; } diff --git a/tests/compiler/interface-generic.json b/tests/compiler/interface-generic.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/interface-generic.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/interface-generic.optimized.wat b/tests/compiler/interface-generic.optimized.wat new file mode 100644 index 0000000000..302dbaa2d8 --- /dev/null +++ b/tests/compiler/interface-generic.optimized.wat @@ -0,0 +1,301 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00g\00e\00n\00e\00r\00i\00c\00.\00t\00s") + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-generic/aGFoo (mut i32) (i32.const 0)) + (global $interface-generic/sGFoo (mut i32) (i32.const 0)) + (global $interface-generic/gFoo (mut i32) (i32.const 0)) + (global $interface-generic/igbool (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $3 + local.get $0 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.tee $2 + i32.const 16 + local.get $2 + i32.const 16 + i32.gt_u + select + local.tee $4 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $3 + i32.const 16 + i32.sub + local.tee $2 + local.get $4 + i32.store + local.get $2 + i32.const -1 + i32.store offset=4 + local.get $2 + local.get $1 + i32.store offset=8 + local.get $2 + local.get $0 + i32.store offset=12 + local.get $3 + ) + (func $interface-generic/passAnGInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $interface-generic/GFoo#foo + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $interface-generic/GFoo#faa + i32.const 4 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $interface-generic/expectGX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $interface-generic/GFoo#get:x + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 49 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start:interface-generic (; 5 ;) (type $FUNCSIG$v) + (local $0 i32) + i32.const 64 + global.set $~lib/rt/stub/startOffset + i32.const 64 + global.set $~lib/rt/stub/offset + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 41 + i32.store + local.get $0 + global.set $interface-generic/aGFoo + i32.const 5 + i32.const 4 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 41 + i32.store + local.get $0 + i32.const 0 + i32.store8 offset=4 + local.get $0 + global.set $interface-generic/sGFoo + global.get $interface-generic/aGFoo + call $interface-generic/passAnGInterface + global.get $interface-generic/sGFoo + call $interface-generic/passAnGInterface + global.get $interface-generic/aGFoo + i32.const 1 + call $interface-generic/expectGX + global.get $interface-generic/sGFoo + i32.const 0 + call $interface-generic/expectGX + global.get $interface-generic/aGFoo + global.set $interface-generic/gFoo + global.get $interface-generic/gFoo + call $interface-generic/GFoo#get:x + i32.const 0 + i32.ne + global.set $interface-generic/igbool + global.get $interface-generic/igbool + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 6 ;) (type $FUNCSIG$v) + call $start:interface-generic + ) + (func $interface-generic/AGFoo#get:x (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface-generic/GFoo#get:x (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load8_u offset=4 + else + unreachable + end + end + ) + (func $interface-generic/AGFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface-generic/GFoo#foo (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + call $interface-generic/AGFoo#foo + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + call $interface-generic/AGFoo#foo + else + unreachable + end + end + ) + (func $interface-generic/AGFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface-generic/GFoo#faa (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + i32.const 3 + call $interface-generic/AGFoo#faa + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.const 1 + i32.const 3 + call $interface-generic/AGFoo#faa + else + unreachable + end + end + ) + (func $null (; 13 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/interface-generic.ts b/tests/compiler/interface-generic.ts new file mode 100644 index 0000000000..5ccbec3fea --- /dev/null +++ b/tests/compiler/interface-generic.ts @@ -0,0 +1,57 @@ + +interface GFoo { + foo(i: T): T; + faa(i: i32, i2: i32): i32; + readonly x: B; +} + +class AGFoo implements GFoo { + i: i32 = 41; + get x(): bool{ return true; } + set x(b: bool){} + + foo(i: i32): i32 { + return this.i + i; + } + + faa(i: i32, i2: i32): i32 { + return i + i2; + } + +} + +class StructurallyImplementsGFoo { + i: i32 = 41; + x: bool = false; + + foo(i: i32): i32 { + return this.i + i; + } + + faa(i: i32, i2: i32): i32 { + return i + i2; + } +} + +const aGFoo = new AGFoo(); +const sGFoo = new StructurallyImplementsGFoo(); + + +function passAnGInterface(foo: GFoo): void { + assert(foo.foo(1) == 42); + assert(foo.faa(1,3) == 4); +} + +passAnGInterface(aGFoo); +passAnGInterface(sGFoo); + +function expectGX(foo: GFoo, x: bool): void { + assert(foo.x == x); +} + +expectGX(aGFoo, true); +expectGX(sGFoo, false); + +const gFoo = > aGFoo; +const igbool = gFoo.x; +assert(igbool) \ No newline at end of file diff --git a/tests/compiler/interface-generic.untouched.wat b/tests/compiler/interface-generic.untouched.wat new file mode 100644 index 0000000000..23acf7645c --- /dev/null +++ b/tests/compiler/interface-generic.untouched.wat @@ -0,0 +1,386 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00g\00e\00n\00e\00r\00i\00c\00.\00t\00s\00") + (table $0 4 funcref) + (elem (i32.const 0) $null $interface-generic/AGFoo#get:x $interface-generic/AGFoo#foo $interface-generic/AGFoo#faa) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-generic/aGFoo (mut i32) (i32.const 0)) + (global $interface-generic/sGFoo (mut i32) (i32.const 0)) + (global $interface-generic/gFoo (mut i32) (i32.const 0)) + (global $interface-generic/igbool (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 64)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $interface-generic/AGFoo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 41 + i32.store + local.get $0 + ) + (func $interface-generic/StructurallyImplementsGFoo#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 5 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 41 + i32.store + local.get $0 + i32.const 0 + i32.store8 offset=4 + local.get $0 + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $interface-generic/passAnGInterface (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + i32.const 1 + call $interface-generic/GFoo#foo + i32.const 42 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 1 + i32.const 3 + call $interface-generic/GFoo#faa + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $interface-generic/expectGX (; 8 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $interface-generic/GFoo#get:x + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 49 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:interface-generic (; 9 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $interface-generic/AGFoo#constructor + global.set $interface-generic/aGFoo + i32.const 0 + call $interface-generic/StructurallyImplementsGFoo#constructor + global.set $interface-generic/sGFoo + global.get $interface-generic/aGFoo + call $interface-generic/passAnGInterface + global.get $interface-generic/sGFoo + call $interface-generic/passAnGInterface + global.get $interface-generic/aGFoo + i32.const 1 + call $interface-generic/expectGX + global.get $interface-generic/sGFoo + i32.const 0 + call $interface-generic/expectGX + global.get $interface-generic/aGFoo + call $~lib/rt/stub/__retain + global.set $interface-generic/gFoo + global.get $interface-generic/gFoo + call $interface-generic/GFoo#get:x + i32.const 0 + i32.ne + global.set $interface-generic/igbool + global.get $interface-generic/igbool + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 10 ;) (type $FUNCSIG$v) + call $start:interface-generic + ) + (func $interface-generic/AGFoo#get:x (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface-generic/GFoo#get:x (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-generic/AGFoo#get:x + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load8_u offset=4 + else + unreachable + end + end + ) + (func $interface-generic/AGFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface-generic/StructurallyImplementsGFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface-generic/GFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $2 + local.get $2 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + local.get $1 + call $interface-generic/AGFoo#foo + else + local.get $2 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + local.get $1 + call $interface-generic/StructurallyImplementsGFoo#foo + else + unreachable + end + end + ) + (func $interface-generic/AGFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface-generic/StructurallyImplementsGFoo#faa (; 17 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface-generic/GFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $3 + local.get $3 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + local.get $1 + local.get $2 + call $interface-generic/AGFoo#faa + else + local.get $3 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + local.get $1 + local.get $2 + call $interface-generic/StructurallyImplementsGFoo#faa + else + unreachable + end + end + ) + (func $null (; 19 ;) (type $FUNCSIG$v) + ) +) diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index b5b70f11d3..3cff2a3143 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -59,50 +59,32 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) (local $2 i32) - (local $3 i32) - (local $4 i32) - local.get $0 - i32.const 1073741808 - i32.gt_u - if - unreachable - end global.get $~lib/rt/stub/offset i32.const 16 i32.add - local.tee $3 - local.get $0 - i32.const 15 - i32.add - i32.const -16 - i32.and local.tee $2 i32.const 16 - local.get $2 - i32.const 16 - i32.gt_u - select - local.tee $4 i32.add call $~lib/rt/stub/maybeGrowMemory - local.get $3 + local.get $2 i32.const 16 i32.sub - local.tee $2 - local.get $4 + local.tee $1 + i32.const 16 i32.store - local.get $2 + local.get $1 i32.const -1 i32.store offset=4 - local.get $2 local.get $1 - i32.store offset=8 - local.get $2 local.get $0 + i32.store offset=8 + local.get $1 + i32.const 5 i32.store offset=12 - local.get $3 + local.get $2 ) (func $interface/passAnInterface (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 @@ -112,7 +94,7 @@ if i32.const 0 i32.const 24 - i32.const 41 + i32.const 42 i32.const 2 call $~lib/builtins/abort unreachable @@ -124,25 +106,21 @@ if i32.const 0 i32.const 24 - i32.const 42 + i32.const 43 i32.const 2 call $~lib/builtins/abort unreachable end ) - (func $interface/expectX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $interface/expectX (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $interface/IFoo#set:x local.get $0 call $interface/IFoo#get:x - i32.const 0 - i32.ne - local.get $1 - i32.const 0 - i32.ne - i32.ne if i32.const 0 i32.const 24 - i32.const 49 + i32.const 51 i32.const 2 call $~lib/builtins/abort unreachable @@ -154,15 +132,16 @@ global.set $~lib/rt/stub/startOffset i32.const 48 global.set $~lib/rt/stub/offset - i32.const 4 i32.const 3 call $~lib/rt/stub/__alloc local.tee $0 i32.const 41 i32.store local.get $0 + i32.const 1 + i32.store8 offset=4 + local.get $0 global.set $interface/aFoo - i32.const 5 i32.const 4 call $~lib/rt/stub/__alloc local.tee $0 @@ -178,10 +157,8 @@ global.get $interface/sFoo call $interface/passAnInterface global.get $interface/aFoo - i32.const 1 call $interface/expectX global.get $interface/sFoo - i32.const 0 call $interface/expectX global.get $interface/aFoo global.set $interface/iFoo @@ -191,11 +168,10 @@ i32.ne global.set $interface/ibool global.get $interface/ibool - i32.eqz if i32.const 0 i32.const 24 - i32.const 57 + i32.const 59 i32.const 0 call $~lib/builtins/abort unreachable @@ -205,7 +181,8 @@ call $start:interface ) (func $interface/AFoo#get:x (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 + local.get $0 + i32.load8_u offset=4 ) (func $interface/IFoo#get:x (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) @@ -217,7 +194,8 @@ i32.const 3 i32.eq if (result i32) - i32.const 1 + local.get $0 + i32.load8_u offset=4 else local.get $1 i32.const 4 @@ -230,13 +208,39 @@ end end ) - (func $interface/AFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/IFoo#set:x (; 9 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 3 + i32.eq + if + local.get $0 + i32.const 0 + i32.store8 offset=4 + else + local.get $1 + i32.const 4 + i32.eq + if + local.get $0 + i32.const 0 + i32.store8 offset=4 + else + unreachable + end + end + ) + (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/IFoo#foo (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/IFoo#foo (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -262,12 +266,12 @@ end end ) - (func $interface/AFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/IFoo#faa (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/IFoo#faa (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -295,7 +299,7 @@ end end ) - (func $null (; 13 ;) (type $FUNCSIG$v) + (func $null (; 14 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index 85a10a4234..3a2c1ce0eb 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -2,13 +2,14 @@ interface IFoo { foo(i: i32): i32; faa(i: i32, i2: i32): i32; - readonly x: bool; + x: bool; } class AFoo implements IFoo { i: i32 = 41; - get x(): bool{ return true; } - set x(b: bool){} + _x: bool = true; + get x(): bool { return this._x; } + set x(b: bool){ this._x = b; } foo(i: i32): i32 { return this.i + i; @@ -46,12 +47,13 @@ passAnInterface(aFoo); passAnInterface(sFoo); function expectX(foo: IFoo, x: bool): void { - assert(foo.x == x); + foo.x = x; + assert(!foo.x); } -expectX(aFoo, true); +expectX(aFoo, false); expectX(sFoo, false); const iFoo = aFoo; const ibool = iFoo.x; -assert(ibool) \ No newline at end of file +assert(!ibool); diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 502404101b..abddd03103 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -9,8 +9,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 4 funcref) - (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#foo $interface/AFoo#faa) + (table $0 5 funcref) + (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#set:x $interface/AFoo#foo $interface/AFoo#faa) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -134,7 +134,7 @@ local.get $0 i32.eqz if - i32.const 4 + i32.const 5 i32.const 3 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain @@ -144,6 +144,9 @@ i32.const 41 i32.store local.get $0 + i32.const 1 + i32.store8 offset=4 + local.get $0 ) (func $interface/StructurallyImplementsIFoo#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -179,7 +182,7 @@ if i32.const 0 i32.const 24 - i32.const 41 + i32.const 42 i32.const 2 call $~lib/builtins/abort unreachable @@ -194,7 +197,7 @@ if i32.const 0 i32.const 24 - i32.const 42 + i32.const 43 i32.const 2 call $~lib/builtins/abort unreachable @@ -207,18 +210,16 @@ call $~lib/rt/stub/__retain local.set $0 local.get $0 - call $interface/IFoo#get:x - i32.const 0 - i32.ne local.get $1 - i32.const 0 - i32.ne - i32.eq + call $interface/IFoo#set:x + local.get $0 + call $interface/IFoo#get:x + i32.eqz i32.eqz if i32.const 0 i32.const 24 - i32.const 49 + i32.const 51 i32.const 2 call $~lib/builtins/abort unreachable @@ -248,7 +249,7 @@ global.get $interface/sFoo call $interface/passAnInterface global.get $interface/aFoo - i32.const 1 + i32.const 0 call $interface/expectX global.get $interface/sFoo i32.const 0 @@ -263,10 +264,11 @@ global.set $interface/ibool global.get $interface/ibool i32.eqz + i32.eqz if i32.const 0 i32.const 24 - i32.const 57 + i32.const 59 i32.const 0 call $~lib/builtins/abort unreachable @@ -276,7 +278,8 @@ call $start:interface ) (func $interface/AFoo#get:x (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 + local.get $0 + i32.load8_u offset=4 ) (func $interface/IFoo#get:x (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) @@ -303,19 +306,51 @@ end end ) - (func $interface/AFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#set:x (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store8 offset=4 + ) + (func $interface/IFoo#set:x (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $2 + local.get $2 + i32.const 3 + i32.eq + if + local.get $0 + local.get $1 + call $interface/AFoo#set:x + else + local.get $2 + i32.const 4 + i32.eq + if + local.get $0 + local.get $1 + i32.store8 offset=4 + else + unreachable + end + end + ) + (func $interface/AFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/StructurallyImplementsIFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#foo (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface/IFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/IFoo#foo (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 i32.const 8 @@ -342,17 +377,17 @@ end end ) - (func $interface/AFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/AFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/StructurallyImplementsIFoo#faa (; 17 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/StructurallyImplementsIFoo#faa (; 19 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface/IFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface/IFoo#faa (; 20 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) local.get $0 i32.const 8 @@ -381,6 +416,6 @@ end end ) - (func $null (; 19 ;) (type $FUNCSIG$v) + (func $null (; 21 ;) (type $FUNCSIG$v) ) ) From cb4bcaea68fd30111b46953478b62750c3f46629 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 5 Dec 2019 16:08:04 -0500 Subject: [PATCH 23/47] Add array.form --- std/assembly/array.ts | 14 + std/assembly/index.d.ts | 2 + std/assembly/iterator.ts | 22 +- tests/compiler/iterator.json | 5 + tests/compiler/iterator.optimized.wat | 974 +++++++++++ tests/compiler/iterator.ts | 53 + tests/compiler/iterator.untouched.wat | 2302 +++++++++++++++++++++++++ 7 files changed, 3365 insertions(+), 7 deletions(-) create mode 100644 tests/compiler/iterator.json create mode 100644 tests/compiler/iterator.optimized.wat create mode 100644 tests/compiler/iterator.ts create mode 100644 tests/compiler/iterator.untouched.wat diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 4e2a7d277d..2315e77822 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -6,6 +6,7 @@ import { ArrayBufferView } from "./arraybuffer"; import { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string"; import { idof, isArray as builtin_isArray } from "./builtins"; import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from "./util/error"; +import { Iterator } from "iterator"; /** Ensures that the given array has _at least_ the specified backing size. */ function ensureSize(array: usize, minSize: usize, alignLog2: u32): void { @@ -489,6 +490,19 @@ export class Array extends ArrayBufferView { return this.join(); } + static from(iter: Iterator): Array { + var arr = new Array(); + var res = iter.next(); + var len = 0; + while (!res.done){ + arr.push(res.value); + res = iter.next(); + len++; + } + arr.length = len; + return arr; + } + // RT integration @unsafe private __visit_impl(cookie: u32): void { diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 12a5c09127..e34c7f4fb8 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1356,6 +1356,8 @@ declare class Float64Array extends TypedArray { /** Class representing a sequence of values of type `T`. */ declare class Array { + // TODO: Add iterable types + static from(iterator: any): T[]; /** Tests if a value is an array. */ static isArray(value: any): value is Array; diff --git a/std/assembly/iterator.ts b/std/assembly/iterator.ts index e3df689744..d81cd0138c 100644 --- a/std/assembly/iterator.ts +++ b/std/assembly/iterator.ts @@ -1,9 +1,13 @@ -export abstract class Iterable { - // ? +export interface Iterable { + readonly iterator: Iterator; } -@sealed -export abstract class Iterator { +export interface IteratorResut { + readonly value: T; + readonly done: bool; +} + +export interface Iterator { // private constructor(iterable: Iterable) { // } @@ -29,7 +33,11 @@ export abstract class Iterator { // ? // } - done(this: u64): bool { - return (this & 1); - } + readonly done: bool; + + readonly value: T; + + next(): Iterator; + + } diff --git a/tests/compiler/iterator.json b/tests/compiler/iterator.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/iterator.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/iterator.optimized.wat b/tests/compiler/iterator.optimized.wat new file mode 100644 index 0000000000..0ba279575a --- /dev/null +++ b/tests/compiler/iterator.optimized.wat @@ -0,0 +1,974 @@ +(module + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05") + (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03") + (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") + (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 176) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s") + (data (i32.const 216) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h") + (data (i32.const 264) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 320) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s") + (global $iterator/iterableArr (mut i32) (i32.const 0)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $iterator/iter (mut i32) (i32.const 0)) + (global $iterator/res (mut i32) (i32.const 0)) + (global $iterator/i (mut i32) (i32.const 0)) + (global $iterator/arr2 (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $3 + local.get $0 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.tee $2 + i32.const 16 + local.get $2 + i32.const 16 + i32.gt_u + select + local.tee $4 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $3 + i32.const 16 + i32.sub + local.tee $2 + local.get $4 + i32.store + local.get $2 + i32.const -1 + i32.store offset=4 + local.get $2 + local.get $1 + i32.store offset=8 + local.get $2 + local.get $0 + i32.store offset=12 + local.get $3 + ) + (func $iterator/IterableArray#get:iterator (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + i32.const 8 + i32.const 6 + call $~lib/rt/stub/__alloc + local.tee $1 + i32.const -1 + i32.store + local.get $1 + local.get $0 + i32.store offset=4 + local.get $1 + ) + (func $~lib/array/Array#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 88 + i32.const 144 + i32.const 94 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/memory/memory.fill (; 5 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + block $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.eqz + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 1 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 2 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 1 + i32.add + i32.const 0 + i32.store8 + local.get $0 + i32.const 2 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 2 + i32.sub + i32.const 0 + i32.store8 + local.get $2 + i32.const 3 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 6 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 3 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.const 0 + local.get $0 + i32.sub + i32.const 3 + i32.and + local.tee $1 + i32.sub + local.get $0 + local.get $1 + i32.add + local.tee $0 + i32.const 0 + i32.store + i32.const -4 + i32.and + local.tee $1 + local.get $0 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 4 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 8 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 12 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 8 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 24 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 12 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 16 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 20 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 24 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 28 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 24 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 20 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 16 + i32.sub + i32.const 0 + i32.store + local.get $0 + i32.const 4 + i32.and + i32.const 24 + i32.add + local.tee $2 + local.get $0 + i32.add + local.set $0 + local.get $1 + local.get $2 + i32.sub + local.set $1 + loop $continue|0 + local.get $1 + i32.const 32 + i32.ge_u + if + local.get $0 + i64.const 0 + i64.store + local.get $0 + i32.const 8 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 16 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 24 + i32.add + i64.const 0 + i64.store + local.get $1 + i32.const 32 + i32.sub + local.set $1 + local.get $0 + i32.const 32 + i32.add + local.set $0 + br $continue|0 + end + end + end + ) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 6 ;) (param $0 i32) (result i32) + (local $1 i32) + i32.const 0 + i32.const 0 + call $~lib/rt/stub/__alloc + local.tee $1 + i32.const 0 + call $~lib/memory/memory.fill + local.get $0 + i32.eqz + if + i32.const 12 + i32.const 2 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.load + drop + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + ) + (func $~lib/memory/memory.copy (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $2 + local.set $3 + local.get $0 + local.get $1 + i32.eq + br_if $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $1 + i32.lt_u + if + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|0 + local.get $0 + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + local.get $0 + local.tee $2 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $2 + local.get $4 + i32.load8_u + i32.store8 + br $continue|0 + end + end + loop $continue|1 + local.get $3 + i32.const 8 + i32.lt_u + i32.eqz + if + local.get $0 + local.get $1 + i64.load + i64.store + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + br $continue|1 + end + end + end + loop $continue|2 + local.get $3 + if + local.get $0 + local.tee $2 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $2 + local.get $4 + i32.load8_u + i32.store8 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + br $continue|2 + end + end + else + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|3 + local.get $0 + local.get $3 + i32.add + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + end + loop $continue|4 + local.get $3 + i32.const 8 + i32.lt_u + i32.eqz + if + local.get $0 + local.get $3 + i32.const 8 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i64.load + i64.store + br $continue|4 + end + end + end + loop $continue|5 + local.get $3 + if + local.get $0 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + end + end + end + ) + (func $~lib/rt/stub/__realloc (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + i32.const 15 + i32.and + i32.eqz + i32.const 0 + local.get $0 + select + i32.eqz + if + i32.const 0 + i32.const 336 + i32.const 43 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 16 + i32.sub + local.tee $3 + i32.load + local.set $4 + local.get $3 + i32.load offset=4 + i32.const -1 + i32.ne + if + i32.const 0 + i32.const 336 + i32.const 46 + i32.const 13 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/rt/stub/offset + local.get $0 + local.get $4 + i32.add + i32.eq + local.set $5 + local.get $1 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.set $2 + local.get $1 + local.get $4 + i32.gt_u + if + local.get $5 + if + local.get $1 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + local.get $0 + local.get $2 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $3 + local.get $2 + i32.store + else + local.get $2 + local.get $4 + i32.const 1 + i32.shl + local.tee $4 + local.get $2 + local.get $4 + i32.gt_u + select + local.get $3 + i32.load offset=8 + call $~lib/rt/stub/__alloc + local.tee $2 + local.get $0 + local.get $3 + i32.load offset=12 + call $~lib/memory/memory.copy + local.get $2 + local.tee $0 + i32.const 16 + i32.sub + local.set $3 + end + else + local.get $5 + if + local.get $0 + local.get $2 + i32.add + global.set $~lib/rt/stub/offset + local.get $3 + local.get $2 + i32.store + end + end + local.get $3 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/array/ensureSize (; 9 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $1 + local.get $0 + i32.load offset=8 + local.tee $2 + i32.const 2 + i32.shr_u + i32.gt_u + if + local.get $1 + i32.const 268435452 + i32.gt_u + if + i32.const 232 + i32.const 144 + i32.const 15 + i32.const 47 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load + local.tee $4 + local.get $1 + i32.const 2 + i32.shl + local.tee $3 + call $~lib/rt/stub/__realloc + local.tee $1 + local.get $2 + i32.add + local.get $3 + local.get $2 + i32.sub + call $~lib/memory/memory.fill + local.get $1 + local.get $4 + i32.ne + if + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + end + local.get $0 + local.get $3 + i32.store offset=8 + end + ) + (func $~lib/array/Array#push (; 10 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + local.get $0 + local.get $0 + i32.load offset=12 + local.tee $2 + i32.const 1 + i32.add + local.tee $3 + call $~lib/array/ensureSize + local.get $0 + i32.load offset=4 + local.get $2 + i32.const 2 + i32.shl + i32.add + local.get $1 + i32.store + local.get $0 + local.get $3 + i32.store offset=12 + ) + (func $~lib/array/Array.from (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + i32.const 16 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/arraybuffer/ArrayBufferView#constructor + local.tee $1 + i32.const 0 + i32.store offset=12 + local.get $1 + i32.const 0 + i32.store offset=12 + local.get $0 + local.tee $3 + call $~lib/iterator/Iterator#next + local.set $0 + loop $continue|0 + local.get $0 + call $~lib/iterator/Iterator#get:done + i32.eqz + if + local.get $1 + local.get $0 + call $~lib/iterator/Iterator#get:value + call $~lib/array/Array#push + local.get $3 + call $~lib/iterator/Iterator#next + local.set $0 + local.get $2 + i32.const 1 + i32.add + local.set $2 + br $continue|0 + end + end + local.get $1 + i32.load offset=12 + drop + local.get $1 + local.get $2 + call $~lib/array/ensureSize + local.get $1 + local.get $2 + i32.store offset=12 + local.get $1 + ) + (func $start:iterator (; 12 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + i32.const 56 + global.set $iterator/iterableArr + i32.const 368 + global.set $~lib/rt/stub/startOffset + i32.const 368 + global.set $~lib/rt/stub/offset + i32.const 56 + call $iterator/IterableArray#get:iterator + global.set $iterator/iter + global.get $iterator/iter + call $~lib/iterator/Iterator#next + global.set $iterator/res + loop $continue|0 + global.get $iterator/res + call $~lib/iterator/Iterator#get:done + i32.eqz + if + global.get $iterator/res + call $~lib/iterator/Iterator#get:value + local.set $0 + global.get $iterator/i + local.tee $1 + i32.const 1 + i32.add + global.set $iterator/i + i32.const 56 + local.get $1 + call $~lib/array/Array#__get + local.get $0 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 43 + i32.const 2 + call $~lib/builtins/abort + unreachable + else + global.get $iterator/iter + call $~lib/iterator/Iterator#next + global.set $iterator/res + br $continue|0 + end + unreachable + end + end + global.get $iterator/iterableArr + call $iterator/IterableArray#get:iterator + call $~lib/array/Array.from + global.set $iterator/arr2 + i32.const 68 + i32.load + i32.const 3 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 51 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $iterator/arr2 + i32.const 0 + call $~lib/array/Array#__get + i32.const 1 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 52 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $iterator/arr2 + i32.const 1 + call $~lib/array/Array#__get + i32.const 3 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 53 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 13 ;) (type $FUNCSIG$v) + call $start:iterator + ) + (func $iterator/ArrayIterator#get:done (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + i32.load offset=12 + i32.ge_s + ) + (func $~lib/iterator/Iterator#get:done (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $iterator/ArrayIterator#get:done + else + unreachable + end + ) + (func $~lib/iterator/Iterator#get:value (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.eq + if + block $__inlined_func$iterator/ArrayIterator#get:value + local.get $0 + call $iterator/ArrayIterator#get:done + i32.eqz + if + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get + local.set $0 + br $__inlined_func$iterator/ArrayIterator#get:value + end + unreachable + end + else + unreachable + end + local.get $0 + ) + (func $~lib/iterator/Iterator#next (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.eq + if + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + else + unreachable + end + local.get $0 + ) + (func $null (; 18 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/iterator.ts b/tests/compiler/iterator.ts new file mode 100644 index 0000000000..f125612a22 --- /dev/null +++ b/tests/compiler/iterator.ts @@ -0,0 +1,53 @@ +import {Iterator, Iterable} from "iterator"; + + +class ArrayIterator implements Iterator { + private _index: i32 = -1; + constructor(private _array: Array){} + + get done(): bool{ + return this._index >= this._array.length; + } + + get value(): T { + if (!this.done){ + return this._array[this._index]; + } + unreachable(); + return changetype(this); + } + next(): Iterator { + this._index++; + return this; + } + + +} + +class IterableArray extends Array implements Iterable { + private _index: i32; + + get iterator(): Iterator { + return new ArrayIterator(this); + } + +} + +let arr: Array = [1,3,5]; +let iterableArr = > arr; + +let iter = iterableArr.iterator; +let res = iter.next(); +let i: i32 = 0; +while (!res.done){ + assert(res.value == arr[i++]); + res = iter.next() +} + + + +let arr2: Array = Array.from(iterableArr.iterator); +// assert (arr2 != null); +assert(arr.length == 3); +assert(arr2[0]== 1) +assert(arr2[1]== 3) \ No newline at end of file diff --git a/tests/compiler/iterator.untouched.wat b/tests/compiler/iterator.untouched.wat new file mode 100644 index 0000000000..7cc87ee8db --- /dev/null +++ b/tests/compiler/iterator.untouched.wat @@ -0,0 +1,2302 @@ +(module + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05\00\00\00") + (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03\00\00\00") + (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00") + (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 176) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s\00") + (data (i32.const 216) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h\00") + (data (i32.const 264) "&\00\00\00\01\00\00\00\01\00\00\00&\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 320) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") + (table $0 6 funcref) + (elem (i32.const 0) $null $iterator/ArrayIterator#constructor $iterator/IterableArray#get:iterator $iterator/ArrayIterator#get:done $iterator/ArrayIterator#get:value $iterator/ArrayIterator#next) + (global $iterator/arr (mut i32) (i32.const 56)) + (global $iterator/iterableArr (mut i32) (i32.const 0)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $iterator/iter (mut i32) (i32.const 0)) + (global $iterator/res (mut i32) (i32.const 0)) + (global $iterator/i (mut i32) (i32.const 0)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $iterator/arr2 (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 368)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/__retain (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $~lib/rt/stub/maybeGrowMemory (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 3 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__release (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $iterator/ArrayIterator#constructor (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.eqz + if + i32.const 8 + i32.const 6 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const -1 + i32.store + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store offset=4 + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $iterator/IterableArray#get:iterator (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 0 + local.get $0 + call $iterator/ArrayIterator#constructor + ) + (func $~lib/array/Array#__unchecked_get (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/array/Array#__get (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 88 + i32.const 144 + i32.const 94 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + call $~lib/array/Array#__unchecked_get + local.set $2 + local.get $2 + ) + (func $~lib/memory/memory.fill (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i64) + block $~lib/util/memory/memset|inlined.0 + local.get $0 + local.set $5 + local.get $1 + local.set $4 + local.get $2 + local.set $3 + local.get $3 + i32.eqz + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $5 + local.get $4 + i32.store8 + local.get $5 + local.get $3 + i32.add + i32.const 1 + i32.sub + local.get $4 + i32.store8 + local.get $3 + i32.const 2 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $5 + i32.const 1 + i32.add + local.get $4 + i32.store8 + local.get $5 + i32.const 2 + i32.add + local.get $4 + i32.store8 + local.get $5 + local.get $3 + i32.add + i32.const 2 + i32.sub + local.get $4 + i32.store8 + local.get $5 + local.get $3 + i32.add + i32.const 3 + i32.sub + local.get $4 + i32.store8 + local.get $3 + i32.const 6 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $5 + i32.const 3 + i32.add + local.get $4 + i32.store8 + local.get $5 + local.get $3 + i32.add + i32.const 4 + i32.sub + local.get $4 + i32.store8 + local.get $3 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + i32.const 0 + local.get $5 + i32.sub + i32.const 3 + i32.and + local.set $6 + local.get $5 + local.get $6 + i32.add + local.set $5 + local.get $3 + local.get $6 + i32.sub + local.set $3 + local.get $3 + i32.const -4 + i32.and + local.set $3 + i32.const -1 + i32.const 255 + i32.div_u + local.get $4 + i32.const 255 + i32.and + i32.mul + local.set $7 + local.get $5 + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 4 + i32.sub + local.get $7 + i32.store + local.get $3 + i32.const 8 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $5 + i32.const 4 + i32.add + local.get $7 + i32.store + local.get $5 + i32.const 8 + i32.add + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 12 + i32.sub + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 8 + i32.sub + local.get $7 + i32.store + local.get $3 + i32.const 24 + i32.le_u + if + br $~lib/util/memory/memset|inlined.0 + end + local.get $5 + i32.const 12 + i32.add + local.get $7 + i32.store + local.get $5 + i32.const 16 + i32.add + local.get $7 + i32.store + local.get $5 + i32.const 20 + i32.add + local.get $7 + i32.store + local.get $5 + i32.const 24 + i32.add + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 28 + i32.sub + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 24 + i32.sub + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 20 + i32.sub + local.get $7 + i32.store + local.get $5 + local.get $3 + i32.add + i32.const 16 + i32.sub + local.get $7 + i32.store + i32.const 24 + local.get $5 + i32.const 4 + i32.and + i32.add + local.set $6 + local.get $5 + local.get $6 + i32.add + local.set $5 + local.get $3 + local.get $6 + i32.sub + local.set $3 + local.get $7 + i64.extend_i32_u + local.get $7 + i64.extend_i32_u + i64.const 32 + i64.shl + i64.or + local.set $8 + block $break|0 + loop $continue|0 + local.get $3 + i32.const 32 + i32.ge_u + i32.eqz + br_if $break|0 + local.get $5 + local.get $8 + i64.store + local.get $5 + i32.const 8 + i32.add + local.get $8 + i64.store + local.get $5 + i32.const 16 + i32.add + local.get $8 + i64.store + local.get $5 + i32.const 24 + i32.add + local.get $8 + i64.store + local.get $3 + i32.const 32 + i32.sub + local.set $3 + local.get $5 + i32.const 32 + i32.add + local.set $5 + br $continue|0 + end + unreachable + end + end + ) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 10 ;) (type $FUNCSIG$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.get $1 + i32.const 1073741808 + local.get $2 + i32.shr_u + i32.gt_u + if + i32.const 232 + i32.const 280 + i32.const 23 + i32.const 56 + call $~lib/builtins/abort + unreachable + end + local.get $1 + local.get $2 + i32.shl + local.tee $1 + i32.const 0 + call $~lib/rt/stub/__alloc + local.set $3 + local.get $3 + i32.const 0 + local.get $1 + call $~lib/memory/memory.fill + local.get $0 + i32.eqz + if + i32.const 12 + i32.const 2 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + i32.load + local.tee $6 + i32.ne + if + local.get $5 + call $~lib/rt/stub/__retain + local.set $5 + local.get $6 + call $~lib/rt/stub/__release + end + local.get $5 + i32.store + local.get $0 + local.get $3 + i32.store offset=4 + local.get $0 + local.get $1 + i32.store offset=8 + local.get $0 + ) + (func $~lib/array/Array#constructor (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + if (result i32) + local.get $0 + else + i32.const 16 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + end + local.get $1 + i32.const 2 + call $~lib/arraybuffer/ArrayBufferView#constructor + local.set $0 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/util/memory/memcpy (; 12 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + block $break|0 + loop $continue|0 + local.get $2 + if (result i32) + local.get $1 + i32.const 3 + i32.and + else + i32.const 0 + end + i32.eqz + br_if $break|0 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + br $continue|0 + end + unreachable + end + local.get $0 + i32.const 3 + i32.and + i32.const 0 + i32.eq + if + block $break|1 + loop $continue|1 + local.get $2 + i32.const 16 + i32.ge_u + i32.eqz + br_if $break|1 + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.get $1 + i32.const 4 + i32.add + i32.load + i32.store + local.get $0 + i32.const 8 + i32.add + local.get $1 + i32.const 8 + i32.add + i32.load + i32.store + local.get $0 + i32.const 12 + i32.add + local.get $1 + i32.const 12 + i32.add + i32.load + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|1 + end + unreachable + end + local.get $2 + i32.const 8 + i32.and + if + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.get $1 + i32.const 4 + i32.add + i32.load + i32.store + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + end + local.get $2 + i32.const 4 + i32.and + if + local.get $0 + local.get $1 + i32.load + i32.store + local.get $0 + i32.const 4 + i32.add + local.set $0 + local.get $1 + i32.const 4 + i32.add + local.set $1 + end + local.get $2 + i32.const 2 + i32.and + if + local.get $0 + local.get $1 + i32.load16_u + i32.store16 + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + end + local.get $2 + i32.const 1 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + return + end + local.get $2 + i32.const 32 + i32.ge_u + if + block $break|2 + block $case2|2 + block $case1|2 + block $case0|2 + local.get $0 + i32.const 3 + i32.and + local.set $5 + local.get $5 + i32.const 1 + i32.eq + br_if $case0|2 + local.get $5 + i32.const 2 + i32.eq + br_if $case1|2 + local.get $5 + i32.const 3 + i32.eq + br_if $case2|2 + br $break|2 + end + local.get $1 + i32.load + local.set $3 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $2 + i32.const 3 + i32.sub + local.set $2 + block $break|3 + loop $continue|3 + local.get $2 + i32.const 17 + i32.ge_u + i32.eqz + br_if $break|3 + local.get $1 + i32.const 1 + i32.add + i32.load + local.set $4 + local.get $0 + local.get $3 + i32.const 24 + i32.shr_u + local.get $4 + i32.const 8 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 5 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 4 + i32.add + local.get $4 + i32.const 24 + i32.shr_u + local.get $3 + i32.const 8 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 9 + i32.add + i32.load + local.set $4 + local.get $0 + i32.const 8 + i32.add + local.get $3 + i32.const 24 + i32.shr_u + local.get $4 + i32.const 8 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 13 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 12 + i32.add + local.get $4 + i32.const 24 + i32.shr_u + local.get $3 + i32.const 8 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|3 + end + unreachable + end + br $break|2 + end + local.get $1 + i32.load + local.set $3 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $2 + i32.const 2 + i32.sub + local.set $2 + block $break|4 + loop $continue|4 + local.get $2 + i32.const 18 + i32.ge_u + i32.eqz + br_if $break|4 + local.get $1 + i32.const 2 + i32.add + i32.load + local.set $4 + local.get $0 + local.get $3 + i32.const 16 + i32.shr_u + local.get $4 + i32.const 16 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 6 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 4 + i32.add + local.get $4 + i32.const 16 + i32.shr_u + local.get $3 + i32.const 16 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 10 + i32.add + i32.load + local.set $4 + local.get $0 + i32.const 8 + i32.add + local.get $3 + i32.const 16 + i32.shr_u + local.get $4 + i32.const 16 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 14 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 12 + i32.add + local.get $4 + i32.const 16 + i32.shr_u + local.get $3 + i32.const 16 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|4 + end + unreachable + end + br $break|2 + end + local.get $1 + i32.load + local.set $3 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $2 + i32.const 1 + i32.sub + local.set $2 + block $break|5 + loop $continue|5 + local.get $2 + i32.const 19 + i32.ge_u + i32.eqz + br_if $break|5 + local.get $1 + i32.const 3 + i32.add + i32.load + local.set $4 + local.get $0 + local.get $3 + i32.const 8 + i32.shr_u + local.get $4 + i32.const 24 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 7 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 4 + i32.add + local.get $4 + i32.const 8 + i32.shr_u + local.get $3 + i32.const 24 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 11 + i32.add + i32.load + local.set $4 + local.get $0 + i32.const 8 + i32.add + local.get $3 + i32.const 8 + i32.shr_u + local.get $4 + i32.const 24 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 15 + i32.add + i32.load + local.set $3 + local.get $0 + i32.const 12 + i32.add + local.get $4 + i32.const 8 + i32.shr_u + local.get $3 + i32.const 24 + i32.shl + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.set $1 + local.get $0 + i32.const 16 + i32.add + local.set $0 + local.get $2 + i32.const 16 + i32.sub + local.set $2 + br $continue|5 + end + unreachable + end + br $break|2 + end + end + local.get $2 + i32.const 16 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 8 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 4 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 2 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + local.get $2 + i32.const 1 + i32.and + if + local.get $0 + local.tee $5 + i32.const 1 + i32.add + local.set $0 + local.get $5 + local.get $1 + local.tee $5 + i32.const 1 + i32.add + local.set $1 + local.get $5 + i32.load8_u + i32.store8 + end + ) + (func $~lib/memory/memory.copy (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.set $5 + local.get $1 + local.set $4 + local.get $2 + local.set $3 + local.get $5 + local.get $4 + i32.eq + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $4 + local.get $3 + i32.add + local.get $5 + i32.le_u + if (result i32) + i32.const 1 + else + local.get $5 + local.get $3 + i32.add + local.get $4 + i32.le_u + end + if + local.get $5 + local.get $4 + local.get $3 + call $~lib/util/memory/memcpy + br $~lib/util/memory/memmove|inlined.0 + end + local.get $5 + local.get $4 + i32.lt_u + if + local.get $4 + i32.const 7 + i32.and + local.get $5 + i32.const 7 + i32.and + i32.eq + if + block $break|0 + loop $continue|0 + local.get $5 + i32.const 7 + i32.and + i32.eqz + br_if $break|0 + local.get $3 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $3 + i32.const 1 + i32.sub + local.set $3 + local.get $5 + local.tee $6 + i32.const 1 + i32.add + local.set $5 + local.get $6 + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + i32.load8_u + i32.store8 + br $continue|0 + end + unreachable + end + block $break|1 + loop $continue|1 + local.get $3 + i32.const 8 + i32.ge_u + i32.eqz + br_if $break|1 + local.get $5 + local.get $4 + i64.load + i64.store + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $4 + i32.const 8 + i32.add + local.set $4 + br $continue|1 + end + unreachable + end + end + block $break|2 + loop $continue|2 + local.get $3 + i32.eqz + br_if $break|2 + local.get $5 + local.tee $6 + i32.const 1 + i32.add + local.set $5 + local.get $6 + local.get $4 + local.tee $6 + i32.const 1 + i32.add + local.set $4 + local.get $6 + i32.load8_u + i32.store8 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + br $continue|2 + end + unreachable + end + else + local.get $4 + i32.const 7 + i32.and + local.get $5 + i32.const 7 + i32.and + i32.eq + if + block $break|3 + loop $continue|3 + local.get $5 + local.get $3 + i32.add + i32.const 7 + i32.and + i32.eqz + br_if $break|3 + local.get $3 + i32.eqz + if + br $~lib/util/memory/memmove|inlined.0 + end + local.get $5 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $4 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + unreachable + end + block $break|4 + loop $continue|4 + local.get $3 + i32.const 8 + i32.ge_u + i32.eqz + br_if $break|4 + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $5 + local.get $3 + i32.add + local.get $4 + local.get $3 + i32.add + i64.load + i64.store + br $continue|4 + end + unreachable + end + end + block $break|5 + loop $continue|5 + local.get $3 + i32.eqz + br_if $break|5 + local.get $5 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $4 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + unreachable + end + end + end + ) + (func $~lib/rt/stub/__realloc (; 14 ;) (type $FUNCSIG$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.get $0 + i32.const 0 + i32.ne + if (result i32) + local.get $0 + i32.const 15 + i32.and + i32.eqz + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 336 + i32.const 43 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 16 + i32.sub + local.set $2 + local.get $2 + i32.load + local.set $3 + local.get $2 + i32.load offset=4 + i32.const -1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 336 + i32.const 46 + i32.const 13 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $3 + i32.add + global.get $~lib/rt/stub/offset + i32.eq + local.set $4 + local.get $1 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.set $5 + local.get $1 + local.get $3 + i32.gt_u + if + local.get $4 + if + local.get $1 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + local.get $0 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + local.get $5 + i32.store + else + local.get $5 + local.tee $6 + local.get $3 + i32.const 1 + i32.shl + local.tee $7 + local.get $6 + local.get $7 + i32.gt_u + select + local.get $2 + i32.load offset=8 + call $~lib/rt/stub/__alloc + local.set $6 + local.get $6 + local.get $0 + local.get $2 + i32.load offset=12 + call $~lib/memory/memory.copy + local.get $6 + local.tee $0 + i32.const 16 + i32.sub + local.set $2 + end + else + local.get $4 + if + local.get $0 + local.get $5 + i32.add + global.set $~lib/rt/stub/offset + local.get $2 + local.get $5 + i32.store + end + end + local.get $2 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/array/ensureSize (; 15 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $0 + i32.load offset=8 + local.set $3 + local.get $1 + local.get $3 + local.get $2 + i32.shr_u + i32.gt_u + if + local.get $1 + i32.const 1073741808 + local.get $2 + i32.shr_u + i32.gt_u + if + i32.const 232 + i32.const 144 + i32.const 15 + i32.const 47 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load + local.set $4 + local.get $1 + local.get $2 + i32.shl + local.set $5 + local.get $4 + local.get $5 + call $~lib/rt/stub/__realloc + local.set $6 + local.get $6 + local.get $3 + i32.add + i32.const 0 + local.get $5 + local.get $3 + i32.sub + call $~lib/memory/memory.fill + local.get $6 + local.get $4 + i32.ne + if + local.get $0 + local.get $6 + call $~lib/rt/stub/__retain + i32.store + local.get $0 + local.get $6 + i32.store offset=4 + end + local.get $0 + local.get $5 + i32.store offset=8 + end + ) + (func $~lib/array/Array#push (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + i32.load offset=12 + local.set $2 + local.get $2 + i32.const 1 + i32.add + local.set $3 + local.get $0 + local.get $3 + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + i32.load offset=4 + local.get $2 + i32.const 2 + i32.shl + i32.add + local.get $1 + i32.store + local.get $0 + local.get $3 + i32.store offset=12 + local.get $3 + ) + (func $~lib/array/Array#set:length (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=12 + local.set $2 + local.get $0 + local.get $1 + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.store offset=12 + ) + (func $~lib/array/Array.from (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + i32.const 0 + i32.const 0 + call $~lib/array/Array#constructor + local.set $1 + local.get $0 + call $~lib/iterator/Iterator#next + local.set $2 + i32.const 0 + local.set $3 + block $break|0 + loop $continue|0 + local.get $2 + call $~lib/iterator/Iterator#get:done + i32.eqz + i32.eqz + br_if $break|0 + local.get $1 + local.get $2 + call $~lib/iterator/Iterator#get:value + call $~lib/array/Array#push + drop + local.get $0 + call $~lib/iterator/Iterator#next + local.set $4 + local.get $2 + call $~lib/rt/stub/__release + local.get $4 + local.set $2 + local.get $3 + i32.const 1 + i32.add + local.set $3 + br $continue|0 + end + unreachable + end + local.get $1 + local.get $3 + call $~lib/array/Array#set:length + local.get $1 + local.set $4 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $4 + ) + (func $~lib/array/Array#get:length (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=12 + ) + (func $start:iterator (; 20 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + global.get $iterator/arr + call $~lib/rt/stub/__retain + global.set $iterator/iterableArr + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + global.get $iterator/iterableArr + call $iterator/IterableArray#get:iterator + local.tee $1 + call $~lib/rt/stub/__retain + global.set $iterator/iter + global.get $iterator/iter + call $~lib/iterator/Iterator#next + global.set $iterator/res + block $break|0 + loop $continue|0 + global.get $iterator/res + call $~lib/iterator/Iterator#get:done + i32.eqz + i32.eqz + br_if $break|0 + global.get $iterator/res + call $~lib/iterator/Iterator#get:value + global.get $iterator/arr + global.get $iterator/i + local.tee $0 + i32.const 1 + i32.add + global.set $iterator/i + local.get $0 + call $~lib/array/Array#__get + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 43 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + global.get $iterator/iter + call $~lib/iterator/Iterator#next + local.set $0 + global.get $iterator/res + call $~lib/rt/stub/__release + local.get $0 + global.set $iterator/res + br $continue|0 + end + unreachable + end + global.get $iterator/iterableArr + call $iterator/IterableArray#get:iterator + local.tee $0 + call $~lib/array/Array.from + global.set $iterator/arr2 + global.get $iterator/arr + call $~lib/array/Array#get:length + i32.const 3 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 51 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $iterator/arr2 + i32.const 0 + call $~lib/array/Array#__get + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 52 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $iterator/arr2 + i32.const 1 + call $~lib/array/Array#__get + i32.const 3 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 53 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + ) + (func $start (; 21 ;) (type $FUNCSIG$v) + call $start:iterator + ) + (func $iterator/ArrayIterator#get:done (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + call $~lib/array/Array#get:length + i32.ge_s + ) + (func $~lib/iterator/Iterator#get:done (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $iterator/ArrayIterator#get:done + else + unreachable + end + ) + (func $iterator/ArrayIterator#get:value (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $iterator/ArrayIterator#get:done + i32.eqz + if + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get + return + end + unreachable + ) + (func $~lib/iterator/Iterator#get:value (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $iterator/ArrayIterator#get:value + else + unreachable + end + ) + (func $iterator/ArrayIterator#next (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + local.get $0 + call $~lib/rt/stub/__retain + ) + (func $~lib/iterator/Iterator#next (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $iterator/ArrayIterator#next + else + unreachable + end + ) + (func $null (; 28 ;) (type $FUNCSIG$v) + ) +) From 4c3bad9574f3af75eb9c08230d0a1941863f2636 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 5 Dec 2019 16:11:34 -0500 Subject: [PATCH 24/47] Updated test artifacts --- tests/compiler/assert-nonnull.optimized.wat | 12 +- tests/compiler/assert-nonnull.untouched.wat | 6 +- tests/compiler/binary.optimized.wat | 10 +- tests/compiler/builtins.optimized.wat | 3 +- tests/compiler/call-super.optimized.wat | 9 +- tests/compiler/exports.optimized.wat | 2 +- tests/compiler/getter-call.optimized.wat | 2 +- tests/compiler/infer-generic.optimized.wat | 2 +- .../compiler/interface-generic.optimized.wat | 4 +- tests/compiler/interface.optimized.wat | 10 +- tests/compiler/memset.optimized.wat | 3 +- tests/compiler/new.optimized.wat | 3 +- tests/compiler/number.optimized.wat | 14 +- .../optional-typeparameters.optimized.wat | 3 +- tests/compiler/rc/global-init.optimized.wat | 4 +- tests/compiler/rc/local-init.optimized.wat | 2 +- .../rc/logical-and-mismatch.optimized.wat | 5 +- .../rc/logical-or-mismatch.optimized.wat | 5 +- tests/compiler/rc/optimize.optimized.wat | 2 +- tests/compiler/rc/rereturn.optimized.wat | 2 +- .../rc/ternary-mismatch.optimized.wat | 5 +- tests/compiler/resolve-access.optimized.wat | 11 +- tests/compiler/resolve-access.untouched.wat | 2 +- tests/compiler/resolve-binary.optimized.wat | 10 +- .../resolve-elementaccess.optimized.wat | 8 +- .../resolve-function-expression.optimized.wat | 7 +- tests/compiler/resolve-new.optimized.wat | 3 +- .../resolve-propertyaccess.optimized.wat | 3 +- tests/compiler/resolve-ternary.optimized.wat | 6 +- tests/compiler/resolve-unary.optimized.wat | 3 +- .../retain-release-sanity.optimized.wat | 18 +- .../retain-release-sanity.untouched.wat | 4 +- tests/compiler/retain-release.optimized.wat | 2 +- tests/compiler/rt/instanceof.optimized.wat | 5 +- tests/compiler/runtime-full.optimized.wat | 2 +- tests/compiler/std/array-access.optimized.wat | 13 +- tests/compiler/std/array-access.untouched.wat | 14 +- .../compiler/std/array-literal.optimized.wat | 13 +- .../compiler/std/array-literal.untouched.wat | 4 +- tests/compiler/std/array.optimized.wat | 101 ++++---- tests/compiler/std/array.untouched.wat | 46 ++-- tests/compiler/std/arraybuffer.optimized.wat | 11 +- tests/compiler/std/dataview.optimized.wat | 41 ++-- tests/compiler/std/date.optimized.wat | 3 +- tests/compiler/std/libm.optimized.wat | 3 +- tests/compiler/std/map.optimized.wat | 46 ++-- tests/compiler/std/math.optimized.wat | 154 ++++++------ tests/compiler/std/new.optimized.wat | 5 +- .../compiler/std/object-literal.optimized.wat | 5 +- tests/compiler/std/object.optimized.wat | 3 +- .../std/operator-overloading.optimized.wat | 9 +- tests/compiler/std/pointer.optimized.wat | 6 +- tests/compiler/std/set.optimized.wat | 43 ++-- tests/compiler/std/static-array.optimized.wat | 35 ++- tests/compiler/std/static-array.untouched.wat | 18 +- .../std/string-encoding.optimized.wat | 4 +- tests/compiler/std/string.optimized.wat | 36 ++- tests/compiler/std/string.untouched.wat | 6 +- tests/compiler/std/symbol.optimized.wat | 13 +- tests/compiler/std/typedarray.optimized.wat | 222 +++++++++--------- tests/compiler/std/typedarray.untouched.wat | 4 +- tests/compiler/typeof.optimized.wat | 6 +- 62 files changed, 494 insertions(+), 562 deletions(-) diff --git a/tests/compiler/assert-nonnull.optimized.wat b/tests/compiler/assert-nonnull.optimized.wat index d739eba408..e09e21d591 100644 --- a/tests/compiler/assert-nonnull.optimized.wat +++ b/tests/compiler/assert-nonnull.optimized.wat @@ -51,12 +51,12 @@ end local.get $0 ) - (func $~lib/array/Array#__unchecked_get (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#__unchecked_get (; 4 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 i32.load ) - (func $~lib/array/Array#__get (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#__get (; 5 ;) (param $0 i32) (result i32) i32.const 0 local.get $0 i32.load offset=12 @@ -64,7 +64,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -76,7 +76,7 @@ if i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -92,7 +92,7 @@ local.get $0 call $~lib/array/Array#__get ) - (func $~lib/array/Array#__get (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#__get (; 7 ;) (param $0 i32) (result i32) i32.const 0 local.get $0 i32.load offset=12 @@ -100,7 +100,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/assert-nonnull.untouched.wat b/tests/compiler/assert-nonnull.untouched.wat index bfc7f19423..c203a67f64 100644 --- a/tests/compiler/assert-nonnull.untouched.wat +++ b/tests/compiler/assert-nonnull.untouched.wat @@ -107,7 +107,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -123,7 +123,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -168,7 +168,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/binary.optimized.wat b/tests/compiler/binary.optimized.wat index e90209a695..1a62e0790f 100644 --- a/tests/compiler/binary.optimized.wat +++ b/tests/compiler/binary.optimized.wat @@ -1,7 +1,5 @@ (module (type $FUNCSIG$v (func)) - (type $FUNCSIG$dd (func (param f64) (result f64))) - (type $FUNCSIG$ff (func (param f32) (result f32))) (memory $0 0) (global $binary/b (mut i32) (i32.const 0)) (global $binary/i (mut i32) (i32.const 0)) @@ -10,7 +8,7 @@ (global $binary/F (mut f64) (f64.const 0)) (export "memory" (memory $0)) (start $start) - (func $~lib/math/NativeMath.pow (; 0 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 0 ;) (param $0 f64) (result f64) (local $1 i32) (local $2 i64) (local $3 i32) @@ -50,7 +48,7 @@ end local.get $0 ) - (func $~lib/math/NativeMathf.mod (; 1 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.mod (; 1 ;) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -195,7 +193,7 @@ local.get $0 f32.mul ) - (func $~lib/math/NativeMathf.pow (; 2 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.pow (; 2 ;) (param $0 f32) (result f32) (local $1 i32) i32.const 1 i32.const 0 @@ -215,7 +213,7 @@ end local.get $0 ) - (func $~lib/math/NativeMath.mod (; 3 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.mod (; 3 ;) (param $0 f64) (result f64) (local $1 i64) (local $2 i64) (local $3 i64) diff --git a/tests/compiler/builtins.optimized.wat b/tests/compiler/builtins.optimized.wat index 07af48865f..63d29c002c 100644 --- a/tests/compiler/builtins.optimized.wat +++ b/tests/compiler/builtins.optimized.wat @@ -5,7 +5,6 @@ (type $FUNCSIG$viiddddd (func (param i32 i32 f64 f64 f64 f64 f64))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64))) (memory $0 1) @@ -71,7 +70,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 5 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 5 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/call-super.optimized.wat b/tests/compiler/call-super.optimized.wat index ad00d717d7..e62c0ea523 100644 --- a/tests/compiler/call-super.optimized.wat +++ b/tests/compiler/call-super.optimized.wat @@ -4,7 +4,6 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00c\00a\00l\00l\00-\00s\00u\00p\00e\00r\00.\00t\00s") @@ -125,7 +124,7 @@ end local.get $0 ) - (func $call-super/B#constructor (; 4 ;) (type $FUNCSIG$i) (result i32) + (func $call-super/B#constructor (; 4 ;) (result i32) (local $0 i32) i32.const 8 i32.const 4 @@ -188,7 +187,7 @@ unreachable end ) - (func $call-super/D#constructor (; 6 ;) (type $FUNCSIG$i) (result i32) + (func $call-super/D#constructor (; 6 ;) (result i32) (local $0 i32) i32.const 8 i32.const 6 @@ -321,7 +320,7 @@ unreachable end ) - (func $call-super/H#constructor (; 10 ;) (type $FUNCSIG$i) (result i32) + (func $call-super/H#constructor (; 10 ;) (result i32) (local $0 i32) i32.const 8 i32.const 10 @@ -370,7 +369,7 @@ unreachable end ) - (func $call-super/J#constructor (; 12 ;) (type $FUNCSIG$i) (result i32) + (func $call-super/J#constructor (; 12 ;) (result i32) (local $0 i32) i32.const 8 i32.const 12 diff --git a/tests/compiler/exports.optimized.wat b/tests/compiler/exports.optimized.wat index 3befaaa6b6..1eebfb2931 100644 --- a/tests/compiler/exports.optimized.wat +++ b/tests/compiler/exports.optimized.wat @@ -102,7 +102,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 4 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/getter-call.optimized.wat b/tests/compiler/getter-call.optimized.wat index 47a9e9bc30..26e731c285 100644 --- a/tests/compiler/getter-call.optimized.wat +++ b/tests/compiler/getter-call.optimized.wat @@ -53,7 +53,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (result i32) (local $0 i32) (local $1 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/infer-generic.optimized.wat b/tests/compiler/infer-generic.optimized.wat index 8da77f7349..50ce734448 100644 --- a/tests/compiler/infer-generic.optimized.wat +++ b/tests/compiler/infer-generic.optimized.wat @@ -24,7 +24,7 @@ local.get $0 select ) - (func $~lib/array/Array#reduce (; 1 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#reduce (; 1 ;) (local $0 i32) (local $1 i32) (local $2 i32) diff --git a/tests/compiler/interface-generic.optimized.wat b/tests/compiler/interface-generic.optimized.wat index 302dbaa2d8..54b4ad4df0 100644 --- a/tests/compiler/interface-generic.optimized.wat +++ b/tests/compiler/interface-generic.optimized.wat @@ -236,7 +236,7 @@ local.get $1 i32.add ) - (func $interface-generic/GFoo#foo (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-generic/GFoo#foo (; 10 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -267,7 +267,7 @@ local.get $2 i32.add ) - (func $interface-generic/GFoo#faa (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-generic/GFoo#faa (; 12 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 3cff2a3143..0d1da99f22 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -59,7 +59,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset @@ -112,7 +112,7 @@ unreachable end ) - (func $interface/expectX (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/expectX (; 4 ;) (param $0 i32) local.get $0 call $interface/IFoo#set:x local.get $0 @@ -208,7 +208,7 @@ end end ) - (func $interface/IFoo#set:x (; 9 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface/IFoo#set:x (; 9 ;) (param $0 i32) (local $1 i32) local.get $0 i32.const 8 @@ -240,7 +240,7 @@ local.get $1 i32.add ) - (func $interface/IFoo#foo (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/IFoo#foo (; 11 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -271,7 +271,7 @@ local.get $2 i32.add ) - (func $interface/IFoo#faa (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/IFoo#faa (; 13 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 diff --git a/tests/compiler/memset.optimized.wat b/tests/compiler/memset.optimized.wat index d062bff123..183cf9cb96 100644 --- a/tests/compiler/memset.optimized.wat +++ b/tests/compiler/memset.optimized.wat @@ -1,14 +1,13 @@ (module (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$viii (func (param i32 i32 i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\12\00\00\00\01\00\00\00\01\00\00\00\12\00\00\00m\00e\00m\00s\00e\00t\00.\00t\00s") (global $memset/dest (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) - (func $memset/memset (; 1 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $memset/memset (; 1 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i64) block $folding-inner0 diff --git a/tests/compiler/new.optimized.wat b/tests/compiler/new.optimized.wat index 4b11d9201e..088236445d 100644 --- a/tests/compiler/new.optimized.wat +++ b/tests/compiler/new.optimized.wat @@ -1,7 +1,6 @@ (module (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (memory $0 0) (global $new/ref (mut i32) (i32.const 0)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) @@ -52,7 +51,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/number.optimized.wat b/tests/compiler/number.optimized.wat index 68475772eb..0ab33cbd27 100644 --- a/tests/compiler/number.optimized.wat +++ b/tests/compiler/number.optimized.wat @@ -8,8 +8,6 @@ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$if (func (param f32) (result i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iijijij (func (param i32 i64 i32 i64 i32 i64) (result i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\000") @@ -135,7 +133,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 3 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -255,7 +253,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 7 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -367,7 +365,7 @@ end i32.const 0 ) - (func $~lib/util/number/genDigits (; 9 ;) (type $FUNCSIG$iijijij) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (result i32) + (func $~lib/util/number/genDigits (; 9 ;) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (result i32) (local $6 i32) (local $7 i32) (local $8 i64) @@ -1189,7 +1187,7 @@ end end ) - (func $~lib/util/number/dtoa_core (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/util/number/dtoa_core (; 12 ;) (param $0 i32) (result i32) (local $1 i64) (local $2 i64) (local $3 i64) @@ -1357,7 +1355,7 @@ global.get $~lib/util/number/_K call $~lib/util/number/prettify ) - (func $~lib/string/String#substring (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 13 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1472,7 +1470,7 @@ global.set $~lib/rt/stub/offset end ) - (func $~lib/util/number/dtoa (; 15 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/util/number/dtoa (; 15 ;) (result i32) (local $0 i32) (local $1 i32) i32.const 56 diff --git a/tests/compiler/optional-typeparameters.optimized.wat b/tests/compiler/optional-typeparameters.optimized.wat index 2189da8971..52557bc5c7 100644 --- a/tests/compiler/optional-typeparameters.optimized.wat +++ b/tests/compiler/optional-typeparameters.optimized.wat @@ -1,7 +1,6 @@ (module (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (memory $0 0) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) @@ -51,7 +50,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/rc/global-init.optimized.wat b/tests/compiler/rc/global-init.optimized.wat index 7fa20715ab..b57185d830 100644 --- a/tests/compiler/rc/global-init.optimized.wat +++ b/tests/compiler/rc/global-init.optimized.wat @@ -524,7 +524,7 @@ i32.add i32.load ) - (func $~lib/rt/tlsf/addMemory (; 8 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 8 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1322,7 +1322,7 @@ call $~lib/rt/rtrace/onalloc local.get $2 ) - (func $~lib/rt/tlsf/__alloc (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/tlsf/__alloc (; 20 ;) (param $0 i32) (result i32) (local $1 i32) global.get $~lib/rt/tlsf/ROOT local.tee $1 diff --git a/tests/compiler/rc/local-init.optimized.wat b/tests/compiler/rc/local-init.optimized.wat index b7077bf470..6d0644bf9d 100644 --- a/tests/compiler/rc/local-init.optimized.wat +++ b/tests/compiler/rc/local-init.optimized.wat @@ -564,7 +564,7 @@ i32.add i32.load ) - (func $~lib/rt/tlsf/addMemory (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 10 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 diff --git a/tests/compiler/rc/logical-and-mismatch.optimized.wat b/tests/compiler/rc/logical-and-mismatch.optimized.wat index 102eef6acc..9d23cdc1ee 100644 --- a/tests/compiler/rc/logical-and-mismatch.optimized.wat +++ b/tests/compiler/rc/logical-and-mismatch.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -478,7 +477,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1374,7 +1373,7 @@ end local.get $0 ) - (func $rc/logical-and-mismatch/Ref#constructor (; 23 ;) (type $FUNCSIG$i) (result i32) + (func $rc/logical-and-mismatch/Ref#constructor (; 23 ;) (result i32) i32.const 0 i32.const 3 call $~lib/rt/tlsf/__alloc diff --git a/tests/compiler/rc/logical-or-mismatch.optimized.wat b/tests/compiler/rc/logical-or-mismatch.optimized.wat index 458dacb34e..5c18d8a876 100644 --- a/tests/compiler/rc/logical-or-mismatch.optimized.wat +++ b/tests/compiler/rc/logical-or-mismatch.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -478,7 +477,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1374,7 +1373,7 @@ end local.get $0 ) - (func $rc/logical-or-mismatch/Ref#constructor (; 23 ;) (type $FUNCSIG$i) (result i32) + (func $rc/logical-or-mismatch/Ref#constructor (; 23 ;) (result i32) i32.const 0 i32.const 3 call $~lib/rt/tlsf/__alloc diff --git a/tests/compiler/rc/optimize.optimized.wat b/tests/compiler/rc/optimize.optimized.wat index adca0ad28d..015437ef14 100644 --- a/tests/compiler/rc/optimize.optimized.wat +++ b/tests/compiler/rc/optimize.optimized.wat @@ -569,7 +569,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 13 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 diff --git a/tests/compiler/rc/rereturn.optimized.wat b/tests/compiler/rc/rereturn.optimized.wat index 52e8d2592b..dc2799892a 100644 --- a/tests/compiler/rc/rereturn.optimized.wat +++ b/tests/compiler/rc/rereturn.optimized.wat @@ -478,7 +478,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 3 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 3 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 diff --git a/tests/compiler/rc/ternary-mismatch.optimized.wat b/tests/compiler/rc/ternary-mismatch.optimized.wat index 08ab899cf5..9bb3a49004 100644 --- a/tests/compiler/rc/ternary-mismatch.optimized.wat +++ b/tests/compiler/rc/ternary-mismatch.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -480,7 +479,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1376,7 +1375,7 @@ end local.get $0 ) - (func $rc/ternary-mismatch/Ref#constructor (; 23 ;) (type $FUNCSIG$i) (result i32) + (func $rc/ternary-mismatch/Ref#constructor (; 23 ;) (result i32) i32.const 0 i32.const 3 call $~lib/rt/tlsf/__alloc diff --git a/tests/compiler/resolve-access.optimized.wat b/tests/compiler/resolve-access.optimized.wat index f086ec01ed..d533451157 100644 --- a/tests/compiler/resolve-access.optimized.wat +++ b/tests/compiler/resolve-access.optimized.wat @@ -8,7 +8,6 @@ (type $FUNCSIG$ij (func (param i64) (result i32))) (type $FUNCSIG$viji (func (param i32 i64 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ji (func (param i32) (result i64))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\08\00\00\00\01\00\00\00\00\00\00\00\08\00\00\00\01") @@ -109,7 +108,7 @@ i32.store offset=12 local.get $3 ) - (func $~lib/memory/memory.copy (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.copy (; 3 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -280,7 +279,7 @@ end end ) - (func $~lib/rt/__allocArray (; 4 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/__allocArray (; 4 ;) (result i32) (local $0 i32) (local $1 i32) i32.const 16 @@ -305,7 +304,7 @@ call $~lib/memory/memory.copy local.get $0 ) - (func $~lib/array/Array#__get (; 5 ;) (type $FUNCSIG$ji) (param $0 i32) (result i64) + (func $~lib/array/Array#__get (; 5 ;) (param $0 i32) (result i64) i32.const 0 local.get $0 i32.load offset=12 @@ -313,7 +312,7 @@ if i32.const 48 i32.const 104 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -527,7 +526,7 @@ call $~lib/array/Array#__get call $~lib/util/number/utoa64 ) - (func $resolve-access/Container#constructor (; 12 ;) (type $FUNCSIG$i) (result i32) + (func $resolve-access/Container#constructor (; 12 ;) (result i32) (local $0 i32) i32.const 8 i32.const 5 diff --git a/tests/compiler/resolve-access.untouched.wat b/tests/compiler/resolve-access.untouched.wat index 24f25c3c86..c232341e54 100644 --- a/tests/compiler/resolve-access.untouched.wat +++ b/tests/compiler/resolve-access.untouched.wat @@ -1449,7 +1449,7 @@ if i32.const 48 i32.const 104 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/resolve-binary.optimized.wat b/tests/compiler/resolve-binary.optimized.wat index 322bb33d15..593368cf67 100644 --- a/tests/compiler/resolve-binary.optimized.wat +++ b/tests/compiler/resolve-binary.optimized.wat @@ -9,8 +9,6 @@ (type $FUNCSIG$iijijiji (func (param i32 i64 i32 i64 i32 i64 i32) (result i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$dd (func (param f64) (result f64))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00t\00r\00u\00e") @@ -77,7 +75,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 3 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 3 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -392,7 +390,7 @@ end local.get $2 ) - (func $~lib/math/NativeMath.pow (; 10 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 10 ;) (param $0 f64) (result f64) (local $1 i32) (local $2 i64) (local $3 i32) @@ -1543,7 +1541,7 @@ local.get $10 i32.add ) - (func $~lib/string/String#substring (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 15 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1709,7 +1707,7 @@ local.get $1 call $~lib/rt/stub/__free ) - (func $resolve-binary/Bar#constructor (; 18 ;) (type $FUNCSIG$i) (result i32) + (func $resolve-binary/Bar#constructor (; 18 ;) (result i32) i32.const 0 i32.const 7 call $~lib/rt/stub/__alloc diff --git a/tests/compiler/resolve-elementaccess.optimized.wat b/tests/compiler/resolve-elementaccess.optimized.wat index 72d36abfc2..3a3e7f1e92 100644 --- a/tests/compiler/resolve-elementaccess.optimized.wat +++ b/tests/compiler/resolve-elementaccess.optimized.wat @@ -132,7 +132,7 @@ i32.store offset=12 local.get $3 ) - (func $~lib/memory/memory.fill (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.fill (; 3 ;) (param $0 i32) (local $1 i32) local.get $0 i32.const 0 @@ -176,7 +176,7 @@ i32.const 0 i32.store8 ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 4 ;) (param $0 i32) (result i32) (local $1 i32) i32.const 8 i32.const 0 @@ -1453,7 +1453,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/string/String#substring (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 14 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1624,7 +1624,7 @@ f64.promote_f32 call $~lib/util/number/dtoa ) - (func $~lib/util/string/compareImpl (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 18 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/resolve-function-expression.optimized.wat b/tests/compiler/resolve-function-expression.optimized.wat index 312582f088..9be81a72e1 100644 --- a/tests/compiler/resolve-function-expression.optimized.wat +++ b/tests/compiler/resolve-function-expression.optimized.wat @@ -4,7 +4,6 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "<\00\00\00\01\00\00\00\01\00\00\00<\00\00\00r\00e\00s\00o\00l\00v\00e\00-\00f\00u\00n\00c\00t\00i\00o\00n\00-\00e\00x\00p\00r\00e\00s\00s\00i\00o\00n\00.\00t\00s") @@ -122,7 +121,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 6 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -242,7 +241,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 10 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -322,7 +321,7 @@ end i32.const 0 ) - (func $~lib/string/String.__eq (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.__eq (; 11 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 128 diff --git a/tests/compiler/resolve-new.optimized.wat b/tests/compiler/resolve-new.optimized.wat index 7a0a791c2f..0d8a8ae53f 100644 --- a/tests/compiler/resolve-new.optimized.wat +++ b/tests/compiler/resolve-new.optimized.wat @@ -1,7 +1,6 @@ (module (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) @@ -50,7 +49,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (result i32) (local $0 i32) (local $1 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/resolve-propertyaccess.optimized.wat b/tests/compiler/resolve-propertyaccess.optimized.wat index 1f4a033cc1..a34b8819a9 100644 --- a/tests/compiler/resolve-propertyaccess.optimized.wat +++ b/tests/compiler/resolve-propertyaccess.optimized.wat @@ -5,7 +5,6 @@ (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\000") @@ -235,7 +234,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 7 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/resolve-ternary.optimized.wat b/tests/compiler/resolve-ternary.optimized.wat index 936454826b..9dfe9b6f13 100644 --- a/tests/compiler/resolve-ternary.optimized.wat +++ b/tests/compiler/resolve-ternary.optimized.wat @@ -506,7 +506,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 3 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 3 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1908,7 +1908,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 30 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 30 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -2956,7 +2956,7 @@ local.get $10 i32.add ) - (func $~lib/string/String#substring (; 35 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 35 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) diff --git a/tests/compiler/resolve-unary.optimized.wat b/tests/compiler/resolve-unary.optimized.wat index e2272f0f8e..45db37b000 100644 --- a/tests/compiler/resolve-unary.optimized.wat +++ b/tests/compiler/resolve-unary.optimized.wat @@ -5,7 +5,6 @@ (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\000") @@ -243,7 +242,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 7 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/retain-release-sanity.optimized.wat b/tests/compiler/retain-release-sanity.optimized.wat index cc50853844..57204658e0 100644 --- a/tests/compiler/retain-release-sanity.optimized.wat +++ b/tests/compiler/retain-release-sanity.optimized.wat @@ -486,7 +486,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1329,7 +1329,7 @@ i32.const 16 i32.add ) - (func $~lib/memory/memory.fill (; 21 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 21 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -1988,7 +1988,7 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 31 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 31 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2212,7 +2212,7 @@ i32.const 16 i32.add ) - (func $~lib/array/ensureSize (; 34 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/ensureSize (; 34 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2230,7 +2230,7 @@ if i32.const 24 i32.const 376 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -2267,7 +2267,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#push (; 35 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array#push (; 35 ;) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -2290,7 +2290,7 @@ local.get $2 i32.store offset=12 ) - (func $~lib/array/Array#pop (; 36 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array#pop (; 36 ;) (param $0 i32) (local $1 i32) local.get $0 i32.load offset=12 @@ -2300,7 +2300,7 @@ if i32.const 424 i32.const 376 - i32.const 288 + i32.const 289 i32.const 20 call $~lib/builtins/abort unreachable @@ -2320,7 +2320,7 @@ local.get $1 i32.store offset=12 ) - (func $~lib/array/Array<~lib/string/String>#push (; 37 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array<~lib/string/String>#push (; 37 ;) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 diff --git a/tests/compiler/retain-release-sanity.untouched.wat b/tests/compiler/retain-release-sanity.untouched.wat index 88797871e9..1418c4af1b 100644 --- a/tests/compiler/retain-release-sanity.untouched.wat +++ b/tests/compiler/retain-release-sanity.untouched.wat @@ -3830,7 +3830,7 @@ if i32.const 24 i32.const 376 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -3910,7 +3910,7 @@ if i32.const 424 i32.const 376 - i32.const 288 + i32.const 289 i32.const 20 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/retain-release.optimized.wat b/tests/compiler/retain-release.optimized.wat index 0e495740e7..aad83383e9 100644 --- a/tests/compiler/retain-release.optimized.wat +++ b/tests/compiler/retain-release.optimized.wat @@ -144,7 +144,7 @@ i32.store offset=12 local.get $3 ) - (func $retain-release/Ref#constructor (; 3 ;) (type $FUNCSIG$i) (result i32) + (func $retain-release/Ref#constructor (; 3 ;) (result i32) i32.const 0 i32.const 3 call $~lib/rt/stub/__alloc diff --git a/tests/compiler/rt/instanceof.optimized.wat b/tests/compiler/rt/instanceof.optimized.wat index 7162b0e5bd..b6736f8d39 100644 --- a/tests/compiler/rt/instanceof.optimized.wat +++ b/tests/compiler/rt/instanceof.optimized.wat @@ -4,7 +4,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) " \00\00\00\01\00\00\00\01\00\00\00 \00\00\00r\00t\00/\00i\00n\00s\00t\00a\00n\00c\00e\00o\00f\00.\00t\00s") @@ -62,7 +61,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset @@ -110,7 +109,7 @@ local.get $0 call $rt/instanceof/Animal#constructor ) - (func $rt/instanceof/BlackCat#constructor (; 5 ;) (type $FUNCSIG$i) (result i32) + (func $rt/instanceof/BlackCat#constructor (; 5 ;) (result i32) i32.const 5 call $~lib/rt/stub/__alloc call $rt/instanceof/Cat#constructor diff --git a/tests/compiler/runtime-full.optimized.wat b/tests/compiler/runtime-full.optimized.wat index 261c212f50..6534034492 100644 --- a/tests/compiler/runtime-full.optimized.wat +++ b/tests/compiler/runtime-full.optimized.wat @@ -477,7 +477,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 3 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 3 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index 6b5a00528f..d0d27cfb93 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -3,7 +3,6 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") @@ -25,7 +24,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -42,14 +41,14 @@ if i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable end local.get $0 ) - (func $~lib/array/Array#__get (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#__get (; 2 ;) (param $0 i32) (result i32) i32.const 1 local.get $0 i32.load offset=12 @@ -57,7 +56,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -88,7 +87,7 @@ call $~lib/array/Array<~lib/array/Array>#__get call $~lib/string/String#get:length ) - (func $~lib/util/string/compareImpl (; 6 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/util/string/compareImpl (; 6 ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) local.get $1 i32.const 1 @@ -172,7 +171,7 @@ end i32.const 0 ) - (func $~lib/string/String#startsWith (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#startsWith (; 7 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index 47c6d34b83..8f0341dc89 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -47,7 +47,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -63,7 +63,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -88,7 +88,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -137,7 +137,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -153,7 +153,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -420,7 +420,7 @@ if i32.const 24 i32.const 80 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -436,7 +436,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index 910538e5bd..97afe0eceb 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -47,7 +46,7 @@ if i32.const 136 i32.const 192 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -66,7 +65,7 @@ if i32.const 136 i32.const 192 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -530,7 +529,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 9 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1601,7 +1600,7 @@ end end ) - (func $~lib/rt/__allocArray (; 26 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/__allocArray (; 26 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 16 local.get $1 @@ -1627,13 +1626,13 @@ i32.store offset=12 local.get $1 ) - (func $std/array-literal/Ref#constructor (; 27 ;) (type $FUNCSIG$i) (result i32) + (func $std/array-literal/Ref#constructor (; 27 ;) (result i32) i32.const 0 i32.const 5 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain ) - (func $std/array-literal/RefWithCtor#constructor (; 28 ;) (type $FUNCSIG$i) (result i32) + (func $std/array-literal/RefWithCtor#constructor (; 28 ;) (result i32) i32.const 0 i32.const 7 call $~lib/rt/tlsf/__alloc diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index dc7ac7f4f2..a6dae3d912 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -71,7 +71,7 @@ if i32.const 136 i32.const 192 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -104,7 +104,7 @@ if i32.const 136 i32.const 192 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index b9831566c9..58f270fb6a 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -23,7 +23,6 @@ (type $FUNCSIG$ij (func (param i64) (result i32))) (type $FUNCSIG$viji (func (param i32 i64 i32))) (type $FUNCSIG$iiij (func (param i32 i32 i64) (result i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -695,7 +694,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 8 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 8 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -2281,7 +2280,7 @@ i32.store offset=8 local.get $0 ) - (func $~lib/array/Array#constructor (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#constructor (; 33 ;) (param $0 i32) (result i32) (local $1 i32) i32.const 16 i32.const 3 @@ -2303,7 +2302,7 @@ i32.const 0 i32.ne ) - (func $std/array/Ref#constructor (; 35 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/array/Ref#constructor (; 35 ;) (param $0 i32) (result i32) (local $1 i32) i32.const 4 i32.const 4 @@ -2422,7 +2421,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -2433,7 +2432,7 @@ i32.add i32.load8_u ) - (func $std/array/isArraysEqual (; 39 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual (; 39 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2564,7 +2563,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -2794,7 +2793,7 @@ i32.const 16 i32.add ) - (func $~lib/array/ensureSize (; 46 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/ensureSize (; 46 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2812,7 +2811,7 @@ if i32.const 24 i32.const 488 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -2850,7 +2849,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#push (; 47 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/Array#push (; 47 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2884,7 +2883,7 @@ if i32.const 872 i32.const 488 - i32.const 288 + i32.const 289 i32.const 20 call $~lib/builtins/abort unreachable @@ -2903,7 +2902,7 @@ local.get $1 i32.store offset=12 ) - (func $~lib/array/Array#set:length (; 49 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array#set:length (; 49 ;) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -2962,7 +2961,7 @@ if i32.const 24 i32.const 488 - i32.const 218 + i32.const 219 i32.const 59 call $~lib/builtins/abort unreachable @@ -3098,7 +3097,7 @@ local.get $0 call $~lib/rt/pure/__retain ) - (func $~lib/array/Array#unshift (; 52 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/Array#unshift (; 52 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) local.get $0 @@ -3140,7 +3139,7 @@ if i32.const 872 i32.const 488 - i32.const 349 + i32.const 350 i32.const 20 call $~lib/builtins/abort unreachable @@ -3283,7 +3282,7 @@ end i32.const -1 ) - (func $~lib/array/Array#indexOf (; 56 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#indexOf (; 56 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -3331,7 +3330,7 @@ end i32.const -1 ) - (func $~lib/array/Array#indexOf (; 57 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#indexOf (; 57 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -3387,7 +3386,7 @@ i32.const 0 i32.ge_s ) - (func $~lib/array/Array#includes (; 59 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#includes (; 59 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -3444,7 +3443,7 @@ end i32.const 0 ) - (func $~lib/array/Array#includes (; 60 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#includes (; 60 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 f64) @@ -3591,7 +3590,7 @@ i32.store offset=12 local.get $4 ) - (func $~lib/array/Array#splice (; 62 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#splice (; 62 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3700,7 +3699,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -3715,14 +3714,14 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable end local.get $0 ) - (func $~lib/array/Array#splice (; 65 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#splice (; 65 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -3808,7 +3807,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -3830,7 +3829,7 @@ if i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -4257,7 +4256,7 @@ local.get $0 f32.convert_i32_s ) - (func $~lib/array/Array#map (; 92 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#map (; 92 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4321,7 +4320,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -5168,7 +5167,7 @@ i32.lt_s i32.sub ) - (func $std/array/isArraysEqual (; 117 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual (; 117 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 f32) (local $4 i32) @@ -5678,7 +5677,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -5691,7 +5690,7 @@ i32.add f64.load ) - (func $std/array/isArraysEqual (; 123 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual (; 123 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 f64) (local $4 i32) @@ -6384,7 +6383,7 @@ if i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -6404,7 +6403,7 @@ local.get $2 call $~lib/array/Array<~lib/array/Array>#__unchecked_set ) - (func $std/array/createReverseOrderedNestedArray (; 138 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createReverseOrderedNestedArray (; 138 ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -6585,7 +6584,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $std/array/createReverseOrderedElementsArray (; 143 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createReverseOrderedElementsArray (; 143 ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -6719,7 +6718,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 148 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 148 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -6888,7 +6887,7 @@ call $~lib/util/string/compareImpl i32.eqz ) - (func $std/array/isArraysEqual<~lib/string/String | null> (; 151 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual<~lib/string/String | null> (; 151 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6947,7 +6946,7 @@ end i32.const 1 ) - (func $~lib/string/String#charAt (; 152 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#charAt (; 152 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 3520 @@ -7089,7 +7088,7 @@ end local.get $1 ) - (func $std/array/createRandomStringArray (; 156 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createRandomStringArray (; 156 ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -7131,7 +7130,7 @@ end local.get $0 ) - (func $~lib/string/String#substring (; 157 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 157 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -7205,7 +7204,7 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/util/string/joinBooleanArray (; 158 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinBooleanArray (; 158 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8846,7 +8845,7 @@ local.get $2 call $~lib/util/number/dtoa_core ) - (func $~lib/util/string/joinFloatArray (; 174 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinFloatArray (; 174 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9134,7 +9133,7 @@ local.get $1 call $~lib/util/string/joinReferenceArray<~lib/string/String | null> ) - (func $~lib/util/string/joinReferenceArray (; 177 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinReferenceArray (; 177 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9293,7 +9292,7 @@ call $~lib/rt/pure/__release local.get $1 ) - (func $~lib/array/Array#join (; 178 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#join (; 178 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -9360,7 +9359,7 @@ end local.get $2 ) - (func $~lib/util/string/joinIntegerArray (; 181 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 181 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9497,7 +9496,7 @@ call $~lib/util/number/utoa_simple local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 183 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 183 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9774,7 +9773,7 @@ end local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 188 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 188 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10010,7 +10009,7 @@ end local.get $3 ) - (func $~lib/util/string/joinIntegerArray (; 191 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 191 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10126,7 +10125,7 @@ i32.const 4672 call $~lib/array/Array<~lib/string/String | null>#join ) - (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 193 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 193 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10321,7 +10320,7 @@ call $~lib/util/number/utoa_simple local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 195 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 195 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10435,7 +10434,7 @@ i32.load offset=12 call $~lib/util/string/joinIntegerArray ) - (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 197 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 197 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10605,7 +10604,7 @@ i32.const 4672 call $~lib/array/Array#join ) - (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 199 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinReferenceArray<~lib/array/Array> (; 199 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -10777,7 +10776,7 @@ i32.load offset=12 call $~lib/util/string/joinReferenceArray<~lib/array/Array> ) - (func $~lib/util/string/joinReferenceArray<~lib/array/Array<~lib/array/Array>> (; 201 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinReferenceArray<~lib/array/Array<~lib/array/Array>> (; 201 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 93b37ee043..62e48c5d6e 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -4107,7 +4107,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -4311,7 +4311,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -4638,7 +4638,7 @@ if i32.const 24 i32.const 488 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -4724,7 +4724,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -4747,7 +4747,7 @@ if i32.const 872 i32.const 488 - i32.const 288 + i32.const 289 i32.const 20 call $~lib/builtins/abort unreachable @@ -4855,7 +4855,7 @@ call $~lib/rt/pure/__release i32.const 24 i32.const 488 - i32.const 218 + i32.const 219 i32.const 59 call $~lib/builtins/abort unreachable @@ -5155,7 +5155,7 @@ if i32.const 872 i32.const 488 - i32.const 349 + i32.const 350 i32.const 20 call $~lib/builtins/abort unreachable @@ -5867,7 +5867,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -5883,7 +5883,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -6021,7 +6021,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -6054,7 +6054,7 @@ if i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -6779,7 +6779,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -8710,7 +8710,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -10096,7 +10096,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -10377,7 +10377,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -10393,7 +10393,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -10576,7 +10576,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -10850,7 +10850,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -10866,7 +10866,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable @@ -11155,7 +11155,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -11958,7 +11958,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -12210,7 +12210,7 @@ if i32.const 280 i32.const 488 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -12226,7 +12226,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index 8b687fa733..c8c6a4a38b 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -7,7 +7,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -484,7 +483,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1327,7 +1326,7 @@ i32.const 16 i32.add ) - (func $~lib/memory/memory.fill (; 21 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 21 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -2060,7 +2059,7 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 33 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 33 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2129,7 +2128,7 @@ i32.store offset=8 local.get $0 ) - (func $~lib/rt/__allocArray (; 34 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/__allocArray (; 34 ;) (result i32) (local $0 i32) (local $1 i32) i32.const 16 @@ -2157,7 +2156,7 @@ call $~lib/memory/memory.copy local.get $0 ) - (func $~lib/dataview/DataView#constructor (; 35 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/dataview/DataView#constructor (; 35 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) diff --git a/tests/compiler/std/dataview.optimized.wat b/tests/compiler/std/dataview.optimized.wat index 58f136d03a..2965ed9f23 100644 --- a/tests/compiler/std/dataview.optimized.wat +++ b/tests/compiler/std/dataview.optimized.wat @@ -9,11 +9,6 @@ (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$fiii (func (param i32 i32 i32) (result f32))) (type $FUNCSIG$jj (func (param i64) (result i64))) - (type $FUNCSIG$dii (func (param i32 i32) (result f64))) - (type $FUNCSIG$jii (func (param i32 i32) (result i64))) - (type $FUNCSIG$vifi (func (param i32 f32 i32))) - (type $FUNCSIG$vidi (func (param i32 f64 i32))) - (type $FUNCSIG$viji (func (param i32 i64 i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -490,7 +485,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1333,7 +1328,7 @@ i32.const 16 i32.add ) - (func $~lib/memory/memory.fill (; 21 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.fill (; 21 ;) (param $0 i32) (local $1 i32) local.get $0 i32.const 0 @@ -1827,7 +1822,7 @@ call $~lib/rt/pure/decrement end ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 31 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -1905,7 +1900,7 @@ i32.sub i32.load offset=12 ) - (func $~lib/dataview/DataView#constructor (; 34 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/dataview/DataView#constructor (; 34 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2049,7 +2044,7 @@ i64.const 32 i64.rotr ) - (func $~lib/dataview/DataView#getFloat64 (; 39 ;) (type $FUNCSIG$dii) (param $0 i32) (param $1 i32) (result f64) + (func $~lib/dataview/DataView#getFloat64 (; 39 ;) (param $0 i32) (param $1 i32) (result f64) i32.const 8 local.get $0 i32.load offset=8 @@ -2175,7 +2170,7 @@ end local.get $0 ) - (func $~lib/dataview/DataView#getInt64 (; 44 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/dataview/DataView#getInt64 (; 44 ;) (param $0 i32) (param $1 i32) (result i64) (local $2 i64) i32.const 8 local.get $0 @@ -2299,7 +2294,7 @@ end local.get $0 ) - (func $~lib/dataview/DataView#getUint64 (; 49 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/dataview/DataView#getUint64 (; 49 ;) (param $0 i32) (param $1 i32) (result i64) (local $2 i64) i32.const 8 local.get $0 @@ -2325,7 +2320,7 @@ call $~lib/polyfills/bswap end ) - (func $~lib/dataview/DataView#setFloat32 (; 50 ;) (type $FUNCSIG$vifi) (param $0 i32) (param $1 f32) (param $2 i32) + (func $~lib/dataview/DataView#setFloat32 (; 50 ;) (param $0 i32) (param $1 f32) (param $2 i32) i32.const 4 local.get $0 i32.load offset=8 @@ -2353,7 +2348,7 @@ i32.store end ) - (func $~lib/dataview/DataView#setFloat64 (; 51 ;) (type $FUNCSIG$vidi) (param $0 i32) (param $1 f64) (param $2 i32) + (func $~lib/dataview/DataView#setFloat64 (; 51 ;) (param $0 i32) (param $1 f64) (param $2 i32) i32.const 8 local.get $0 i32.load offset=8 @@ -2381,7 +2376,7 @@ i64.store end ) - (func $~lib/dataview/DataView#setInt8 (; 52 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/dataview/DataView#setInt8 (; 52 ;) (param $0 i32) i32.const 0 local.get $0 i32.load offset=8 @@ -2399,7 +2394,7 @@ i32.const 108 i32.store8 ) - (func $~lib/dataview/DataView#setInt16 (; 53 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/dataview/DataView#setInt16 (; 53 ;) (param $0 i32) (param $1 i32) (param $2 i32) i32.const 2 local.get $0 i32.load offset=8 @@ -2423,7 +2418,7 @@ end i32.store16 ) - (func $~lib/dataview/DataView#setInt32 (; 54 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/dataview/DataView#setInt32 (; 54 ;) (param $0 i32) (param $1 i32) (param $2 i32) i32.const 4 local.get $0 i32.load offset=8 @@ -2447,7 +2442,7 @@ end i32.store ) - (func $~lib/dataview/DataView#setInt64 (; 55 ;) (type $FUNCSIG$viji) (param $0 i32) (param $1 i64) (param $2 i32) + (func $~lib/dataview/DataView#setInt64 (; 55 ;) (param $0 i32) (param $1 i64) (param $2 i32) i32.const 8 local.get $0 i32.load offset=8 @@ -2471,7 +2466,7 @@ end i64.store ) - (func $~lib/dataview/DataView#setUint8 (; 56 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/dataview/DataView#setUint8 (; 56 ;) (param $0 i32) i32.const 0 local.get $0 i32.load offset=8 @@ -2489,7 +2484,7 @@ i32.const 238 i32.store8 ) - (func $~lib/dataview/DataView#setUint16 (; 57 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/dataview/DataView#setUint16 (; 57 ;) (param $0 i32) (param $1 i32) (param $2 i32) i32.const 2 local.get $0 i32.load offset=8 @@ -2513,7 +2508,7 @@ end i32.store16 ) - (func $~lib/dataview/DataView#setUint32 (; 58 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/dataview/DataView#setUint32 (; 58 ;) (param $0 i32) (param $1 i32) (param $2 i32) i32.const 4 local.get $0 i32.load offset=8 @@ -2537,7 +2532,7 @@ end i32.store ) - (func $~lib/dataview/DataView#setUint64 (; 59 ;) (type $FUNCSIG$viji) (param $0 i32) (param $1 i64) (param $2 i32) + (func $~lib/dataview/DataView#setUint64 (; 59 ;) (param $0 i32) (param $1 i64) (param $2 i32) i32.const 8 local.get $0 i32.load offset=8 @@ -2561,7 +2556,7 @@ end i64.store ) - (func $~lib/dataview/DataView#constructor|trampoline (; 60 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/dataview/DataView#constructor|trampoline (; 60 ;) (param $0 i32) (result i32) (local $1 i32) block $2of2 block $1of2 diff --git a/tests/compiler/std/date.optimized.wat b/tests/compiler/std/date.optimized.wat index 06c01aa074..8ea9f4c6eb 100644 --- a/tests/compiler/std/date.optimized.wat +++ b/tests/compiler/std/date.optimized.wat @@ -4,7 +4,6 @@ (type $FUNCSIG$d (func (result f64))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) (import "Date" "UTC" (func $~lib/bindings/Date/UTC (param i32 i32 i32 i32 i32 i32 f64) (result f64))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "Date" "now" (func $~lib/bindings/Date/now (result f64))) @@ -58,7 +57,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 4 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/stub/__alloc (; 4 ;) (result i32) (local $0 i32) (local $1 i32) global.get $~lib/rt/stub/offset diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index a11b6aea6d..514fb9366d 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -8,7 +8,6 @@ (type $FUNCSIG$fff (func (param f32 f32) (result f32))) (type $FUNCSIG$ffi (func (param f32 i32) (result f32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ij (func (param i64) (result i32))) (memory $0 1) (data (i32.const 8) "\c0\00\00\00\01\00\00\00\00\00\00\00\c0\00\00\00n\83\f9\a2\00\00\00\00\d1W\'\fc)\15DN\99\95b\db\c0\dd4\f5\abcQ\feA\90C<:n$\b7a\c5\bb\de\ea.I\06\e0\d2MB\1c\eb\1d\fe\1c\92\d1\t\f55\82\e8>\a7)\b1&p\9c\e9\84D\bb.9\d6\919A~_\b4\8b_\84\9c\f49S\83\ff\97\f8\1f;(\f9\bd\8b\11/\ef\0f\98\05\de\cf~6m\1fm\nZf?FO\b7\t\cb\'\c7\ba\'u-\ea_\9e\f79\07={\f1\e5\eb\b1_\fbk\ea\92R\8aF0\03V\08]\8d\1f \bc\cf\f0\abk{\fca\91\e3\a9\1d6\f4\9a_\85\99e\08\1b\e6^\80\d8\ff\8d@h\a0\14W\15\06\061\'sM") (data (i32.const 216) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\c0\00\00\00\18") @@ -1605,7 +1604,7 @@ f64.convert_i32_s end ) - (func $~lib/math/pio2_large_quot (; 23 ;) (type $FUNCSIG$ij) (param $0 i64) (result i32) + (func $~lib/math/pio2_large_quot (; 23 ;) (param $0 i64) (result i32) (local $1 i64) (local $2 i64) (local $3 i64) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 21be66eb98..d8244b6f3c 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -17,10 +17,6 @@ (type $FUNCSIG$iid (func (param i32 f64) (result i32))) (type $FUNCSIG$iidi (func (param i32 f64 i32) (result i32))) (type $FUNCSIG$vidi (func (param i32 f64 i32))) - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$vij (func (param i32 i64))) - (type $FUNCSIG$vif (func (param i32 f32))) - (type $FUNCSIG$vid (func (param i32 f64))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -496,7 +492,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1392,7 +1388,7 @@ end local.get $0 ) - (func $~lib/memory/memory.fill (; 23 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 23 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -1601,7 +1597,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 24 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 1073741808 @@ -2053,7 +2049,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map#constructor (; 33 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 33 ;) (result i32) (local $0 i32) i32.const 24 i32.const 3 @@ -2395,7 +2391,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 40 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#delete (; 40 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -2804,7 +2800,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 42 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 42 ;) (result i32) (local $0 i32) i32.const 24 i32.const 4 @@ -3088,7 +3084,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 47 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#delete (; 47 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -3481,7 +3477,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 49 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 49 ;) (result i32) (local $0 i32) i32.const 24 i32.const 5 @@ -3831,7 +3827,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 56 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#delete (; 56 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -4240,7 +4236,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 58 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 58 ;) (result i32) (local $0 i32) i32.const 24 i32.const 6 @@ -4524,7 +4520,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 63 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#delete (; 63 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -4917,7 +4913,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 65 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 65 ;) (result i32) (local $0 i32) i32.const 24 i32.const 7 @@ -5269,7 +5265,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 72 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#delete (; 72 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -5646,7 +5642,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 74 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 74 ;) (result i32) (local $0 i32) i32.const 24 i32.const 8 @@ -6025,7 +6021,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map#constructor (; 77 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 77 ;) (result i32) (local $0 i32) i32.const 24 i32.const 9 @@ -6412,7 +6408,7 @@ local.get $0 i32.load offset=8 ) - (func $~lib/map/Map#delete (; 84 ;) (type $FUNCSIG$vij) (param $0 i32) (param $1 i64) + (func $~lib/map/Map#delete (; 84 ;) (param $0 i32) (param $1 i64) (local $2 i32) (local $3 i32) local.get $0 @@ -6797,7 +6793,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 86 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 86 ;) (result i32) (local $0 i32) i32.const 24 i32.const 10 @@ -7150,7 +7146,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 88 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 88 ;) (result i32) (local $0 i32) i32.const 24 i32.const 11 @@ -7475,7 +7471,7 @@ local.get $0 i32.load offset=4 ) - (func $~lib/map/Map#delete (; 94 ;) (type $FUNCSIG$vif) (param $0 i32) (param $1 f32) + (func $~lib/map/Map#delete (; 94 ;) (param $0 i32) (param $1 f32) (local $2 i32) (local $3 i32) local.get $0 @@ -7861,7 +7857,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/map/Map#constructor (; 96 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 96 ;) (result i32) (local $0 i32) i32.const 24 i32.const 12 @@ -8186,7 +8182,7 @@ local.get $0 i32.load offset=8 ) - (func $~lib/map/Map#delete (; 102 ;) (type $FUNCSIG$vid) (param $0 i32) (param $1 f64) + (func $~lib/map/Map#delete (; 102 ;) (param $0 i32) (param $1 f64) (local $2 i32) (local $3 i32) local.get $0 diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index ebc91fd300..03d0f2e0c1 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -18,16 +18,6 @@ (type $FUNCSIG$vd (func (param f64))) (type $FUNCSIG$jji (func (param i64 i32) (result i64))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iddd (func (param f64 f64 f64) (result i32))) - (type $FUNCSIG$ifff (func (param f32 f32 f32) (result i32))) - (type $FUNCSIG$idid (func (param f64 i32 f64) (result i32))) - (type $FUNCSIG$ifif (func (param f32 i32 f32) (result i32))) - (type $FUNCSIG$idd (func (param f64 f64) (result i32))) - (type $FUNCSIG$iff (func (param f32 f32) (result i32))) - (type $FUNCSIG$idddd (func (param f64 f64 f64 f64) (result i32))) - (type $FUNCSIG$iffff (func (param f32 f32 f32 f32) (result i32))) - (type $FUNCSIG$ij (func (param i64) (result i32))) - (type $FUNCSIG$vjjjjj (func (param i64 i64 i64 i64 i64))) (import "Math" "E" (global $~lib/bindings/Math/E f64)) (import "Math" "LN2" (global $~lib/bindings/Math/LN2 f64)) (import "Math" "LN10" (global $~lib/bindings/Math/LN10 f64)) @@ -255,7 +245,7 @@ local.get $2 f64.add ) - (func $std/math/check (; 34 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/check (; 34 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 local.get $1 f64.eq @@ -448,7 +438,7 @@ local.get $2 f32.add ) - (func $std/math/check (; 37 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/check (; 37 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 local.get $1 f32.eq @@ -478,7 +468,7 @@ end i32.const 1 ) - (func $std/math/test_scalbn (; 38 ;) (type $FUNCSIG$idid) (param $0 f64) (param $1 i32) (param $2 f64) (result i32) + (func $std/math/test_scalbn (; 38 ;) (param $0 f64) (param $1 i32) (param $2 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.scalbn @@ -486,7 +476,7 @@ f64.const 0 call $std/math/check ) - (func $std/math/test_scalbnf (; 39 ;) (type $FUNCSIG$ifif) (param $0 f32) (param $1 i32) (param $2 f32) (result i32) + (func $std/math/test_scalbnf (; 39 ;) (param $0 f32) (param $1 i32) (param $2 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.scalbn @@ -494,7 +484,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_abs (; 40 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_abs (; 40 ;) (param $0 f64) (param $1 f64) (result i32) local.get $0 f64.abs local.get $1 @@ -510,7 +500,7 @@ i32.const 0 end ) - (func $std/math/test_absf (; 41 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_absf (; 41 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 f32.abs local.get $1 @@ -684,7 +674,7 @@ f64.add f64.mul ) - (func $std/math/test_acos (; 44 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_acos (; 44 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.acos local.get $1 @@ -835,7 +825,7 @@ f32.add f32.mul ) - (func $std/math/test_acosf (; 47 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_acosf (; 47 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.acos local.get $1 @@ -1263,7 +1253,7 @@ f64.const 0.6931471805599453 f64.add ) - (func $std/math/test_acosh (; 51 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_acosh (; 51 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.acosh local.get $1 @@ -1633,7 +1623,7 @@ f32.const 0.6931471824645996 f32.add ) - (func $std/math/test_acoshf (; 55 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_acoshf (; 55 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.acosh local.get $1 @@ -1778,7 +1768,7 @@ end local.get $0 ) - (func $std/math/test_asin (; 57 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_asin (; 57 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.asin local.get $1 @@ -1874,7 +1864,7 @@ local.get $0 f32.copysign ) - (func $std/math/test_asinf (; 59 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_asinf (; 59 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.asin local.get $1 @@ -1951,7 +1941,7 @@ local.get $0 f64.copysign ) - (func $std/math/test_asinh (; 61 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_asinh (; 61 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.asinh local.get $1 @@ -2032,7 +2022,7 @@ local.get $0 f32.copysign ) - (func $std/math/test_asinhf (; 63 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_asinhf (; 63 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.asinh local.get $1 @@ -2265,7 +2255,7 @@ local.get $3 f64.copysign ) - (func $std/math/test_atan (; 65 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_atan (; 65 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.atan local.get $1 @@ -2480,7 +2470,7 @@ local.get $4 f32.copysign ) - (func $std/math/test_atanf (; 67 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_atanf (; 67 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.atan local.get $1 @@ -2541,7 +2531,7 @@ local.get $0 f64.copysign ) - (func $std/math/test_atanh (; 69 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_atanh (; 69 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.atanh local.get $1 @@ -2605,7 +2595,7 @@ local.get $0 f32.copysign ) - (func $std/math/test_atanhf (; 71 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_atanhf (; 71 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.atanh local.get $1 @@ -2832,7 +2822,7 @@ i32.and select ) - (func $std/math/test_atan2 (; 73 ;) (type $FUNCSIG$idddd) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) + (func $std/math/test_atan2 (; 73 ;) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.atan2 @@ -3046,7 +3036,7 @@ i32.and select ) - (func $std/math/test_atan2f (; 75 ;) (type $FUNCSIG$iffff) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) + (func $std/math/test_atan2f (; 75 ;) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.atan2 @@ -3176,7 +3166,7 @@ f64.mul f64.add ) - (func $std/math/test_cbrt (; 77 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_cbrt (; 77 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.cbrt local.get $1 @@ -3291,14 +3281,14 @@ f64.div f32.demote_f64 ) - (func $std/math/test_cbrtf (; 79 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_cbrtf (; 79 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.cbrt local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_ceil (; 80 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_ceil (; 80 ;) (param $0 f64) (param $1 f64) (result i32) local.get $0 f64.ceil local.get $1 @@ -3314,14 +3304,14 @@ i32.const 0 end ) - (func $std/math/test_ceilf (; 81 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_ceilf (; 81 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 f32.ceil local.get $1 f32.const 0 call $std/math/check ) - (func $~lib/math/pio2_large_quot (; 82 ;) (type $FUNCSIG$ij) (param $0 i64) (result i32) + (func $~lib/math/pio2_large_quot (; 82 ;) (param $0 i64) (result i32) (local $1 i64) (local $2 i64) (local $3 i64) @@ -3953,7 +3943,7 @@ end local.get $0 ) - (func $std/math/test_cos (; 84 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_cos (; 84 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.cos local.get $1 @@ -4239,7 +4229,7 @@ end local.get $0 ) - (func $std/math/test_cosf (; 86 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_cosf (; 86 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.cos local.get $1 @@ -4736,7 +4726,7 @@ f64.const 2247116418577894884661631e283 f64.mul ) - (func $std/math/test_cosh (; 90 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_cosh (; 90 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.cosh local.get $1 @@ -5198,14 +5188,14 @@ f32.const 1661534994731144841129758e11 f32.mul ) - (func $std/math/test_coshf (; 94 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_coshf (; 94 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.cosh local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_exp (; 95 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_exp (; 95 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.exp local.get $1 @@ -5221,14 +5211,14 @@ i32.const 0 end ) - (func $std/math/test_expf (; 96 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_expf (; 96 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.exp local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_expm1 (; 97 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_expm1 (; 97 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.expm1 local.get $1 @@ -5244,14 +5234,14 @@ i32.const 0 end ) - (func $std/math/test_expm1f (; 98 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_expm1f (; 98 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.expm1 local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_floor (; 99 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_floor (; 99 ;) (param $0 f64) (param $1 f64) (result i32) local.get $0 f64.floor local.get $1 @@ -5267,7 +5257,7 @@ i32.const 0 end ) - (func $std/math/test_floorf (; 100 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_floorf (; 100 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 f32.floor local.get $1 @@ -5444,7 +5434,7 @@ f64.sqrt f64.mul ) - (func $std/math/test_hypot (; 102 ;) (type $FUNCSIG$idddd) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) + (func $std/math/test_hypot (; 102 ;) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.hypot @@ -5557,7 +5547,7 @@ f32.sqrt f32.mul ) - (func $std/math/test_hypotf (; 104 ;) (type $FUNCSIG$iffff) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) + (func $std/math/test_hypotf (; 104 ;) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.hypot @@ -5565,7 +5555,7 @@ local.get $3 call $std/math/check ) - (func $std/math/test_log (; 105 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_log (; 105 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.log local.get $1 @@ -5581,7 +5571,7 @@ i32.const 0 end ) - (func $std/math/test_logf (; 106 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_logf (; 106 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.log local.get $1 @@ -5790,7 +5780,7 @@ local.get $1 f64.add ) - (func $std/math/test_log10 (; 108 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_log10 (; 108 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.log10 local.get $1 @@ -5964,14 +5954,14 @@ f32.mul f32.add ) - (func $std/math/test_log10f (; 110 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_log10f (; 110 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.log10 local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_log1p (; 111 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_log1p (; 111 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.log1p local.get $1 @@ -5987,7 +5977,7 @@ i32.const 0 end ) - (func $std/math/test_log1pf (; 112 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_log1pf (; 112 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.log1p local.get $1 @@ -6189,7 +6179,7 @@ local.get $1 f64.add ) - (func $std/math/test_log2 (; 114 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_log2 (; 114 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.log2 local.get $1 @@ -6355,14 +6345,14 @@ f32.convert_i32_s f32.add ) - (func $std/math/test_log2f (; 116 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_log2f (; 116 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.log2 local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_max (; 117 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_max (; 117 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 local.get $1 f64.max @@ -6380,7 +6370,7 @@ i32.const 0 end ) - (func $std/math/test_maxf (; 118 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_maxf (; 118 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 local.get $1 f32.max @@ -6388,7 +6378,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_min (; 119 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_min (; 119 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 local.get $1 f64.min @@ -6406,7 +6396,7 @@ i32.const 0 end ) - (func $std/math/test_minf (; 120 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_minf (; 120 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 local.get $1 f32.min @@ -6617,7 +6607,7 @@ local.get $0 f64.mul ) - (func $std/math/test_mod (; 122 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_mod (; 122 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.mod @@ -6827,7 +6817,7 @@ local.get $0 f32.mul ) - (func $std/math/test_modf (; 124 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_modf (; 124 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.mod @@ -7743,7 +7733,7 @@ f64.const 1e-300 f64.mul ) - (func $std/math/test_pow (; 126 ;) (type $FUNCSIG$idddd) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) + (func $std/math/test_pow (; 126 ;) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.pow @@ -8547,7 +8537,7 @@ f32.const 1.0000000031710769e-30 f32.mul ) - (func $std/math/test_powf (; 128 ;) (type $FUNCSIG$iffff) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) + (func $std/math/test_powf (; 128 ;) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.pow @@ -8742,7 +8732,7 @@ f32.const 1 f32.sub ) - (func $std/math/test_round (; 134 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_round (; 134 ;) (param $0 f64) (param $1 f64) (result i32) local.get $0 f64.const 0.5 f64.add @@ -8753,7 +8743,7 @@ f64.const 0 call $std/math/check ) - (func $std/math/test_roundf (; 135 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_roundf (; 135 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 f32.const 0.5 f32.add @@ -8764,7 +8754,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_sign (; 136 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_sign (; 136 ;) (param $0 f64) (param $1 f64) (result i32) (local $2 f64) local.get $0 local.set $2 @@ -8790,7 +8780,7 @@ i32.const 0 end ) - (func $std/math/test_signf (; 137 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_signf (; 137 ;) (param $0 f32) (param $1 f32) (result i32) f32.const 1 local.get $0 f32.copysign @@ -9056,7 +9046,7 @@ end local.get $0 ) - (func $std/math/test_rem (; 139 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_rem (; 139 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMath.rem @@ -9308,7 +9298,7 @@ end local.get $0 ) - (func $std/math/test_remf (; 141 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_remf (; 141 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 local.get $1 call $~lib/math/NativeMathf.rem @@ -9638,7 +9628,7 @@ end local.get $0 ) - (func $std/math/test_sin (; 143 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_sin (; 143 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.sin local.get $1 @@ -9925,7 +9915,7 @@ end local.get $0 ) - (func $std/math/test_sinf (; 145 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_sinf (; 145 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.sin local.get $1 @@ -10009,7 +9999,7 @@ f64.mul f64.mul ) - (func $std/math/test_sinh (; 147 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_sinh (; 147 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.sinh local.get $1 @@ -10097,14 +10087,14 @@ f32.mul f32.mul ) - (func $std/math/test_sinhf (; 149 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_sinhf (; 149 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.sinh local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_sqrt (; 150 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_sqrt (; 150 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 f64.sqrt local.get $1 @@ -10120,7 +10110,7 @@ i32.const 0 end ) - (func $std/math/test_sqrtf (; 151 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_sqrtf (; 151 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 f32.sqrt local.get $1 @@ -10488,7 +10478,7 @@ i32.sub call $~lib/math/tan_kern ) - (func $std/math/test_tan (; 154 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_tan (; 154 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.tan local.get $1 @@ -10759,7 +10749,7 @@ local.get $1 f32.demote_f64 ) - (func $std/math/test_tanf (; 156 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_tanf (; 156 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.tan local.get $1 @@ -10845,7 +10835,7 @@ local.get $0 f64.copysign ) - (func $std/math/test_tanh (; 158 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_tanh (; 158 ;) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) local.get $0 call $~lib/math/NativeMath.tanh local.get $1 @@ -10935,14 +10925,14 @@ local.get $0 f32.copysign ) - (func $std/math/test_tanhf (; 160 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_tanhf (; 160 ;) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) local.get $0 call $~lib/math/NativeMathf.tanh local.get $1 local.get $2 call $std/math/check ) - (func $std/math/test_trunc (; 161 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_trunc (; 161 ;) (param $0 f64) (param $1 f64) (result i32) local.get $0 f64.trunc local.get $1 @@ -10958,7 +10948,7 @@ i32.const 0 end ) - (func $std/math/test_truncf (; 162 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_truncf (; 162 ;) (param $0 f32) (param $1 f32) (result i32) local.get $0 f32.trunc local.get $1 @@ -11363,7 +11353,7 @@ local.get $1 global.set $~lib/math/NativeMath.sincos_cos ) - (func $std/math/test_sincos (; 164 ;) (type $FUNCSIG$vjjjjj) (param $0 i64) (param $1 i64) (param $2 i64) (param $3 i64) (param $4 i64) + (func $std/math/test_sincos (; 164 ;) (param $0 i64) (param $1 i64) (param $2 i64) (param $3 i64) (param $4 i64) (local $5 f64) (local $6 f64) local.get $3 diff --git a/tests/compiler/std/new.optimized.wat b/tests/compiler/std/new.optimized.wat index d537cbb35b..0e0d912479 100644 --- a/tests/compiler/std/new.optimized.wat +++ b/tests/compiler/std/new.optimized.wat @@ -1,7 +1,6 @@ (module (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) @@ -50,7 +49,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 1 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/stub/__alloc (; 1 ;) (result i32) (local $0 i32) (local $1 i32) global.get $~lib/rt/stub/offset @@ -77,7 +76,7 @@ i32.store offset=12 local.get $1 ) - (func $std/new/AClass#constructor (; 2 ;) (type $FUNCSIG$i) (result i32) + (func $std/new/AClass#constructor (; 2 ;) (result i32) (local $0 i32) call $~lib/rt/stub/__alloc local.tee $0 diff --git a/tests/compiler/std/object-literal.optimized.wat b/tests/compiler/std/object-literal.optimized.wat index 99f0a7fc0d..2c7d97155f 100644 --- a/tests/compiler/std/object-literal.optimized.wat +++ b/tests/compiler/std/object-literal.optimized.wat @@ -4,7 +4,6 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d") @@ -108,7 +107,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 4 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 4 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -188,7 +187,7 @@ end i32.const 0 ) - (func $~lib/string/String.__eq (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.__eq (; 5 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 24 diff --git a/tests/compiler/std/object.optimized.wat b/tests/compiler/std/object.optimized.wat index e3f679a4d6..0c42abf545 100644 --- a/tests/compiler/std/object.optimized.wat +++ b/tests/compiler/std/object.optimized.wat @@ -5,7 +5,6 @@ (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00s\00t\00d\00/\00o\00b\00j\00e\00c\00t\00.\00t\00s") @@ -77,7 +76,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 6 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/std/operator-overloading.optimized.wat b/tests/compiler/std/operator-overloading.optimized.wat index 9f3306a420..9e154ba35a 100644 --- a/tests/compiler/std/operator-overloading.optimized.wat +++ b/tests/compiler/std/operator-overloading.optimized.wat @@ -5,7 +5,6 @@ (type $FUNCSIG$ddd (func (param f64 f64) (result f64))) (type $FUNCSIG$ddi (func (param f64 i32) (result f64))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "6\00\00\00\01\00\00\00\01\00\00\006\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") @@ -121,7 +120,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) global.get $~lib/rt/stub/offset @@ -148,7 +147,7 @@ i32.store offset=12 local.get $2 ) - (func $std/operator-overloading/Tester#constructor (; 3 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/Tester#constructor (; 3 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 3 call $~lib/rt/stub/__alloc @@ -1196,7 +1195,7 @@ i32.const 0 end ) - (func $std/operator-overloading/TesterInlineStatic#constructor (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/TesterInlineStatic#constructor (; 9 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 4 call $~lib/rt/stub/__alloc @@ -1208,7 +1207,7 @@ i32.store offset=4 local.get $2 ) - (func $std/operator-overloading/TesterInlineInstance#constructor (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/operator-overloading/TesterInlineInstance#constructor (; 10 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 5 call $~lib/rt/stub/__alloc diff --git a/tests/compiler/std/pointer.optimized.wat b/tests/compiler/std/pointer.optimized.wat index 2dbea92c9e..cd1e2763ee 100644 --- a/tests/compiler/std/pointer.optimized.wat +++ b/tests/compiler/std/pointer.optimized.wat @@ -1,8 +1,6 @@ (module (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$vii (func (param i32 i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00s\00t\00d\00/\00p\00o\00i\00n\00t\00e\00r\00.\00t\00s") @@ -14,7 +12,7 @@ (global $std/pointer/buf (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) - (func $~lib/memory/memory.fill (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/memory/memory.fill (; 1 ;) (param $0 i32) (local $1 i32) local.get $0 i32.const 0 @@ -58,7 +56,7 @@ i32.const 0 i32.store8 ) - (func $~lib/memory/memory.copy (; 2 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.copy (; 2 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index 423232b1f2..8cc01ef6dc 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -17,7 +17,6 @@ (type $FUNCSIG$iid (func (param i32 f64) (result i32))) (type $FUNCSIG$iidi (func (param i32 f64 i32) (result i32))) (type $FUNCSIG$vid (func (param i32 f64))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -491,7 +490,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1387,7 +1386,7 @@ end local.get $0 ) - (func $~lib/memory/memory.fill (; 23 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 23 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -1596,7 +1595,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 24 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 1073741808 @@ -2048,7 +2047,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set#constructor (; 33 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 33 ;) (result i32) (local $0 i32) i32.const 24 i32.const 3 @@ -2356,7 +2355,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 39 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#delete (; 39 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -2666,7 +2665,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 41 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 41 ;) (result i32) (local $0 i32) i32.const 24 i32.const 4 @@ -2918,7 +2917,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 45 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#delete (; 45 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -3226,7 +3225,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 47 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 47 ;) (result i32) (local $0 i32) i32.const 24 i32.const 5 @@ -3542,7 +3541,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 53 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#delete (; 53 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -3852,7 +3851,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 55 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 55 ;) (result i32) (local $0 i32) i32.const 24 i32.const 6 @@ -4104,7 +4103,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 59 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#delete (; 59 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -4412,7 +4411,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 61 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 61 ;) (result i32) (local $0 i32) i32.const 24 i32.const 7 @@ -4734,7 +4733,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 67 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#delete (; 67 ;) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 local.get $1 @@ -5040,7 +5039,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 69 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 69 ;) (result i32) (local $0 i32) i32.const 24 i32.const 8 @@ -5348,7 +5347,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set#constructor (; 72 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 72 ;) (result i32) (local $0 i32) i32.const 24 i32.const 9 @@ -5705,7 +5704,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 78 ;) (type $FUNCSIG$vij) (param $0 i32) (param $1 i64) + (func $~lib/set/Set#delete (; 78 ;) (param $0 i32) (param $1 i64) (local $2 i32) (local $3 i32) local.get $0 @@ -6012,7 +6011,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 80 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 80 ;) (result i32) (local $0 i32) i32.const 24 i32.const 10 @@ -6287,7 +6286,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 82 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 82 ;) (result i32) (local $0 i32) i32.const 24 i32.const 11 @@ -6581,7 +6580,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 87 ;) (type $FUNCSIG$vif) (param $0 i32) (param $1 f32) + (func $~lib/set/Set#delete (; 87 ;) (param $0 i32) (param $1 f32) (local $2 i32) (local $3 i32) local.get $0 @@ -6889,7 +6888,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/set/Set#constructor (; 89 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 89 ;) (result i32) (local $0 i32) i32.const 24 i32.const 12 @@ -7183,7 +7182,7 @@ i32.store end ) - (func $~lib/set/Set#delete (; 94 ;) (type $FUNCSIG$vid) (param $0 i32) (param $1 f64) + (func $~lib/set/Set#delete (; 94 ;) (param $0 i32) (param $1 f64) (local $2 i32) (local $3 i32) local.get $0 diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index 86307a5777..be1bb940b2 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -4,11 +4,6 @@ (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) - (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$ji (func (param i32) (result i64))) - (type $FUNCSIG$fi (func (param i32) (result f32))) - (type $FUNCSIG$di (func (param i32) (result f64))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\08\00\00\00\01\00\00\00\00\00\00\00\08\00\00\00\01\00\00\00\02") @@ -29,7 +24,7 @@ (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) - (func $~lib/array/Array#__get (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#__get (; 1 ;) (param $0 i32) (result i32) local.get $0 i32.const 60 i32.load @@ -37,7 +32,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -423,7 +418,7 @@ i32.store offset=12 local.get $0 ) - (func $~lib/memory/memory.fill (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 6 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -632,7 +627,7 @@ end end ) - (func $~lib/array/ensureSize (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/ensureSize (; 7 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -652,7 +647,7 @@ if i32.const 424 i32.const 376 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -688,7 +683,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#__set (; 8 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 8 ;) i32.const 0 i32.const 60 i32.load @@ -706,7 +701,7 @@ i32.const 2 i32.store ) - (func $~lib/array/Array#__get (; 9 ;) (type $FUNCSIG$ji) (param $0 i32) (result i64) + (func $~lib/array/Array#__get (; 9 ;) (param $0 i32) (result i64) local.get $0 i32.const 124 i32.load @@ -714,7 +709,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -727,7 +722,7 @@ i32.add i64.load ) - (func $~lib/array/Array#__set (; 10 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 10 ;) i32.const 0 i32.const 124 i32.load @@ -745,7 +740,7 @@ i64.const 4 i64.store ) - (func $~lib/array/Array#__get (; 11 ;) (type $FUNCSIG$fi) (param $0 i32) (result f32) + (func $~lib/array/Array#__get (; 11 ;) (param $0 i32) (result f32) local.get $0 i32.const 180 i32.load @@ -753,7 +748,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -766,7 +761,7 @@ i32.add f32.load ) - (func $~lib/array/Array#__set (; 12 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 12 ;) i32.const 0 i32.const 180 i32.load @@ -784,7 +779,7 @@ f32.const 2.5 f32.store ) - (func $~lib/array/Array#__get (; 13 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) + (func $~lib/array/Array#__get (; 13 ;) (param $0 i32) (result f64) local.get $0 i32.const 244 i32.load @@ -792,7 +787,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -805,7 +800,7 @@ i32.add f64.load ) - (func $~lib/array/Array#__set (; 14 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 14 ;) i32.const 0 i32.const 244 i32.load diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index 4fba861c4f..14c250b2a8 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -60,7 +60,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -1843,7 +1843,7 @@ if i32.const 424 i32.const 376 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -1906,7 +1906,7 @@ if i32.const 320 i32.const 376 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -1950,7 +1950,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -1983,7 +1983,7 @@ if i32.const 320 i32.const 376 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -2027,7 +2027,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -2060,7 +2060,7 @@ if i32.const 320 i32.const 376 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable @@ -2104,7 +2104,7 @@ if i32.const 320 i32.const 376 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -2137,7 +2137,7 @@ if i32.const 320 i32.const 376 - i32.const 109 + i32.const 110 i32.const 21 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string-encoding.optimized.wat b/tests/compiler/std/string-encoding.optimized.wat index bdd7cc7f08..4fed21bd5c 100644 --- a/tests/compiler/std/string-encoding.optimized.wat +++ b/tests/compiler/std/string-encoding.optimized.wat @@ -589,7 +589,7 @@ i32.add i32.load ) - (func $~lib/rt/tlsf/addMemory (; 11 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 11 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -1996,7 +1996,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 36 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 36 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 6eb97041b0..5ea002362f 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -15,8 +15,6 @@ (type $FUNCSIG$iid (func (param i32 f64) (result i32))) (type $FUNCSIG$iijijiji (func (param i32 i64 i32 i64 i32 i64 i32) (result i32))) (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) - (type $FUNCSIG$j (func (result i64))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onincrement" (func $~lib/rt/rtrace/onincrement (param i32))) (import "rtrace" "ondecrement" (func $~lib/rt/rtrace/ondecrement (param i32))) @@ -938,7 +936,7 @@ i32.add i32.load ) - (func $~lib/rt/tlsf/addMemory (; 11 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 11 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -2140,7 +2138,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 31 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/util/string/compareImpl (; 31 ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) local.get $1 i32.const 1 @@ -2292,7 +2290,7 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/string/String.fromCharCode|trampoline (; 35 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.fromCharCode|trampoline (; 35 ;) (param $0 i32) (result i32) (local $1 i32) block $1of1 block $0of1 @@ -2362,7 +2360,7 @@ local.get $1 call $~lib/rt/pure/__retain ) - (func $~lib/string/String#startsWith (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#startsWith (; 37 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2413,7 +2411,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/string/String#endsWith (; 38 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#endsWith (; 38 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) i32.const 536870904 @@ -3021,7 +3019,7 @@ local.get $3 call $~lib/rt/pure/__retain ) - (func $~lib/util/string/strtol (; 48 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) + (func $~lib/util/string/strtol (; 48 ;) (param $0 i32) (result f64) (local $1 i32) (local $2 i32) (local $3 f64) @@ -3238,7 +3236,7 @@ local.get $5 f64.mul ) - (func $~lib/util/string/strtol (; 49 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/util/string/strtol (; 49 ;) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -3456,7 +3454,7 @@ local.get $5 i32.mul ) - (func $~lib/util/string/strtol (; 50 ;) (type $FUNCSIG$j) (result i64) + (func $~lib/util/string/strtol (; 50 ;) (result i64) (local $0 i32) (local $1 i32) (local $2 i32) @@ -3697,7 +3695,7 @@ f64.load f64.mul ) - (func $~lib/math/ipow32 (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/math/ipow32 (; 52 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) i32.const 5 @@ -4735,7 +4733,7 @@ call $~lib/string/String.__lt i32.eqz ) - (func $~lib/string/String.__lte (; 61 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.__lte (; 61 ;) (param $0 i32) (result i32) i32.const 440 local.get $0 call $~lib/string/String.__gt @@ -5562,7 +5560,7 @@ local.get $1 call $~lib/rt/pure/__retain ) - (func $~lib/rt/__allocArray (; 70 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/__allocArray (; 70 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5590,7 +5588,7 @@ i32.store offset=12 local.get $1 ) - (func $~lib/memory/memory.fill (; 71 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 71 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -5799,7 +5797,7 @@ end end ) - (func $~lib/array/ensureSize (; 72 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/ensureSize (; 72 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5817,7 +5815,7 @@ if i32.const 9840 i32.const 11000 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -5854,7 +5852,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array<~lib/string/String>#push (; 73 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/Array<~lib/string/String>#push (; 73 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) local.get $0 @@ -6102,7 +6100,7 @@ if i32.const 240 i32.const 11000 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -6122,7 +6120,7 @@ call $~lib/rt/pure/__release i32.const 11048 i32.const 11000 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index da82ce61c9..a811789f64 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -8746,7 +8746,7 @@ if i32.const 9840 i32.const 11000 - i32.const 14 + i32.const 15 i32.const 47 call $~lib/builtins/abort unreachable @@ -9153,7 +9153,7 @@ if i32.const 240 i32.const 11000 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -9169,7 +9169,7 @@ call $~lib/rt/pure/__release i32.const 11048 i32.const 11000 - i32.const 97 + i32.const 98 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index 4b61f5aa8e..c0cca2db27 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -7,7 +7,6 @@ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\06\00\00\00\01\00\00\00\01\00\00\00\06\00\00\001\002\003") @@ -152,7 +151,7 @@ i32.store offset=12 local.get $3 ) - (func $~lib/memory/memory.fill (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 4 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -361,7 +360,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 1073741808 @@ -415,7 +414,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map<~lib/string/String,usize>#constructor (; 7 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map<~lib/string/String,usize>#constructor (; 7 ;) (result i32) (local $0 i32) i32.const 24 i32.const 3 @@ -442,7 +441,7 @@ call $~lib/map/Map<~lib/string/String,usize>#clear local.get $0 ) - (func $~lib/map/Map#constructor (; 8 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 8 ;) (result i32) (local $0 i32) i32.const 24 i32.const 4 @@ -519,7 +518,7 @@ end local.get $1 ) - (func $~lib/util/string/compareImpl (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 11 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -1179,7 +1178,7 @@ i32.store end ) - (func $~lib/symbol/_Symbol.for (; 21 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/symbol/_Symbol.for (; 21 ;) (result i32) (local $0 i32) global.get $~lib/symbol/stringToId if diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 98f0bcc32a..dc963cce3a 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -37,12 +37,6 @@ (type $FUNCSIG$iid (func (param i32 f64) (result i32))) (type $FUNCSIG$iijijiji (func (param i32 i64 i32 i64 i32 i64 i32) (result i32))) (type $FUNCSIG$iiid (func (param i32 i32 f64) (result i32))) - (type $FUNCSIG$fi (func (param i32) (result f32))) - (type $FUNCSIG$di (func (param i32) (result f64))) - (type $FUNCSIG$ff (func (param f32) (result f32))) - (type $FUNCSIG$dd (func (param f64) (result f64))) - (type $FUNCSIG$iij (func (param i32 i64) (result i32))) - (type $FUNCSIG$iif (func (param i32 f32) (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (import "rtrace" "onfree" (func $~lib/rt/rtrace/onfree (param i32))) (import "rtrace" "onalloc" (func $~lib/rt/rtrace/onalloc (param i32))) @@ -580,7 +574,7 @@ i32.or i32.store offset=4 ) - (func $~lib/rt/tlsf/addMemory (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/rt/tlsf/addMemory (; 7 ;) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -2166,7 +2160,7 @@ i32.store offset=8 local.get $0 ) - (func $~lib/typedarray/Int8Array#constructor (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#constructor (; 32 ;) (param $0 i32) (result i32) i32.const 12 i32.const 3 call $~lib/rt/tlsf/__alloc @@ -2182,7 +2176,7 @@ i32.load i32.sub ) - (func $~lib/typedarray/Uint8Array#constructor (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8Array#constructor (; 34 ;) (param $0 i32) (result i32) i32.const 12 i32.const 4 call $~lib/rt/tlsf/__alloc @@ -2191,7 +2185,7 @@ i32.const 0 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Uint8ClampedArray#constructor (; 35 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8ClampedArray#constructor (; 35 ;) (param $0 i32) (result i32) i32.const 12 i32.const 5 call $~lib/rt/tlsf/__alloc @@ -2200,7 +2194,7 @@ i32.const 0 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Int16Array#constructor (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#constructor (; 36 ;) (param $0 i32) (result i32) i32.const 12 i32.const 6 call $~lib/rt/tlsf/__alloc @@ -2215,7 +2209,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/typedarray/Uint16Array#constructor (; 38 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#constructor (; 38 ;) (param $0 i32) (result i32) i32.const 12 i32.const 7 call $~lib/rt/tlsf/__alloc @@ -2224,7 +2218,7 @@ i32.const 1 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Int32Array#constructor (; 39 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int32Array#constructor (; 39 ;) (param $0 i32) (result i32) i32.const 12 i32.const 8 call $~lib/rt/tlsf/__alloc @@ -2239,7 +2233,7 @@ i32.const 2 i32.shr_u ) - (func $~lib/typedarray/Uint32Array#constructor (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint32Array#constructor (; 41 ;) (param $0 i32) (result i32) i32.const 12 i32.const 9 call $~lib/rt/tlsf/__alloc @@ -2248,7 +2242,7 @@ i32.const 2 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Int64Array#constructor (; 42 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int64Array#constructor (; 42 ;) (param $0 i32) (result i32) i32.const 12 i32.const 10 call $~lib/rt/tlsf/__alloc @@ -2263,7 +2257,7 @@ i32.const 3 i32.shr_u ) - (func $~lib/typedarray/Uint64Array#constructor (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint64Array#constructor (; 44 ;) (param $0 i32) (result i32) i32.const 12 i32.const 11 call $~lib/rt/tlsf/__alloc @@ -2272,7 +2266,7 @@ i32.const 3 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Float32Array#constructor (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float32Array#constructor (; 45 ;) (param $0 i32) (result i32) i32.const 12 i32.const 12 call $~lib/rt/tlsf/__alloc @@ -2281,7 +2275,7 @@ i32.const 2 call $~lib/arraybuffer/ArrayBufferView#constructor ) - (func $~lib/typedarray/Float64Array#constructor (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#constructor (; 46 ;) (param $0 i32) (result i32) i32.const 12 i32.const 13 call $~lib/rt/tlsf/__alloc @@ -3635,7 +3629,7 @@ if i32.const 280 i32.const 512 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -3854,7 +3848,7 @@ if i32.const 280 i32.const 512 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -4097,7 +4091,7 @@ local.get $1 i32.add ) - (func $~lib/typedarray/Int8Array#reduce (; 73 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#reduce (; 73 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4188,7 +4182,7 @@ local.get $2 i32.store8 ) - (func $~lib/typedarray/Uint8Array#reduce (; 76 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8Array#reduce (; 76 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4321,7 +4315,7 @@ local.get $2 i32.store16 ) - (func $~lib/typedarray/Int16Array#reduce (; 80 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#reduce (; 80 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4418,7 +4412,7 @@ local.get $2 i32.store16 ) - (func $~lib/typedarray/Uint16Array#reduce (; 83 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#reduce (; 83 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4491,7 +4485,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int32Array#reduce (; 85 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int32Array#reduce (; 85 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4651,7 +4645,7 @@ local.get $1 i64.add ) - (func $~lib/typedarray/Int64Array#reduce (; 91 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/typedarray/Int64Array#reduce (; 91 ;) (param $0 i32) (param $1 i32) (result i64) (local $2 i32) (local $3 i64) (local $4 i32) @@ -4811,7 +4805,7 @@ local.get $1 f32.add ) - (func $~lib/typedarray/Float32Array#reduce (; 97 ;) (type $FUNCSIG$fi) (param $0 i32) (result f32) + (func $~lib/typedarray/Float32Array#reduce (; 97 ;) (param $0 i32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) @@ -4887,7 +4881,7 @@ local.get $1 f64.add ) - (func $~lib/typedarray/Float64Array#reduce (; 100 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) + (func $~lib/typedarray/Float64Array#reduce (; 100 ;) (param $0 i32) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -4958,7 +4952,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int8Array#reduceRight (; 102 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#reduceRight (; 102 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5030,7 +5024,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8Array#reduceRight (; 104 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8Array#reduceRight (; 104 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5140,7 +5134,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int16Array#reduceRight (; 107 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#reduceRight (; 107 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5214,7 +5208,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint16Array#reduceRight (; 109 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#reduceRight (; 109 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5288,7 +5282,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int32Array#reduceRight (; 111 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int32Array#reduceRight (; 111 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5396,7 +5390,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int64Array#reduceRight (; 114 ;) (type $FUNCSIG$jii) (param $0 i32) (param $1 i32) (result i64) + (func $~lib/typedarray/Int64Array#reduceRight (; 114 ;) (param $0 i32) (param $1 i32) (result i64) (local $2 i32) (local $3 i64) (local $4 i32) @@ -5504,7 +5498,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Float32Array#reduceRight (; 117 ;) (type $FUNCSIG$fi) (param $0 i32) (result f32) + (func $~lib/typedarray/Float32Array#reduceRight (; 117 ;) (param $0 i32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) @@ -5576,7 +5570,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Float64Array#reduceRight (; 119 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) + (func $~lib/typedarray/Float64Array#reduceRight (; 119 ;) (param $0 i32) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -5653,7 +5647,7 @@ local.get $0 i32.mul ) - (func $~lib/typedarray/Int8Array#map (; 122 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#map (; 122 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5775,7 +5769,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8Array#map (; 124 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8Array#map (; 124 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -5916,7 +5910,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8ClampedArray#map (; 127 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8ClampedArray#map (; 127 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6038,7 +6032,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int16Array#map (; 129 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#map (; 129 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6194,7 +6188,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint16Array#map (; 132 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#map (; 132 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6350,7 +6344,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int32Array#map (; 135 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int32Array#map (; 135 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6483,7 +6477,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint32Array#map (; 137 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint32Array#map (; 137 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6644,7 +6638,7 @@ local.get $0 i64.mul ) - (func $~lib/typedarray/Int64Array#map (; 141 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int64Array#map (; 141 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6800,7 +6794,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint64Array#map (; 144 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint64Array#map (; 144 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6961,7 +6955,7 @@ local.get $0 f32.mul ) - (func $~lib/typedarray/Float32Array#map (; 148 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float32Array#map (; 148 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7122,7 +7116,7 @@ local.get $0 f64.mul ) - (func $~lib/typedarray/Float64Array#map (; 152 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#map (; 152 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7422,7 +7416,7 @@ i32.const 16 i32.add ) - (func $~lib/typedarray/Int8Array#filter (; 157 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#filter (; 157 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7596,7 +7590,7 @@ i32.const 2 i32.gt_u ) - (func $~lib/typedarray/Uint8Array#filter (; 160 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8Array#filter (; 160 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7763,7 +7757,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8ClampedArray#filter (; 162 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8ClampedArray#filter (; 162 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -7939,7 +7933,7 @@ i32.const 2 i32.gt_s ) - (func $~lib/typedarray/Int16Array#filter (; 165 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#filter (; 165 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8123,7 +8117,7 @@ i32.const 2 i32.gt_u ) - (func $~lib/typedarray/Uint16Array#filter (; 168 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#filter (; 168 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8305,7 +8299,7 @@ i32.const 2 i32.gt_s ) - (func $~lib/typedarray/Int32Array#filter (; 171 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int32Array#filter (; 171 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8487,7 +8481,7 @@ i32.const 2 i32.gt_u ) - (func $~lib/typedarray/Uint32Array#filter (; 174 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint32Array#filter (; 174 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8669,7 +8663,7 @@ i64.const 2 i64.gt_s ) - (func $~lib/typedarray/Int64Array#filter (; 177 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int64Array#filter (; 177 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8851,7 +8845,7 @@ i64.const 2 i64.gt_u ) - (func $~lib/typedarray/Uint64Array#filter (; 180 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint64Array#filter (; 180 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9033,7 +9027,7 @@ f32.const 2 f32.gt ) - (func $~lib/typedarray/Float32Array#filter (; 183 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float32Array#filter (; 183 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9215,7 +9209,7 @@ f64.const 2 f64.gt ) - (func $~lib/typedarray/Float64Array#filter (; 186 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#filter (; 186 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -11847,7 +11841,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/math/NativeMathf.mod (; 265 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.mod (; 265 ;) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -12089,7 +12083,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/math/NativeMath.mod (; 269 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.mod (; 269 ;) (param $0 f64) (result f64) (local $1 i64) (local $2 i64) (local $3 i64) @@ -12383,7 +12377,7 @@ i32.add global.set $std/typedarray/forEachCallCount ) - (func $~lib/typedarray/Int8Array#forEach (; 274 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/typedarray/Int8Array#forEach (; 274 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -12651,7 +12645,7 @@ i32.add global.set $std/typedarray/forEachCallCount ) - (func $~lib/typedarray/Int16Array#forEach (; 280 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/typedarray/Int16Array#forEach (; 280 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -12741,7 +12735,7 @@ local.get $1 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint16Array#forEach (; 282 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/typedarray/Uint16Array#forEach (; 282 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -13208,7 +13202,7 @@ i32.add global.set $std/typedarray/forEachCallCount ) - (func $~lib/typedarray/Float32Array#forEach (; 293 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/typedarray/Float32Array#forEach (; 293 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -13331,7 +13325,7 @@ i32.add global.set $std/typedarray/forEachCallCount ) - (func $~lib/typedarray/Float64Array#forEach (; 296 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/typedarray/Float64Array#forEach (; 296 ;) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -13674,7 +13668,7 @@ end local.get $3 ) - (func $~lib/typedarray/Uint8Array#subarray (; 301 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8Array#subarray (; 301 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -13886,7 +13880,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8ClampedArray#subarray (; 303 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8ClampedArray#subarray (; 303 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -14155,7 +14149,7 @@ end local.get $3 ) - (func $~lib/typedarray/Int16Array#subarray (; 306 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int16Array#subarray (; 306 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -14434,7 +14428,7 @@ end local.get $3 ) - (func $~lib/typedarray/Uint16Array#subarray (; 309 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint16Array#subarray (; 309 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -14853,7 +14847,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint32Array#subarray (; 313 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint32Array#subarray (; 313 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -15120,7 +15114,7 @@ end local.get $3 ) - (func $~lib/typedarray/Int64Array#subarray (; 316 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int64Array#subarray (; 316 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -15333,7 +15327,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint64Array#subarray (; 318 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint64Array#subarray (; 318 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -15603,7 +15597,7 @@ end local.get $3 ) - (func $~lib/typedarray/Float32Array#subarray (; 321 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Float32Array#subarray (; 321 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 4 @@ -16141,7 +16135,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int8Array#lastIndexOf|trampoline (; 327 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int8Array#lastIndexOf|trampoline (; 327 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -17539,7 +17533,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int16Array#lastIndexOf|trampoline (; 333 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int16Array#lastIndexOf|trampoline (; 333 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -18515,7 +18509,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int32Array#lastIndexOf|trampoline (; 338 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int32Array#lastIndexOf|trampoline (; 338 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -19486,7 +19480,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int64Array#lastIndexOf|trampoline (; 343 ;) (type $FUNCSIG$iij) (param $0 i32) (param $1 i64) (result i32) + (func $~lib/typedarray/Int64Array#lastIndexOf|trampoline (; 343 ;) (param $0 i32) (param $1 i64) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -20458,7 +20452,7 @@ end local.get $2 ) - (func $~lib/typedarray/Float32Array#lastIndexOf|trampoline (; 348 ;) (type $FUNCSIG$iif) (param $0 i32) (param $1 f32) (result i32) + (func $~lib/typedarray/Float32Array#lastIndexOf|trampoline (; 348 ;) (param $0 i32) (param $1 f32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -21014,7 +21008,7 @@ end local.get $2 ) - (func $~lib/typedarray/Float64Array#lastIndexOf|trampoline (; 352 ;) (type $FUNCSIG$iid) (param $0 i32) (param $1 f64) (result i32) + (func $~lib/typedarray/Float64Array#lastIndexOf|trampoline (; 352 ;) (param $0 i32) (param $1 f64) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -21452,7 +21446,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Float64Array#includes (; 354 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#includes (; 354 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 f64) @@ -21507,7 +21501,7 @@ i32.const 0 end ) - (func $~lib/typedarray/Float32Array#includes (; 355 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float32Array#includes (; 355 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -21742,7 +21736,7 @@ end local.get $2 ) - (func $~lib/string/String#substring (; 361 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 361 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -21816,7 +21810,7 @@ local.get $2 call $~lib/rt/pure/__retain ) - (func $~lib/util/string/joinIntegerArray (; 362 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 362 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -21923,14 +21917,14 @@ end local.get $2 ) - (func $~lib/typedarray/Int8Array#join (; 363 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#join (; 363 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 i32.load offset=8 call $~lib/util/string/joinIntegerArray ) - (func $~lib/util/string/compareImpl (; 364 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 364 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -22159,7 +22153,7 @@ call $~lib/util/number/utoa_simple local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 369 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 369 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -22266,7 +22260,7 @@ end local.get $2 ) - (func $~lib/typedarray/Uint8Array#join (; 370 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint8Array#join (; 370 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -22452,7 +22446,7 @@ end local.get $2 ) - (func $~lib/util/string/joinIntegerArray (; 374 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 374 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -22563,7 +22557,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int16Array#join (; 375 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int16Array#join (; 375 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -22662,7 +22656,7 @@ call $~lib/util/number/utoa_simple local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 378 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 378 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -22773,7 +22767,7 @@ end local.get $2 ) - (func $~lib/typedarray/Uint16Array#join (; 379 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint16Array#join (; 379 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -22884,7 +22878,7 @@ end local.get $2 ) - (func $~lib/util/string/joinIntegerArray (; 382 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 382 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -22995,7 +22989,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int32Array#join (; 383 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int32Array#join (; 383 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -23088,7 +23082,7 @@ call $~lib/util/number/utoa_simple local.get $0 ) - (func $~lib/util/string/joinIntegerArray (; 386 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 386 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -23199,7 +23193,7 @@ end local.get $2 ) - (func $~lib/typedarray/Uint32Array#join (; 387 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint32Array#join (; 387 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -23476,7 +23470,7 @@ end local.get $3 ) - (func $~lib/util/string/joinIntegerArray (; 393 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 393 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -23587,7 +23581,7 @@ end local.get $2 ) - (func $~lib/typedarray/Int64Array#join (; 394 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int64Array#join (; 394 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -23739,7 +23733,7 @@ end local.get $1 ) - (func $~lib/util/string/joinIntegerArray (; 398 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinIntegerArray (; 398 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -23850,7 +23844,7 @@ end local.get $2 ) - (func $~lib/typedarray/Uint64Array#join (; 399 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Uint64Array#join (; 399 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -24976,7 +24970,7 @@ local.get $2 call $~lib/util/number/dtoa_core ) - (func $~lib/util/string/joinFloatArray (; 406 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinFloatArray (; 406 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -25090,7 +25084,7 @@ end local.get $2 ) - (func $~lib/typedarray/Float32Array#join (; 407 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float32Array#join (; 407 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -25159,7 +25153,7 @@ local.get $0 call $~lib/rt/pure/__release ) - (func $~lib/util/string/joinFloatArray (; 409 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/util/string/joinFloatArray (; 409 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -25270,7 +25264,7 @@ end local.get $2 ) - (func $~lib/typedarray/Float64Array#join (; 410 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#join (; 410 ;) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -25413,7 +25407,7 @@ local.get $3 call $~lib/rt/pure/__retain ) - (func $~lib/typedarray/Int8Array.wrap (; 414 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int8Array.wrap (; 414 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -25585,7 +25579,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8Array.wrap (; 416 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8Array.wrap (; 416 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -25755,7 +25749,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint8ClampedArray.wrap (; 418 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint8ClampedArray.wrap (; 418 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -25925,7 +25919,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int16Array.wrap (; 420 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int16Array.wrap (; 420 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26100,7 +26094,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint16Array.wrap (; 422 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint16Array.wrap (; 422 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26273,7 +26267,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int32Array.wrap (; 424 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int32Array.wrap (; 424 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26444,7 +26438,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint32Array.wrap (; 426 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint32Array.wrap (; 426 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26615,7 +26609,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Int64Array.wrap (; 428 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int64Array.wrap (; 428 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26787,7 +26781,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Uint64Array.wrap (; 430 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Uint64Array.wrap (; 430 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -26959,7 +26953,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Float32Array.wrap (; 432 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Float32Array.wrap (; 432 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 @@ -27129,7 +27123,7 @@ local.get $2 call $~lib/rt/pure/__release ) - (func $~lib/typedarray/Float64Array.wrap (; 434 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Float64Array.wrap (; 434 ;) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) i32.const 0 local.get $0 diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index 319bdeda1a..fc1d2f9229 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -5559,7 +5559,7 @@ if i32.const 280 i32.const 512 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable @@ -5867,7 +5867,7 @@ if i32.const 280 i32.const 512 - i32.const 93 + i32.const 94 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/typeof.optimized.wat b/tests/compiler/typeof.optimized.wat index b0ff5d9436..dae6a6d86b 100644 --- a/tests/compiler/typeof.optimized.wat +++ b/tests/compiler/typeof.optimized.wat @@ -4,8 +4,6 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00n\00u\00m\00b\00e\00r") @@ -30,7 +28,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 2 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 2 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -187,7 +185,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 6 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/rt/stub/__alloc (; 6 ;) (result i32) (local $0 i32) (local $1 i32) global.get $~lib/rt/stub/offset From 9f4c24baef82876bb659d5016c4f82c526562e8d Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 6 Dec 2019 12:12:05 -0500 Subject: [PATCH 25/47] Add Map Iterator --- std/assembly/array.ts | 1 - std/assembly/index.d.ts | 27 +- std/assembly/iterator.ts | 7 +- std/assembly/map.ts | 114 +- tests/compiler/assert-nonnull.optimized.wat | 6 +- tests/compiler/assert-nonnull.untouched.wat | 6 +- tests/compiler/iterator.optimized.wat | 974 ---------- tests/compiler/resolve-access.optimized.wat | 2 +- tests/compiler/resolve-access.untouched.wat | 2 +- .../retain-release-sanity.optimized.wat | 4 +- .../retain-release-sanity.untouched.wat | 4 +- tests/compiler/std/array-access.optimized.wat | 6 +- tests/compiler/std/array-access.untouched.wat | 14 +- .../compiler/std/array-literal.optimized.wat | 4 +- .../compiler/std/array-literal.untouched.wat | 4 +- tests/compiler/std/array.optimized.wat | 26 +- tests/compiler/std/array.untouched.wat | 46 +- tests/compiler/std/iterator.json | 5 + tests/compiler/std/iterator.optimized.wat | 1711 +++++++++++++++++ tests/compiler/{ => std}/iterator.ts | 24 +- .../compiler/{ => std}/iterator.untouched.wat | 1227 +++++++++++- tests/compiler/std/map.optimized.wat | 16 +- tests/compiler/std/map.untouched.wat | 20 +- tests/compiler/std/static-array.optimized.wat | 10 +- tests/compiler/std/static-array.untouched.wat | 18 +- tests/compiler/std/string.optimized.wat | 6 +- tests/compiler/std/string.untouched.wat | 6 +- tests/compiler/std/symbol.optimized.wat | 4 +- tests/compiler/std/symbol.untouched.wat | 4 +- tests/compiler/std/typedarray.optimized.wat | 4 +- tests/compiler/std/typedarray.untouched.wat | 4 +- 31 files changed, 3101 insertions(+), 1205 deletions(-) delete mode 100644 tests/compiler/iterator.optimized.wat create mode 100644 tests/compiler/std/iterator.json create mode 100644 tests/compiler/std/iterator.optimized.wat rename tests/compiler/{ => std}/iterator.ts (69%) rename tests/compiler/{ => std}/iterator.untouched.wat (58%) diff --git a/std/assembly/array.ts b/std/assembly/array.ts index 2315e77822..c5e07a7d1a 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -6,7 +6,6 @@ import { ArrayBufferView } from "./arraybuffer"; import { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string"; import { idof, isArray as builtin_isArray } from "./builtins"; import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from "./util/error"; -import { Iterator } from "iterator"; /** Ensures that the given array has _at least_ the specified backing size. */ function ensureSize(array: usize, minSize: usize, alignLog2: u32): void { diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index e34c7f4fb8..6b03d4cf97 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1525,15 +1525,38 @@ interface Function {} interface IArguments {} interface RegExp {} +interface IteratorResult { + done: bool; + value: TReturn; +} + +interface Iterator { + next(): IteratorResult; +} + +interface Iterable { + iterator: Iterator; +} + +interface IterableIterator extends Iterator { + iterator: IterableIterator; +} + +declare class MapEntry { + key: K; + value: V; +} + declare class Map { + entries(): Iterator> readonly size: i32; has(key: K): bool; set(key: K, value: V): void; get(key: K): V; delete(key: K): bool; clear(): void; - keys(): K[]; // preliminary - values(): V[]; // preliminary + keys(): Iterator; + values(): Iterator; toString(): string; } diff --git a/std/assembly/iterator.ts b/std/assembly/iterator.ts index d81cd0138c..4eef898992 100644 --- a/std/assembly/iterator.ts +++ b/std/assembly/iterator.ts @@ -2,7 +2,7 @@ export interface Iterable { readonly iterator: Iterator; } -export interface IteratorResut { +export interface IteratorResult { readonly value: T; readonly done: bool; } @@ -33,11 +33,8 @@ export interface Iterator { // ? // } - readonly done: bool; - - readonly value: T; - next(): Iterator; + next(): IteratorResult; } diff --git a/std/assembly/map.ts b/std/assembly/map.ts index 29701da392..15815e6c5b 100644 --- a/std/assembly/map.ts +++ b/std/assembly/map.ts @@ -2,6 +2,7 @@ import { HASH } from "./util/hash"; import { E_KEYNOTFOUND } from "util/error"; +import { Iterator, IteratorResult } from "iterator"; // A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht @@ -61,6 +62,67 @@ function ENTRY_SIZE(): usize { return size; } +class EntriesIter implements Iterator> { + private index: usize = 0; + constructor(private _map: Map, protected start: usize, protected size: usize){} + + get done(): bool { + return this.index >= this.size; + } + + protected get entry(): MapEntry { + return changetype>(this.start + this.index * ENTRY_SIZE()); + } + + get value(): MapEntry { + return this.entry; + } + + next(): IteratorResult> { + while (!this.done) { + if (!(this.entry.taggedNext & EMPTY)) { + break + } + this.index++ + } + return this; + } +} + +class KeyIterator { + constructor(private entriesIter: EntriesIter){} + + get done(): bool { + return this.entriesIter.done; + } + + get value(): K { + return this.entriesIter.value.key; + } + + next(): IteratorResult { + this.entriesIter.next(); + return this; + } +} + +class ValueIterator { + constructor(private entriesIter: EntriesIter){} + + get done(): bool { + return this.entriesIter.done; + } + + get value(): V { + return this.entriesIter.value.value; + } + + next(): IteratorResult { + this.entriesIter.next(); + return this; + } +} + export class Map { // buckets holding references to the respective first entry within @@ -68,7 +130,7 @@ export class Map { private bucketsMask: u32; // entries in insertion order - private entries: ArrayBuffer; // MapEntry[entriesCapacity] + private _entries: ArrayBuffer; // MapEntry[entriesCapacity] private entriesCapacity: i32; private entriesOffset: i32; private entriesCount: i32; @@ -79,12 +141,18 @@ export class Map { this.clear(); } + public entries(): EntriesIter { + var start = changetype(this._entries); + var size = this.entriesOffset; + return new EntriesIter(this, start, size); + } + clear(): void { const bucketsSize = INITIAL_CAPACITY * BUCKET_SIZE; this.buckets = new ArrayBuffer(bucketsSize); this.bucketsMask = INITIAL_CAPACITY - 1; const entriesSize = INITIAL_CAPACITY * ENTRY_SIZE(); - this.entries = new ArrayBuffer(entriesSize); + this._entries = new ArrayBuffer(entriesSize); this.entriesCapacity = INITIAL_CAPACITY; this.entriesOffset = 0; this.entriesCount = 0; @@ -136,7 +204,7 @@ export class Map { ); } // append new entry - let entries = this.entries; + let entries = this._entries; entry = changetype>(changetype(entries) + this.entriesOffset++ * ENTRY_SIZE()); // link with the map entry.key = isManaged() @@ -176,7 +244,7 @@ export class Map { var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE()); // copy old entries to new entries - var oldPtr = changetype(this.entries); + var oldPtr = changetype(this._entries); var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE(); var newPtr = changetype(newEntries); while (oldPtr != oldEnd) { @@ -196,43 +264,17 @@ export class Map { this.buckets = newBuckets; this.bucketsMask = newBucketsMask; - this.entries = newEntries; + this._entries = newEntries; this.entriesCapacity = newEntriesCapacity; this.entriesOffset = this.entriesCount; } - keys(): K[] { - // FIXME: this is preliminary, needs iterators/closures - var start = changetype(this.entries); - var size = this.entriesOffset; - var keys = new Array(size); - var length = 0; - for (let i = 0; i < size; ++i) { - let entry = changetype>(start + i * ENTRY_SIZE()); - if (!(entry.taggedNext & EMPTY)) { - keys.push(entry.key); - ++length; - } - } - keys.length = length; - return keys; + keys(): Iterator { + return new KeyIterator(this.entries()); } - values(): V[] { - // FIXME: this is preliminary, needs iterators/closures - var start = changetype(this.entries); - var size = this.entriesOffset; - var values = new Array(size); - var length = 0; - for (let i = 0; i < size; ++i) { - let entry = changetype>(start + i * ENTRY_SIZE()); - if (!(entry.taggedNext & EMPTY)) { - values.push(entry.value); - ++length; - } - } - values.length = length; - return values; + values(): Iterator { + return new ValueIterator(this.entries()); } toString(): string { @@ -243,7 +285,7 @@ export class Map { @unsafe private __visit_impl(cookie: u32): void { __visit(changetype(this.buckets), cookie); - var entries = changetype(this.entries); + var entries = changetype(this._entries); if (isManaged() || isManaged()) { let cur = entries; let end = cur + this.entriesOffset * ENTRY_SIZE(); diff --git a/tests/compiler/assert-nonnull.optimized.wat b/tests/compiler/assert-nonnull.optimized.wat index e09e21d591..4a1462cb71 100644 --- a/tests/compiler/assert-nonnull.optimized.wat +++ b/tests/compiler/assert-nonnull.optimized.wat @@ -64,7 +64,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -76,7 +76,7 @@ if i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -100,7 +100,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/assert-nonnull.untouched.wat b/tests/compiler/assert-nonnull.untouched.wat index c203a67f64..bfc7f19423 100644 --- a/tests/compiler/assert-nonnull.untouched.wat +++ b/tests/compiler/assert-nonnull.untouched.wat @@ -107,7 +107,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -123,7 +123,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -168,7 +168,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/iterator.optimized.wat b/tests/compiler/iterator.optimized.wat deleted file mode 100644 index 0ba279575a..0000000000 --- a/tests/compiler/iterator.optimized.wat +++ /dev/null @@ -1,974 +0,0 @@ -(module - (type $FUNCSIG$ii (func (param i32) (result i32))) - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$v (func)) - (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (memory $0 1) - (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05") - (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03") - (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") - (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 176) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s") - (data (i32.const 216) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h") - (data (i32.const 264) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") - (data (i32.const 320) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s") - (global $iterator/iterableArr (mut i32) (i32.const 0)) - (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) - (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $iterator/iter (mut i32) (i32.const 0)) - (global $iterator/res (mut i32) (i32.const 0)) - (global $iterator/i (mut i32) (i32.const 0)) - (global $iterator/arr2 (mut i32) (i32.const 0)) - (export "memory" (memory $0)) - (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) - (local $1 i32) - (local $2 i32) - local.get $0 - memory.size - local.tee $2 - i32.const 16 - i32.shl - local.tee $1 - i32.gt_u - if - local.get $2 - local.get $0 - local.get $1 - i32.sub - i32.const 65535 - i32.add - i32.const -65536 - i32.and - i32.const 16 - i32.shr_u - local.tee $1 - local.get $2 - local.get $1 - i32.gt_s - select - memory.grow - i32.const 0 - i32.lt_s - if - local.get $1 - memory.grow - i32.const 0 - i32.lt_s - if - unreachable - end - end - end - local.get $0 - global.set $~lib/rt/stub/offset - ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - local.get $0 - i32.const 1073741808 - i32.gt_u - if - unreachable - end - global.get $~lib/rt/stub/offset - i32.const 16 - i32.add - local.tee $3 - local.get $0 - i32.const 15 - i32.add - i32.const -16 - i32.and - local.tee $2 - i32.const 16 - local.get $2 - i32.const 16 - i32.gt_u - select - local.tee $4 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $3 - i32.const 16 - i32.sub - local.tee $2 - local.get $4 - i32.store - local.get $2 - i32.const -1 - i32.store offset=4 - local.get $2 - local.get $1 - i32.store offset=8 - local.get $2 - local.get $0 - i32.store offset=12 - local.get $3 - ) - (func $iterator/IterableArray#get:iterator (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - i32.const 8 - i32.const 6 - call $~lib/rt/stub/__alloc - local.tee $1 - i32.const -1 - i32.store - local.get $1 - local.get $0 - i32.store offset=4 - local.get $1 - ) - (func $~lib/array/Array#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $1 - local.get $0 - i32.load offset=12 - i32.ge_u - if - i32.const 88 - i32.const 144 - i32.const 94 - i32.const 41 - call $~lib/builtins/abort - unreachable - end - local.get $0 - i32.load offset=4 - local.get $1 - i32.const 2 - i32.shl - i32.add - i32.load - ) - (func $~lib/memory/memory.fill (; 5 ;) (param $0 i32) (param $1 i32) - (local $2 i32) - block $~lib/util/memory/memset|inlined.0 - local.get $1 - i32.eqz - br_if $~lib/util/memory/memset|inlined.0 - local.get $0 - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - i32.const 1 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 2 - i32.le_u - br_if $~lib/util/memory/memset|inlined.0 - local.get $0 - i32.const 1 - i32.add - i32.const 0 - i32.store8 - local.get $0 - i32.const 2 - i32.add - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 2 - i32.sub - i32.const 0 - i32.store8 - local.get $2 - i32.const 3 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 6 - i32.le_u - br_if $~lib/util/memory/memset|inlined.0 - local.get $0 - i32.const 3 - i32.add - i32.const 0 - i32.store8 - local.get $0 - local.get $1 - i32.add - i32.const 4 - i32.sub - i32.const 0 - i32.store8 - local.get $1 - i32.const 8 - i32.le_u - br_if $~lib/util/memory/memset|inlined.0 - local.get $1 - i32.const 0 - local.get $0 - i32.sub - i32.const 3 - i32.and - local.tee $1 - i32.sub - local.get $0 - local.get $1 - i32.add - local.tee $0 - i32.const 0 - i32.store - i32.const -4 - i32.and - local.tee $1 - local.get $0 - i32.add - i32.const 4 - i32.sub - i32.const 0 - i32.store - local.get $1 - i32.const 8 - i32.le_u - br_if $~lib/util/memory/memset|inlined.0 - local.get $0 - i32.const 4 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 8 - i32.add - i32.const 0 - i32.store - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 12 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 8 - i32.sub - i32.const 0 - i32.store - local.get $1 - i32.const 24 - i32.le_u - br_if $~lib/util/memory/memset|inlined.0 - local.get $0 - i32.const 12 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 16 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 20 - i32.add - i32.const 0 - i32.store - local.get $0 - i32.const 24 - i32.add - i32.const 0 - i32.store - local.get $0 - local.get $1 - i32.add - local.tee $2 - i32.const 28 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 24 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 20 - i32.sub - i32.const 0 - i32.store - local.get $2 - i32.const 16 - i32.sub - i32.const 0 - i32.store - local.get $0 - i32.const 4 - i32.and - i32.const 24 - i32.add - local.tee $2 - local.get $0 - i32.add - local.set $0 - local.get $1 - local.get $2 - i32.sub - local.set $1 - loop $continue|0 - local.get $1 - i32.const 32 - i32.ge_u - if - local.get $0 - i64.const 0 - i64.store - local.get $0 - i32.const 8 - i32.add - i64.const 0 - i64.store - local.get $0 - i32.const 16 - i32.add - i64.const 0 - i64.store - local.get $0 - i32.const 24 - i32.add - i64.const 0 - i64.store - local.get $1 - i32.const 32 - i32.sub - local.set $1 - local.get $0 - i32.const 32 - i32.add - local.set $0 - br $continue|0 - end - end - end - ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 6 ;) (param $0 i32) (result i32) - (local $1 i32) - i32.const 0 - i32.const 0 - call $~lib/rt/stub/__alloc - local.tee $1 - i32.const 0 - call $~lib/memory/memory.fill - local.get $0 - i32.eqz - if - i32.const 12 - i32.const 2 - call $~lib/rt/stub/__alloc - local.set $0 - end - local.get $0 - i32.const 0 - i32.store - local.get $0 - i32.const 0 - i32.store offset=4 - local.get $0 - i32.const 0 - i32.store offset=8 - local.get $0 - i32.load - drop - local.get $0 - local.get $1 - i32.store - local.get $0 - local.get $1 - i32.store offset=4 - local.get $0 - i32.const 0 - i32.store offset=8 - local.get $0 - ) - (func $~lib/memory/memory.copy (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - (local $4 i32) - block $~lib/util/memory/memmove|inlined.0 - local.get $2 - local.set $3 - local.get $0 - local.get $1 - i32.eq - br_if $~lib/util/memory/memmove|inlined.0 - local.get $0 - local.get $1 - i32.lt_u - if - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - loop $continue|0 - local.get $0 - i32.const 7 - i32.and - if - local.get $3 - i32.eqz - br_if $~lib/util/memory/memmove|inlined.0 - local.get $3 - i32.const 1 - i32.sub - local.set $3 - local.get $0 - local.tee $2 - i32.const 1 - i32.add - local.set $0 - local.get $1 - local.tee $4 - i32.const 1 - i32.add - local.set $1 - local.get $2 - local.get $4 - i32.load8_u - i32.store8 - br $continue|0 - end - end - loop $continue|1 - local.get $3 - i32.const 8 - i32.lt_u - i32.eqz - if - local.get $0 - local.get $1 - i64.load - i64.store - local.get $3 - i32.const 8 - i32.sub - local.set $3 - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - br $continue|1 - end - end - end - loop $continue|2 - local.get $3 - if - local.get $0 - local.tee $2 - i32.const 1 - i32.add - local.set $0 - local.get $1 - local.tee $4 - i32.const 1 - i32.add - local.set $1 - local.get $2 - local.get $4 - i32.load8_u - i32.store8 - local.get $3 - i32.const 1 - i32.sub - local.set $3 - br $continue|2 - end - end - else - local.get $1 - i32.const 7 - i32.and - local.get $0 - i32.const 7 - i32.and - i32.eq - if - loop $continue|3 - local.get $0 - local.get $3 - i32.add - i32.const 7 - i32.and - if - local.get $3 - i32.eqz - br_if $~lib/util/memory/memmove|inlined.0 - local.get $0 - local.get $3 - i32.const 1 - i32.sub - local.tee $3 - i32.add - local.get $1 - local.get $3 - i32.add - i32.load8_u - i32.store8 - br $continue|3 - end - end - loop $continue|4 - local.get $3 - i32.const 8 - i32.lt_u - i32.eqz - if - local.get $0 - local.get $3 - i32.const 8 - i32.sub - local.tee $3 - i32.add - local.get $1 - local.get $3 - i32.add - i64.load - i64.store - br $continue|4 - end - end - end - loop $continue|5 - local.get $3 - if - local.get $0 - local.get $3 - i32.const 1 - i32.sub - local.tee $3 - i32.add - local.get $1 - local.get $3 - i32.add - i32.load8_u - i32.store8 - br $continue|5 - end - end - end - end - ) - (func $~lib/rt/stub/__realloc (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - local.get $0 - i32.const 15 - i32.and - i32.eqz - i32.const 0 - local.get $0 - select - i32.eqz - if - i32.const 0 - i32.const 336 - i32.const 43 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $0 - i32.const 16 - i32.sub - local.tee $3 - i32.load - local.set $4 - local.get $3 - i32.load offset=4 - i32.const -1 - i32.ne - if - i32.const 0 - i32.const 336 - i32.const 46 - i32.const 13 - call $~lib/builtins/abort - unreachable - end - global.get $~lib/rt/stub/offset - local.get $0 - local.get $4 - i32.add - i32.eq - local.set $5 - local.get $1 - i32.const 15 - i32.add - i32.const -16 - i32.and - local.set $2 - local.get $1 - local.get $4 - i32.gt_u - if - local.get $5 - if - local.get $1 - i32.const 1073741808 - i32.gt_u - if - unreachable - end - local.get $0 - local.get $2 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $3 - local.get $2 - i32.store - else - local.get $2 - local.get $4 - i32.const 1 - i32.shl - local.tee $4 - local.get $2 - local.get $4 - i32.gt_u - select - local.get $3 - i32.load offset=8 - call $~lib/rt/stub/__alloc - local.tee $2 - local.get $0 - local.get $3 - i32.load offset=12 - call $~lib/memory/memory.copy - local.get $2 - local.tee $0 - i32.const 16 - i32.sub - local.set $3 - end - else - local.get $5 - if - local.get $0 - local.get $2 - i32.add - global.set $~lib/rt/stub/offset - local.get $3 - local.get $2 - i32.store - end - end - local.get $3 - local.get $1 - i32.store offset=12 - local.get $0 - ) - (func $~lib/array/ensureSize (; 9 ;) (param $0 i32) (param $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - local.get $1 - local.get $0 - i32.load offset=8 - local.tee $2 - i32.const 2 - i32.shr_u - i32.gt_u - if - local.get $1 - i32.const 268435452 - i32.gt_u - if - i32.const 232 - i32.const 144 - i32.const 15 - i32.const 47 - call $~lib/builtins/abort - unreachable - end - local.get $0 - i32.load - local.tee $4 - local.get $1 - i32.const 2 - i32.shl - local.tee $3 - call $~lib/rt/stub/__realloc - local.tee $1 - local.get $2 - i32.add - local.get $3 - local.get $2 - i32.sub - call $~lib/memory/memory.fill - local.get $1 - local.get $4 - i32.ne - if - local.get $0 - local.get $1 - i32.store - local.get $0 - local.get $1 - i32.store offset=4 - end - local.get $0 - local.get $3 - i32.store offset=8 - end - ) - (func $~lib/array/Array#push (; 10 ;) (param $0 i32) (param $1 i32) - (local $2 i32) - (local $3 i32) - local.get $0 - local.get $0 - i32.load offset=12 - local.tee $2 - i32.const 1 - i32.add - local.tee $3 - call $~lib/array/ensureSize - local.get $0 - i32.load offset=4 - local.get $2 - i32.const 2 - i32.shl - i32.add - local.get $1 - i32.store - local.get $0 - local.get $3 - i32.store offset=12 - ) - (func $~lib/array/Array.from (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - i32.const 16 - i32.const 3 - call $~lib/rt/stub/__alloc - call $~lib/arraybuffer/ArrayBufferView#constructor - local.tee $1 - i32.const 0 - i32.store offset=12 - local.get $1 - i32.const 0 - i32.store offset=12 - local.get $0 - local.tee $3 - call $~lib/iterator/Iterator#next - local.set $0 - loop $continue|0 - local.get $0 - call $~lib/iterator/Iterator#get:done - i32.eqz - if - local.get $1 - local.get $0 - call $~lib/iterator/Iterator#get:value - call $~lib/array/Array#push - local.get $3 - call $~lib/iterator/Iterator#next - local.set $0 - local.get $2 - i32.const 1 - i32.add - local.set $2 - br $continue|0 - end - end - local.get $1 - i32.load offset=12 - drop - local.get $1 - local.get $2 - call $~lib/array/ensureSize - local.get $1 - local.get $2 - i32.store offset=12 - local.get $1 - ) - (func $start:iterator (; 12 ;) (type $FUNCSIG$v) - (local $0 i32) - (local $1 i32) - i32.const 56 - global.set $iterator/iterableArr - i32.const 368 - global.set $~lib/rt/stub/startOffset - i32.const 368 - global.set $~lib/rt/stub/offset - i32.const 56 - call $iterator/IterableArray#get:iterator - global.set $iterator/iter - global.get $iterator/iter - call $~lib/iterator/Iterator#next - global.set $iterator/res - loop $continue|0 - global.get $iterator/res - call $~lib/iterator/Iterator#get:done - i32.eqz - if - global.get $iterator/res - call $~lib/iterator/Iterator#get:value - local.set $0 - global.get $iterator/i - local.tee $1 - i32.const 1 - i32.add - global.set $iterator/i - i32.const 56 - local.get $1 - call $~lib/array/Array#__get - local.get $0 - i32.ne - if - i32.const 0 - i32.const 192 - i32.const 43 - i32.const 2 - call $~lib/builtins/abort - unreachable - else - global.get $iterator/iter - call $~lib/iterator/Iterator#next - global.set $iterator/res - br $continue|0 - end - unreachable - end - end - global.get $iterator/iterableArr - call $iterator/IterableArray#get:iterator - call $~lib/array/Array.from - global.set $iterator/arr2 - i32.const 68 - i32.load - i32.const 3 - i32.ne - if - i32.const 0 - i32.const 192 - i32.const 51 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - global.get $iterator/arr2 - i32.const 0 - call $~lib/array/Array#__get - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 192 - i32.const 52 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - global.get $iterator/arr2 - i32.const 1 - call $~lib/array/Array#__get - i32.const 3 - i32.ne - if - i32.const 0 - i32.const 192 - i32.const 53 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - ) - (func $start (; 13 ;) (type $FUNCSIG$v) - call $start:iterator - ) - (func $iterator/ArrayIterator#get:done (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.load - local.get $0 - i32.load offset=4 - i32.load offset=12 - i32.ge_s - ) - (func $~lib/iterator/Iterator#get:done (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $iterator/ArrayIterator#get:done - else - unreachable - end - ) - (func $~lib/iterator/Iterator#get:value (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 6 - i32.eq - if - block $__inlined_func$iterator/ArrayIterator#get:value - local.get $0 - call $iterator/ArrayIterator#get:done - i32.eqz - if - local.get $0 - i32.load offset=4 - local.get $0 - i32.load - call $~lib/array/Array#__get - local.set $0 - br $__inlined_func$iterator/ArrayIterator#get:value - end - unreachable - end - else - unreachable - end - local.get $0 - ) - (func $~lib/iterator/Iterator#next (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 6 - i32.eq - if - local.get $0 - local.get $0 - i32.load - i32.const 1 - i32.add - i32.store - else - unreachable - end - local.get $0 - ) - (func $null (; 18 ;) (type $FUNCSIG$v) - nop - ) -) diff --git a/tests/compiler/resolve-access.optimized.wat b/tests/compiler/resolve-access.optimized.wat index d533451157..59d5d9920c 100644 --- a/tests/compiler/resolve-access.optimized.wat +++ b/tests/compiler/resolve-access.optimized.wat @@ -312,7 +312,7 @@ if i32.const 48 i32.const 104 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/resolve-access.untouched.wat b/tests/compiler/resolve-access.untouched.wat index c232341e54..24f25c3c86 100644 --- a/tests/compiler/resolve-access.untouched.wat +++ b/tests/compiler/resolve-access.untouched.wat @@ -1449,7 +1449,7 @@ if i32.const 48 i32.const 104 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/retain-release-sanity.optimized.wat b/tests/compiler/retain-release-sanity.optimized.wat index 57204658e0..539205f389 100644 --- a/tests/compiler/retain-release-sanity.optimized.wat +++ b/tests/compiler/retain-release-sanity.optimized.wat @@ -2230,7 +2230,7 @@ if i32.const 24 i32.const 376 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -2300,7 +2300,7 @@ if i32.const 424 i32.const 376 - i32.const 289 + i32.const 288 i32.const 20 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/retain-release-sanity.untouched.wat b/tests/compiler/retain-release-sanity.untouched.wat index 1418c4af1b..88797871e9 100644 --- a/tests/compiler/retain-release-sanity.untouched.wat +++ b/tests/compiler/retain-release-sanity.untouched.wat @@ -3830,7 +3830,7 @@ if i32.const 24 i32.const 376 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -3910,7 +3910,7 @@ if i32.const 424 i32.const 376 - i32.const 289 + i32.const 288 i32.const 20 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index d0d27cfb93..5c84d01fdb 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -24,7 +24,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -41,7 +41,7 @@ if i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -56,7 +56,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-access.untouched.wat b/tests/compiler/std/array-access.untouched.wat index 8f0341dc89..47c6d34b83 100644 --- a/tests/compiler/std/array-access.untouched.wat +++ b/tests/compiler/std/array-access.untouched.wat @@ -47,7 +47,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -63,7 +63,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -88,7 +88,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -137,7 +137,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -153,7 +153,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -420,7 +420,7 @@ if i32.const 24 i32.const 80 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -436,7 +436,7 @@ call $~lib/rt/stub/__release i32.const 128 i32.const 80 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index 97afe0eceb..3e7fe3e757 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -46,7 +46,7 @@ if i32.const 136 i32.const 192 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -65,7 +65,7 @@ if i32.const 136 i32.const 192 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array-literal.untouched.wat b/tests/compiler/std/array-literal.untouched.wat index a6dae3d912..dc7ac7f4f2 100644 --- a/tests/compiler/std/array-literal.untouched.wat +++ b/tests/compiler/std/array-literal.untouched.wat @@ -71,7 +71,7 @@ if i32.const 136 i32.const 192 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -104,7 +104,7 @@ if i32.const 136 i32.const 192 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 58f270fb6a..a9d57c836c 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -2421,7 +2421,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -2563,7 +2563,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -2811,7 +2811,7 @@ if i32.const 24 i32.const 488 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -2883,7 +2883,7 @@ if i32.const 872 i32.const 488 - i32.const 289 + i32.const 288 i32.const 20 call $~lib/builtins/abort unreachable @@ -2961,7 +2961,7 @@ if i32.const 24 i32.const 488 - i32.const 219 + i32.const 218 i32.const 59 call $~lib/builtins/abort unreachable @@ -3139,7 +3139,7 @@ if i32.const 872 i32.const 488 - i32.const 350 + i32.const 349 i32.const 20 call $~lib/builtins/abort unreachable @@ -3699,7 +3699,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -3714,7 +3714,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -3807,7 +3807,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -3829,7 +3829,7 @@ if i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -4320,7 +4320,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -5677,7 +5677,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -6383,7 +6383,7 @@ if i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 62e48c5d6e..93b37ee043 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -4107,7 +4107,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -4311,7 +4311,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -4638,7 +4638,7 @@ if i32.const 24 i32.const 488 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -4724,7 +4724,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -4747,7 +4747,7 @@ if i32.const 872 i32.const 488 - i32.const 289 + i32.const 288 i32.const 20 call $~lib/builtins/abort unreachable @@ -4855,7 +4855,7 @@ call $~lib/rt/pure/__release i32.const 24 i32.const 488 - i32.const 219 + i32.const 218 i32.const 59 call $~lib/builtins/abort unreachable @@ -5155,7 +5155,7 @@ if i32.const 872 i32.const 488 - i32.const 350 + i32.const 349 i32.const 20 call $~lib/builtins/abort unreachable @@ -5867,7 +5867,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -5883,7 +5883,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -6021,7 +6021,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -6054,7 +6054,7 @@ if i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -6779,7 +6779,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -8710,7 +8710,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -10096,7 +10096,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -10377,7 +10377,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -10393,7 +10393,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -10576,7 +10576,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -10850,7 +10850,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -10866,7 +10866,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable @@ -11155,7 +11155,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -11958,7 +11958,7 @@ call $~lib/rt/pure/__release i32.const 280 i32.const 488 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -12210,7 +12210,7 @@ if i32.const 280 i32.const 488 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -12226,7 +12226,7 @@ call $~lib/rt/pure/__release i32.const 3368 i32.const 488 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/iterator.json b/tests/compiler/std/iterator.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/std/iterator.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat new file mode 100644 index 0000000000..154d060e65 --- /dev/null +++ b/tests/compiler/std/iterator.optimized.wat @@ -0,0 +1,1711 @@ +(module + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05") + (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03") + (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") + (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 176) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s") + (data (i32.const 224) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h") + (data (i32.const 272) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s") + (data (i32.const 376) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00h\00e\00l\00l\00o") + (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d") + (global $std/iterator/iterableArr (mut i32) (i32.const 0)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $std/iterator/iter (mut i32) (i32.const 0)) + (global $std/iterator/res (mut i32) (i32.const 0)) + (global $std/iterator/i (mut i32) (i32.const 0)) + (global $std/iterator/arr2 (mut i32) (i32.const 0)) + (global $std/iterator/map (mut i32) (i32.const 0)) + (global $std/iterator/entries (mut i32) (i32.const 0)) + (global $std/iterator/resEntry (mut i32) (i32.const 0)) + (global $std/iterator/keyIter (mut i32) (i32.const 0)) + (global $std/iterator/key (mut i32) (i32.const 0)) + (global $std/iterator/valIter (mut i32) (i32.const 0)) + (global $std/iterator/val (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $3 + local.get $0 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.tee $2 + i32.const 16 + local.get $2 + i32.const 16 + i32.gt_u + select + local.tee $4 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $3 + i32.const 16 + i32.sub + local.tee $2 + local.get $4 + i32.store + local.get $2 + i32.const -1 + i32.store offset=4 + local.get $2 + local.get $1 + i32.store offset=8 + local.get $2 + local.get $0 + i32.store offset=12 + local.get $3 + ) + (func $std/iterator/IterableArray#get:iterator (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + i32.const 8 + i32.const 6 + call $~lib/rt/stub/__alloc + local.tee $1 + i32.const -1 + i32.store + local.get $1 + local.get $0 + i32.store offset=4 + local.get $1 + ) + (func $~lib/array/Array#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 88 + i32.const 144 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/memory/memory.fill (; 5 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + block $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.eqz + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 1 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 2 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 1 + i32.add + i32.const 0 + i32.store8 + local.get $0 + i32.const 2 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 2 + i32.sub + i32.const 0 + i32.store8 + local.get $2 + i32.const 3 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 6 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 3 + i32.add + i32.const 0 + i32.store8 + local.get $0 + local.get $1 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store8 + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $1 + i32.const 0 + local.get $0 + i32.sub + i32.const 3 + i32.and + local.tee $1 + i32.sub + local.get $0 + local.get $1 + i32.add + local.tee $0 + i32.const 0 + i32.store + i32.const -4 + i32.and + local.tee $1 + local.get $0 + i32.add + i32.const 4 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 8 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 4 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 8 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 12 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 8 + i32.sub + i32.const 0 + i32.store + local.get $1 + i32.const 24 + i32.le_u + br_if $~lib/util/memory/memset|inlined.0 + local.get $0 + i32.const 12 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 16 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 20 + i32.add + i32.const 0 + i32.store + local.get $0 + i32.const 24 + i32.add + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.add + local.tee $2 + i32.const 28 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 24 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 20 + i32.sub + i32.const 0 + i32.store + local.get $2 + i32.const 16 + i32.sub + i32.const 0 + i32.store + local.get $0 + i32.const 4 + i32.and + i32.const 24 + i32.add + local.tee $2 + local.get $0 + i32.add + local.set $0 + local.get $1 + local.get $2 + i32.sub + local.set $1 + loop $continue|0 + local.get $1 + i32.const 32 + i32.ge_u + if + local.get $0 + i64.const 0 + i64.store + local.get $0 + i32.const 8 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 16 + i32.add + i64.const 0 + i64.store + local.get $0 + i32.const 24 + i32.add + i64.const 0 + i64.store + local.get $1 + i32.const 32 + i32.sub + local.set $1 + local.get $0 + i32.const 32 + i32.add + local.set $0 + br $continue|0 + end + end + end + ) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 6 ;) (param $0 i32) (result i32) + (local $1 i32) + i32.const 0 + i32.const 0 + call $~lib/rt/stub/__alloc + local.tee $1 + i32.const 0 + call $~lib/memory/memory.fill + local.get $0 + i32.eqz + if + i32.const 12 + i32.const 2 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.load + drop + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + ) + (func $~lib/memory/memory.copy (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + block $~lib/util/memory/memmove|inlined.0 + local.get $2 + local.set $3 + local.get $0 + local.get $1 + i32.eq + br_if $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $1 + i32.lt_u + if + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|0 + local.get $0 + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + local.get $0 + local.tee $2 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $2 + local.get $4 + i32.load8_u + i32.store8 + br $continue|0 + end + end + loop $continue|1 + local.get $3 + i32.const 8 + i32.lt_u + i32.eqz + if + local.get $0 + local.get $1 + i64.load + i64.store + local.get $3 + i32.const 8 + i32.sub + local.set $3 + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + br $continue|1 + end + end + end + loop $continue|2 + local.get $3 + if + local.get $0 + local.tee $2 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.tee $4 + i32.const 1 + i32.add + local.set $1 + local.get $2 + local.get $4 + i32.load8_u + i32.store8 + local.get $3 + i32.const 1 + i32.sub + local.set $3 + br $continue|2 + end + end + else + local.get $1 + i32.const 7 + i32.and + local.get $0 + i32.const 7 + i32.and + i32.eq + if + loop $continue|3 + local.get $0 + local.get $3 + i32.add + i32.const 7 + i32.and + if + local.get $3 + i32.eqz + br_if $~lib/util/memory/memmove|inlined.0 + local.get $0 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|3 + end + end + loop $continue|4 + local.get $3 + i32.const 8 + i32.lt_u + i32.eqz + if + local.get $0 + local.get $3 + i32.const 8 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i64.load + i64.store + br $continue|4 + end + end + end + loop $continue|5 + local.get $3 + if + local.get $0 + local.get $3 + i32.const 1 + i32.sub + local.tee $3 + i32.add + local.get $1 + local.get $3 + i32.add + i32.load8_u + i32.store8 + br $continue|5 + end + end + end + end + ) + (func $~lib/rt/stub/__realloc (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + i32.const 15 + i32.and + i32.eqz + i32.const 0 + local.get $0 + select + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 43 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 16 + i32.sub + local.tee $3 + i32.load + local.set $4 + local.get $3 + i32.load offset=4 + i32.const -1 + i32.ne + if + i32.const 0 + i32.const 344 + i32.const 46 + i32.const 13 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/rt/stub/offset + local.get $0 + local.get $4 + i32.add + i32.eq + local.set $5 + local.get $1 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.set $2 + local.get $1 + local.get $4 + i32.gt_u + if + local.get $5 + if + local.get $1 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + local.get $0 + local.get $2 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $3 + local.get $2 + i32.store + else + local.get $2 + local.get $4 + i32.const 1 + i32.shl + local.tee $4 + local.get $2 + local.get $4 + i32.gt_u + select + local.get $3 + i32.load offset=8 + call $~lib/rt/stub/__alloc + local.tee $2 + local.get $0 + local.get $3 + i32.load offset=12 + call $~lib/memory/memory.copy + local.get $2 + local.tee $0 + i32.const 16 + i32.sub + local.set $3 + end + else + local.get $5 + if + local.get $0 + local.get $2 + i32.add + global.set $~lib/rt/stub/offset + local.get $3 + local.get $2 + i32.store + end + end + local.get $3 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/array/ensureSize (; 9 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $1 + local.get $0 + i32.load offset=8 + local.tee $2 + i32.const 2 + i32.shr_u + i32.gt_u + if + local.get $1 + i32.const 268435452 + i32.gt_u + if + i32.const 240 + i32.const 144 + i32.const 14 + i32.const 47 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load + local.tee $4 + local.get $1 + i32.const 2 + i32.shl + local.tee $3 + call $~lib/rt/stub/__realloc + local.tee $1 + local.get $2 + i32.add + local.get $3 + local.get $2 + i32.sub + call $~lib/memory/memory.fill + local.get $1 + local.get $4 + i32.ne + if + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + end + local.get $0 + local.get $3 + i32.store offset=8 + end + ) + (func $~lib/array/Array#push (; 10 ;) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + local.get $0 + local.get $0 + i32.load offset=12 + local.tee $2 + i32.const 1 + i32.add + local.tee $3 + call $~lib/array/ensureSize + local.get $0 + i32.load offset=4 + local.get $2 + i32.const 2 + i32.shl + i32.add + local.get $1 + i32.store + local.get $0 + local.get $3 + i32.store offset=12 + ) + (func $~lib/array/Array.from (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + i32.const 16 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/arraybuffer/ArrayBufferView#constructor + local.tee $1 + i32.const 0 + i32.store offset=12 + local.get $1 + i32.const 0 + i32.store offset=12 + local.get $0 + local.tee $3 + call $~lib/iterator/Iterator#next + local.set $0 + loop $continue|0 + local.get $0 + call $~lib/iterator/IteratorResult#get:done + i32.eqz + if + local.get $1 + local.get $0 + call $~lib/iterator/IteratorResult#get:value + call $~lib/array/Array#push + local.get $3 + call $~lib/iterator/Iterator#next + local.set $0 + local.get $2 + i32.const 1 + i32.add + local.set $2 + br $continue|0 + end + end + local.get $1 + i32.load offset=12 + drop + local.get $1 + local.get $2 + call $~lib/array/ensureSize + local.get $1 + local.get $2 + i32.store offset=12 + local.get $1 + ) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 12 ;) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + i32.const 240 + i32.const 288 + i32.const 54 + i32.const 42 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 0 + call $~lib/rt/stub/__alloc + local.tee $1 + local.get $0 + call $~lib/memory/memory.fill + local.get $1 + ) + (func $~lib/map/Map<~lib/string/String,i32>#clear (; 13 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + i32.const 16 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $1 + local.get $0 + i32.load + drop + local.get $0 + local.get $1 + i32.store + local.get $0 + i32.const 3 + i32.store offset=4 + i32.const 48 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $1 + local.get $0 + i32.load offset=8 + drop + local.get $0 + local.get $1 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + ) + (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 14 ;) (result i32) + (local $0 i32) + i32.const 24 + i32.const 8 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#clear + local.get $0 + ) + (func $~lib/string/String#get:length (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/hash/hashStr (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + i32.const -2128831035 + local.set $1 + local.get $0 + local.tee $2 + if + block $break|0 + i32.const 0 + local.set $0 + local.get $2 + call $~lib/string/String#get:length + i32.const 1 + i32.shl + local.set $3 + loop $loop|0 + local.get $0 + local.get $3 + i32.ge_u + br_if $break|0 + local.get $0 + local.get $2 + i32.add + i32.load8_u + local.get $1 + i32.xor + i32.const 16777619 + i32.mul + local.set $1 + local.get $0 + i32.const 1 + i32.add + local.set $0 + br $loop|0 + end + unreachable + end + end + local.get $1 + ) + (func $~lib/util/string/compareImpl (; 17 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 7 + i32.and + local.get $1 + i32.const 7 + i32.and + i32.or + i32.eqz + i32.const 0 + local.get $2 + i32.const 4 + i32.ge_u + select + if + loop $continue|0 + local.get $0 + i64.load + local.get $1 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + local.get $2 + i32.const 4 + i32.sub + local.tee $2 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + loop $continue|1 + block $break|1 + local.get $2 + local.tee $3 + i32.const 1 + i32.sub + local.set $2 + local.get $3 + i32.eqz + br_if $break|1 + local.get $1 + i32.load16_u + local.tee $3 + local.get $0 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $4 + local.get $3 + i32.sub + return + else + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + br $continue|1 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/string/String.__eq (; 18 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + return + end + block $folding-inner0 + local.get $1 + i32.eqz + i32.const 1 + local.get $0 + select + br_if $folding-inner0 + local.get $0 + call $~lib/string/String#get:length + local.tee $2 + local.get $1 + call $~lib/string/String#get:length + i32.ne + br_if $folding-inner0 + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/string/compareImpl + i32.eqz + return + end + i32.const 0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#find (; 19 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + local.get $2 + i32.and + i32.const 2 + i32.shl + i32.add + i32.load + local.set $0 + loop $continue|0 + local.get $0 + if + local.get $0 + i32.load offset=8 + i32.const 1 + i32.and + if (result i32) + i32.const 0 + else + local.get $0 + i32.load + local.get $1 + call $~lib/string/String.__eq + end + if + local.get $0 + return + else + local.get $0 + i32.load offset=8 + i32.const -2 + i32.and + local.set $0 + br $continue|0 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + local.get $1 + i32.const 1 + i32.add + local.tee $4 + i32.const 2 + i32.shl + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $5 + local.get $4 + i32.const 3 + i32.shl + i32.const 3 + i32.div_s + local.tee $6 + i32.const 12 + i32.mul + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $4 + local.get $0 + i32.load offset=8 + local.tee $2 + local.get $0 + i32.load offset=16 + i32.const 12 + i32.mul + i32.add + local.set $7 + local.get $4 + local.set $3 + loop $continue|0 + local.get $2 + local.get $7 + i32.ne + if + local.get $2 + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + if + local.get $3 + local.get $2 + i32.load + i32.store + local.get $3 + local.get $2 + i32.load offset=4 + i32.store offset=4 + local.get $3 + local.get $2 + i32.load + call $~lib/util/hash/hashStr + local.get $1 + i32.and + i32.const 2 + i32.shl + local.get $5 + i32.add + local.tee $8 + i32.load + i32.store offset=8 + local.get $8 + local.get $3 + i32.store + local.get $3 + i32.const 12 + i32.add + local.set $3 + end + local.get $2 + i32.const 12 + i32.add + local.set $2 + br $continue|0 + end + end + local.get $5 + local.tee $2 + local.get $0 + i32.load + i32.ne + drop + local.get $0 + local.get $2 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $4 + local.tee $1 + local.get $0 + i32.load offset=8 + i32.ne + drop + local.get $0 + local.get $1 + i32.store offset=8 + local.get $0 + local.get $6 + i32.store offset=12 + local.get $0 + local.get $0 + i32.load offset=20 + i32.store offset=16 + ) + (func $~lib/map/Map<~lib/string/String,i32>#set (; 21 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + local.get $1 + local.get $1 + call $~lib/util/hash/hashStr + local.tee $4 + call $~lib/map/Map<~lib/string/String,i32>#find + local.tee $3 + if + local.get $3 + local.get $2 + i32.store offset=4 + else + local.get $0 + i32.load offset=16 + local.get $0 + i32.load offset=12 + i32.eq + if + local.get $0 + local.get $0 + i32.load offset=20 + local.get $0 + i32.load offset=12 + i32.const 3 + i32.mul + i32.const 4 + i32.div_s + i32.lt_s + if (result i32) + local.get $0 + i32.load offset=4 + else + local.get $0 + i32.load offset=4 + i32.const 1 + i32.shl + i32.const 1 + i32.or + end + call $~lib/map/Map<~lib/string/String,i32>#rehash + end + local.get $0 + i32.load offset=8 + local.set $3 + local.get $0 + local.get $0 + i32.load offset=16 + local.tee $5 + i32.const 1 + i32.add + i32.store offset=16 + local.get $5 + i32.const 12 + i32.mul + local.get $3 + i32.add + local.tee $3 + local.get $1 + i32.store + local.get $3 + local.get $2 + i32.store offset=4 + local.get $0 + local.get $0 + i32.load offset=20 + i32.const 1 + i32.add + i32.store offset=20 + local.get $3 + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + local.get $4 + i32.and + i32.const 2 + i32.shl + i32.add + local.tee $0 + i32.load + i32.store offset=8 + local.get $0 + local.get $3 + i32.store + end + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 22 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 16 + i32.const 9 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.get $2 + i32.store offset=8 + local.get $0 + local.get $3 + i32.store offset=12 + local.get $0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#entries (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 0 + local.get $0 + local.get $0 + i32.load offset=8 + local.get $0 + i32.load offset=16 + call $~lib/map/EntriesIter<~lib/string/String,i32>#constructor + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=12 + i32.ge_u + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=8 + local.get $0 + i32.load + i32.const 12 + i32.mul + i32.add + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + loop $continue|0 + block $break|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + br_if $break|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + br_if $break|0 + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + br $continue|0 + end + end + local.get $0 + ) + (func $start:std/iterator (; 27 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + i32.const 56 + global.set $std/iterator/iterableArr + i32.const 448 + global.set $~lib/rt/stub/startOffset + i32.const 448 + global.set $~lib/rt/stub/offset + i32.const 56 + call $std/iterator/IterableArray#get:iterator + global.set $std/iterator/iter + global.get $std/iterator/iter + call $~lib/iterator/Iterator#next + global.set $std/iterator/res + loop $continue|0 + global.get $std/iterator/res + call $~lib/iterator/IteratorResult#get:done + i32.eqz + if + global.get $std/iterator/res + call $~lib/iterator/IteratorResult#get:value + local.set $0 + global.get $std/iterator/i + local.tee $1 + i32.const 1 + i32.add + global.set $std/iterator/i + i32.const 56 + local.get $1 + call $~lib/array/Array#__get + local.get $0 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 40 + i32.const 2 + call $~lib/builtins/abort + unreachable + else + global.get $std/iterator/iter + call $~lib/iterator/Iterator#next + global.set $std/iterator/res + br $continue|0 + end + unreachable + end + end + global.get $std/iterator/iterableArr + call $std/iterator/IterableArray#get:iterator + call $~lib/array/Array.from + global.set $std/iterator/arr2 + i32.const 68 + i32.load + i32.const 3 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 48 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/arr2 + i32.const 0 + call $~lib/array/Array#__get + i32.const 1 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 49 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/arr2 + i32.const 1 + call $~lib/array/Array#__get + i32.const 3 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 50 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + call $~lib/map/Map<~lib/string/String,i32>#constructor + global.set $std/iterator/map + global.get $std/iterator/map + i32.const 392 + i32.const 40 + call $~lib/map/Map<~lib/string/String,i32>#set + global.get $std/iterator/map + i32.const 424 + i32.const 1 + call $~lib/map/Map<~lib/string/String,i32>#set + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#entries + global.set $std/iterator/entries + global.get $std/iterator/entries + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + global.set $std/iterator/resEntry + global.get $std/iterator/resEntry + local.tee $0 + i32.const 8 + i32.sub + i32.load + i32.const 9 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + else + unreachable + end + i32.load + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 58 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#entries + local.set $0 + i32.const 4 + i32.const 12 + call $~lib/rt/stub/__alloc + local.tee $1 + local.get $0 + i32.store + local.get $1 + global.set $std/iterator/keyIter + global.get $std/iterator/keyIter + local.tee $0 + i32.const 8 + i32.sub + i32.load + i32.const 12 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next + else + unreachable + end + global.set $std/iterator/key + global.get $std/iterator/key + local.tee $0 + i32.const 8 + i32.sub + i32.load + i32.const 12 + i32.eq + if (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load + else + unreachable + end + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 62 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#entries + local.set $0 + i32.const 4 + i32.const 14 + call $~lib/rt/stub/__alloc + local.tee $1 + local.get $0 + i32.store + local.get $1 + global.set $std/iterator/valIter + global.get $std/iterator/valIter + call $~lib/iterator/Iterator#next + global.set $std/iterator/val + global.get $std/iterator/val + call $~lib/iterator/IteratorResult#get:value + i32.const 40 + i32.ne + if + i32.const 0 + i32.const 192 + i32.const 66 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 28 ;) (type $FUNCSIG$v) + call $start:std/iterator + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 29 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + drop + local.get $0 + ) + (func $~lib/iterator/Iterator#next (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 6 + i32.eq + if + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next + else + unreachable + end + local.set $0 + end + local.get $0 + ) + (func $std/iterator/ArrayIterator#get:done (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + i32.load offset=12 + i32.ge_s + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + ) + (func $~lib/iterator/IteratorResult#get:value (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 6 + i32.eq + if + block $__inlined_func$std/iterator/ArrayIterator#get:value + local.get $0 + call $std/iterator/ArrayIterator#get:done + i32.eqz + if + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get + local.set $0 + br $__inlined_func$std/iterator/ArrayIterator#get:value + end + unreachable + end + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=4 + else + unreachable + end + local.set $0 + end + local.get $0 + ) + (func $~lib/iterator/IteratorResult#get:done (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $std/iterator/ArrayIterator#get:done + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + else + unreachable + end + end + ) + (func $null (; 35 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/iterator.ts b/tests/compiler/std/iterator.ts similarity index 69% rename from tests/compiler/iterator.ts rename to tests/compiler/std/iterator.ts index f125612a22..3149d58fb1 100644 --- a/tests/compiler/iterator.ts +++ b/tests/compiler/std/iterator.ts @@ -1,6 +1,3 @@ -import {Iterator, Iterable} from "iterator"; - - class ArrayIterator implements Iterator { private _index: i32 = -1; constructor(private _array: Array){} @@ -16,7 +13,7 @@ class ArrayIterator implements Iterator { unreachable(); return changetype(this); } - next(): Iterator { + next(): IteratorResult { this._index++; return this; } @@ -50,4 +47,21 @@ let arr2: Array = Array.from(iterableArr.iterator); // assert (arr2 != null); assert(arr.length == 3); assert(arr2[0]== 1) -assert(arr2[1]== 3) \ No newline at end of file +assert(arr2[1]== 3) + +let map = new Map(); +map.set("hello", 40); +map.set("world", 1); + +let entries = map.entries(); +let resEntry = entries.next(); +assert(resEntry.value.key == "hello"); + +let keyIter = map.keys(); +let key = keyIter.next(); +assert(key.value == "hello"); + +let valIter = map.values(); +let val = valIter.next(); +assert(val.value == 40); + diff --git a/tests/compiler/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat similarity index 58% rename from tests/compiler/iterator.untouched.wat rename to tests/compiler/std/iterator.untouched.wat index 7cc87ee8db..56eb33f4f3 100644 --- a/tests/compiler/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -6,6 +6,8 @@ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -13,22 +15,31 @@ (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03\00\00\00") (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00") (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 176) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s\00") - (data (i32.const 216) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h\00") - (data (i32.const 264) "&\00\00\00\01\00\00\00\01\00\00\00&\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 320) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") - (table $0 6 funcref) - (elem (i32.const 0) $null $iterator/ArrayIterator#constructor $iterator/IterableArray#get:iterator $iterator/ArrayIterator#get:done $iterator/ArrayIterator#get:value $iterator/ArrayIterator#next) - (global $iterator/arr (mut i32) (i32.const 56)) - (global $iterator/iterableArr (mut i32) (i32.const 0)) + (data (i32.const 176) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s\00") + (data (i32.const 224) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h\00") + (data (i32.const 272) "&\00\00\00\01\00\00\00\01\00\00\00&\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 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") + (data (i32.const 376) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00h\00e\00l\00l\00o\00") + (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d\00") + (table $0 11 funcref) + (elem (i32.const 0) $null $std/iterator/ArrayIterator#constructor $std/iterator/IterableArray#get:iterator $~lib/map/EntriesIter<~lib/string/String,i32>#constructor $~lib/map/EntriesIter<~lib/string/String,i32>#get:done $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry $~lib/map/EntriesIter<~lib/string/String,i32>#next $std/iterator/ArrayIterator#next $std/iterator/ArrayIterator#get:done $std/iterator/ArrayIterator#get:value $~lib/map/EntriesIter<~lib/string/String,i32>#get:value) + (global $std/iterator/arr (mut i32) (i32.const 56)) + (global $std/iterator/iterableArr (mut i32) (i32.const 0)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $iterator/iter (mut i32) (i32.const 0)) - (global $iterator/res (mut i32) (i32.const 0)) - (global $iterator/i (mut i32) (i32.const 0)) + (global $std/iterator/iter (mut i32) (i32.const 0)) + (global $std/iterator/res (mut i32) (i32.const 0)) + (global $std/iterator/i (mut i32) (i32.const 0)) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) - (global $iterator/arr2 (mut i32) (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 368)) + (global $std/iterator/arr2 (mut i32) (i32.const 0)) + (global $std/iterator/map (mut i32) (i32.const 0)) + (global $std/iterator/entries (mut i32) (i32.const 0)) + (global $std/iterator/resEntry (mut i32) (i32.const 0)) + (global $std/iterator/keyIter (mut i32) (i32.const 0)) + (global $std/iterator/key (mut i32) (i32.const 0)) + (global $std/iterator/valIter (mut i32) (i32.const 0)) + (global $std/iterator/val (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 436)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/__retain (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -144,7 +155,7 @@ (func $~lib/rt/stub/__release (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $iterator/ArrayIterator#constructor (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/iterator/ArrayIterator#constructor (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 call $~lib/rt/stub/__retain local.set $1 @@ -168,10 +179,10 @@ call $~lib/rt/stub/__release local.get $0 ) - (func $iterator/IterableArray#get:iterator (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/IterableArray#get:iterator (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 0 local.get $0 - call $iterator/ArrayIterator#constructor + call $std/iterator/ArrayIterator#constructor ) (func $~lib/array/Array#__unchecked_get (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 @@ -191,7 +202,7 @@ if i32.const 88 i32.const 144 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -477,8 +488,8 @@ i32.shr_u i32.gt_u if - i32.const 232 - i32.const 280 + i32.const 240 + i32.const 288 i32.const 23 i32.const 56 call $~lib/builtins/abort @@ -1834,7 +1845,7 @@ i32.eqz if i32.const 0 - i32.const 336 + i32.const 344 i32.const 43 i32.const 2 call $~lib/builtins/abort @@ -1854,7 +1865,7 @@ i32.eqz if i32.const 0 - i32.const 336 + i32.const 344 i32.const 46 i32.const 13 call $~lib/builtins/abort @@ -1956,9 +1967,9 @@ i32.shr_u i32.gt_u if - i32.const 232 + i32.const 240 i32.const 144 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -2059,13 +2070,13 @@ block $break|0 loop $continue|0 local.get $2 - call $~lib/iterator/Iterator#get:done + call $~lib/iterator/IteratorResult#get:done i32.eqz i32.eqz br_if $break|0 local.get $1 local.get $2 - call $~lib/iterator/Iterator#get:value + call $~lib/iterator/IteratorResult#get:value call $~lib/array/Array#push drop local.get $0 @@ -2098,12 +2109,856 @@ local.get $0 i32.load offset=12 ) - (func $start:iterator (; 20 ;) (type $FUNCSIG$v) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + i32.const 1073741808 + i32.gt_u + if + i32.const 240 + i32.const 288 + i32.const 54 + i32.const 42 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 0 + call $~lib/rt/stub/__alloc + local.set $2 + local.get $2 + i32.const 0 + local.get $1 + call $~lib/memory/memory.fill + local.get $2 + call $~lib/rt/stub/__retain + ) + (func $~lib/map/Map<~lib/string/String,i32>#clear (; 21 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + local.tee $1 + i32.const 0 + i32.const 16 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $2 + local.get $1 + i32.load + call $~lib/rt/stub/__release + local.get $2 + i32.store + local.get $0 + i32.const 4 + i32.const 1 + i32.sub + i32.store offset=4 + local.get $0 + local.tee $1 + i32.const 0 + i32.const 48 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $2 + local.get $1 + i32.load offset=8 + call $~lib/rt/stub/__release + local.get $2 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + ) + (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 24 + i32.const 8 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#clear + local.get $0 + ) + (func $~lib/string/String#get:length (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/hash/hashStr (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + i32.const -2128831035 + local.set $1 + local.get $0 + i32.const 0 + i32.ne + if + block $break|0 + i32.const 0 + local.set $2 + local.get $0 + call $~lib/string/String#get:length + i32.const 1 + i32.shl + local.set $3 + loop $loop|0 + local.get $2 + local.get $3 + i32.lt_u + i32.eqz + br_if $break|0 + local.get $1 + local.get $0 + local.get $2 + i32.add + i32.load8_u + i32.xor + i32.const 16777619 + i32.mul + local.set $1 + local.get $2 + i32.const 1 + i32.add + local.set $2 + br $loop|0 + end + unreachable + end + end + local.get $1 + local.set $3 + local.get $0 + call $~lib/rt/stub/__release + local.get $3 + ) + (func $~lib/util/string/compareImpl (; 25 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $break|0 + loop $continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + i32.eqz + br_if $break|1 + local.get $5 + i32.load16_u + local.set $7 + local.get $6 + i32.load16_u + local.set $8 + local.get $7 + local.get $8 + i32.ne + if + local.get $7 + local.get $8 + i32.sub + local.set $9 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $9 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $continue|1 + end + unreachable + end + i32.const 0 + local.set $8 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $8 + ) + (func $~lib/string/String.__eq (; 26 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $~lib/map/Map<~lib/string/String,i32>#find (; 27 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.load + local.get $2 + local.get $0 + i32.load offset=4 + i32.and + i32.const 4 + i32.mul + i32.add + i32.load + local.set $3 + block $break|0 + loop $continue|0 + local.get $3 + i32.eqz + br_if $break|0 + local.get $3 + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + if (result i32) + local.get $3 + i32.load + local.get $1 + call $~lib/string/String.__eq + else + i32.const 0 + end + if + local.get $3 + local.set $4 + local.get $1 + call $~lib/rt/stub/__release + local.get $4 + return + end + local.get $3 + i32.load offset=8 + i32.const 1 + i32.const -1 + i32.xor + i32.and + local.set $3 + br $continue|0 + end + unreachable + end + i32.const 0 + local.set $4 + local.get $1 + call $~lib/rt/stub/__release + local.get $4 + ) + (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 28 ;) (type $FUNCSIG$vii) (param $0 i32) (param $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) + (local $10 i32) + (local $11 i32) + (local $12 i32) + local.get $1 + i32.const 1 + i32.add + local.set $2 + i32.const 0 + local.get $2 + i32.const 4 + i32.mul + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $3 + local.get $2 + i32.const 8 + i32.mul + i32.const 3 + i32.div_s + local.set $4 + i32.const 0 + local.get $4 + i32.const 12 + i32.mul + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $5 + local.get $0 + i32.load offset=8 + local.set $6 + local.get $6 + local.get $0 + i32.load offset=16 + i32.const 12 + i32.mul + i32.add + local.set $7 + local.get $5 + local.set $8 + block $break|0 + loop $continue|0 + local.get $6 + local.get $7 + i32.ne + i32.eqz + br_if $break|0 + local.get $6 + local.set $9 + local.get $9 + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + if + local.get $8 + local.set $10 + local.get $10 + local.get $9 + i32.load + i32.store + local.get $10 + local.get $9 + i32.load offset=4 + i32.store offset=4 + block $~lib/util/hash/HASH<~lib/string/String>|inlined.1 (result i32) + local.get $9 + i32.load + call $~lib/rt/stub/__retain + local.set $11 + local.get $11 + call $~lib/util/hash/hashStr + local.set $12 + local.get $11 + call $~lib/rt/stub/__release + local.get $12 + br $~lib/util/hash/HASH<~lib/string/String>|inlined.1 + end + local.get $1 + i32.and + local.set $11 + local.get $3 + local.get $11 + i32.const 4 + i32.mul + i32.add + local.set $12 + local.get $10 + local.get $12 + i32.load + i32.store offset=8 + local.get $12 + local.get $8 + i32.store + local.get $8 + i32.const 12 + i32.add + local.set $8 + end + local.get $6 + i32.const 12 + i32.add + local.set $6 + br $continue|0 + end + unreachable + end + local.get $0 + local.tee $9 + local.get $3 + local.tee $10 + local.get $9 + i32.load + local.tee $12 + i32.ne + if + local.get $10 + call $~lib/rt/stub/__retain + local.set $10 + local.get $12 + call $~lib/rt/stub/__release + end + local.get $10 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.tee $9 + local.get $5 + local.tee $11 + local.get $9 + i32.load offset=8 + local.tee $10 + i32.ne + if + local.get $11 + call $~lib/rt/stub/__retain + local.set $11 + local.get $10 + call $~lib/rt/stub/__release + end + local.get $11 + i32.store offset=8 + local.get $0 + local.get $4 + i32.store offset=12 + local.get $0 + local.get $0 + i32.load offset=20 + i32.store offset=16 + local.get $3 + call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + ) + (func $~lib/map/Map<~lib/string/String,i32>#set (; 29 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + block $~lib/util/hash/HASH<~lib/string/String>|inlined.0 (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $3 + local.get $3 + call $~lib/util/hash/hashStr + local.set $4 + local.get $3 + call $~lib/rt/stub/__release + local.get $4 + br $~lib/util/hash/HASH<~lib/string/String>|inlined.0 + end + local.set $5 + local.get $0 + local.get $1 + local.get $5 + call $~lib/map/Map<~lib/string/String,i32>#find + local.set $6 + local.get $6 + if + local.get $6 + local.get $2 + i32.store offset=4 + else + local.get $0 + i32.load offset=16 + local.get $0 + i32.load offset=12 + i32.eq + if + local.get $0 + local.get $0 + i32.load offset=20 + local.get $0 + i32.load offset=12 + i32.const 3 + i32.mul + i32.const 4 + i32.div_s + i32.lt_s + if (result i32) + local.get $0 + i32.load offset=4 + else + local.get $0 + i32.load offset=4 + i32.const 1 + i32.shl + i32.const 1 + i32.or + end + call $~lib/map/Map<~lib/string/String,i32>#rehash + end + local.get $0 + i32.load offset=8 + call $~lib/rt/stub/__retain + local.set $3 + local.get $3 + local.get $0 + local.get $0 + i32.load offset=16 + local.tee $4 + i32.const 1 + i32.add + i32.store offset=16 + local.get $4 + i32.const 12 + i32.mul + i32.add + local.set $6 + local.get $6 + local.get $1 + call $~lib/rt/stub/__retain + i32.store + local.get $6 + local.get $2 + i32.store offset=4 + local.get $0 + local.get $0 + i32.load offset=20 + i32.const 1 + i32.add + i32.store offset=20 + local.get $0 + i32.load + local.get $5 + local.get $0 + i32.load offset=4 + i32.and + i32.const 4 + i32.mul + i32.add + local.set $4 + local.get $6 + local.get $4 + i32.load + i32.store offset=8 + local.get $4 + local.get $6 + i32.store + local.get $3 + call $~lib/rt/stub/__release + end + local.get $1 + call $~lib/rt/stub/__release + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 30 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.eqz + if + i32.const 16 + i32.const 9 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 0 + i32.store + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store offset=4 + local.get $0 + local.get $2 + i32.store offset=8 + local.get $0 + local.get $3 + i32.store offset=12 + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#entries (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=8 + local.set $1 + local.get $0 + i32.load offset=16 + local.set $2 + i32.const 0 + local.get $0 + local.get $1 + local.get $2 + call $~lib/map/EntriesIter<~lib/string/String,i32>#constructor + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=12 + i32.ge_u + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=8 + local.get $0 + i32.load + i32.const 12 + i32.mul + i32.add + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $break|0 + loop $continue|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + i32.eqz + i32.eqz + br_if $break|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + if + br $break|0 + end + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + br $continue|0 + end + unreachable + end + local.get $0 + call $~lib/rt/stub/__retain + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#constructor (; 35 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 12 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#keys (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + i32.const 0 + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#entries + local.tee $1 + call $~lib/map/KeyIterator<~lib/string/String,i32>#constructor + local.set $2 + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#constructor (; 37 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 14 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#values (; 38 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + i32.const 0 + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#entries + local.tee $1 + call $~lib/map/ValueIterator<~lib/string/String,i32>#constructor + local.set $2 + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $start:std/iterator (; 39 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) - global.get $iterator/arr + (local $2 i32) + global.get $std/iterator/arr call $~lib/rt/stub/__retain - global.set $iterator/iterableArr + global.set $std/iterator/iterableArr global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -2114,29 +2969,29 @@ global.set $~lib/rt/stub/startOffset global.get $~lib/rt/stub/startOffset global.set $~lib/rt/stub/offset - global.get $iterator/iterableArr - call $iterator/IterableArray#get:iterator + global.get $std/iterator/iterableArr + call $std/iterator/IterableArray#get:iterator local.tee $1 call $~lib/rt/stub/__retain - global.set $iterator/iter - global.get $iterator/iter + global.set $std/iterator/iter + global.get $std/iterator/iter call $~lib/iterator/Iterator#next - global.set $iterator/res + global.set $std/iterator/res block $break|0 loop $continue|0 - global.get $iterator/res - call $~lib/iterator/Iterator#get:done + global.get $std/iterator/res + call $~lib/iterator/IteratorResult#get:done i32.eqz i32.eqz br_if $break|0 - global.get $iterator/res - call $~lib/iterator/Iterator#get:value - global.get $iterator/arr - global.get $iterator/i + global.get $std/iterator/res + call $~lib/iterator/IteratorResult#get:value + global.get $std/iterator/arr + global.get $std/iterator/i local.tee $0 i32.const 1 i32.add - global.set $iterator/i + global.set $std/iterator/i local.get $0 call $~lib/array/Array#__get i32.eq @@ -2144,28 +2999,28 @@ if i32.const 0 i32.const 192 - i32.const 43 + i32.const 40 i32.const 2 call $~lib/builtins/abort unreachable end - global.get $iterator/iter + global.get $std/iterator/iter call $~lib/iterator/Iterator#next local.set $0 - global.get $iterator/res + global.get $std/iterator/res call $~lib/rt/stub/__release local.get $0 - global.set $iterator/res + global.set $std/iterator/res br $continue|0 end unreachable end - global.get $iterator/iterableArr - call $iterator/IterableArray#get:iterator + global.get $std/iterator/iterableArr + call $std/iterator/IterableArray#get:iterator local.tee $0 call $~lib/array/Array.from - global.set $iterator/arr2 - global.get $iterator/arr + global.set $std/iterator/arr2 + global.get $std/iterator/arr call $~lib/array/Array#get:length i32.const 3 i32.eq @@ -2173,12 +3028,12 @@ if i32.const 0 i32.const 192 - i32.const 51 + i32.const 48 i32.const 0 call $~lib/builtins/abort unreachable end - global.get $iterator/arr2 + global.get $std/iterator/arr2 i32.const 0 call $~lib/array/Array#__get i32.const 1 @@ -2187,12 +3042,12 @@ if i32.const 0 i32.const 192 - i32.const 52 + i32.const 49 i32.const 0 call $~lib/builtins/abort unreachable end - global.get $iterator/arr2 + global.get $std/iterator/arr2 i32.const 1 call $~lib/array/Array#__get i32.const 3 @@ -2201,7 +3056,77 @@ if i32.const 0 i32.const 192 - i32.const 53 + i32.const 50 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + call $~lib/map/Map<~lib/string/String,i32>#constructor + global.set $std/iterator/map + global.get $std/iterator/map + i32.const 392 + i32.const 40 + call $~lib/map/Map<~lib/string/String,i32>#set + global.get $std/iterator/map + i32.const 424 + i32.const 1 + call $~lib/map/Map<~lib/string/String,i32>#set + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#entries + global.set $std/iterator/entries + global.get $std/iterator/entries + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + global.set $std/iterator/resEntry + global.get $std/iterator/resEntry + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value + i32.load + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 58 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#keys + global.set $std/iterator/keyIter + global.get $std/iterator/keyIter + call $~lib/iterator/Iterator<~lib/string/String>#next + global.set $std/iterator/key + global.get $std/iterator/key + call $~lib/iterator/IteratorResult<~lib/string/String>#get:value + local.tee $2 + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 62 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#values + global.set $std/iterator/valIter + global.get $std/iterator/valIter + call $~lib/iterator/Iterator#next + global.set $std/iterator/val + global.get $std/iterator/val + call $~lib/iterator/IteratorResult#get:value + i32.const 40 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 66 i32.const 0 call $~lib/builtins/abort unreachable @@ -2210,19 +3135,31 @@ call $~lib/rt/stub/__release local.get $1 call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release ) - (func $start (; 21 ;) (type $FUNCSIG$v) - call $start:iterator + (func $start (; 40 ;) (type $FUNCSIG$v) + call $start:std/iterator ) - (func $iterator/ArrayIterator#get:done (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#next (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 local.get $0 i32.load + i32.const 1 + i32.add + i32.store local.get $0 - i32.load offset=4 - call $~lib/array/Array#get:length - i32.ge_s + call $~lib/rt/stub/__retain + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 42 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator#get:done (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator#next (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -2234,14 +3171,30 @@ i32.eq if (result i32) local.get $0 - call $iterator/ArrayIterator#get:done + call $std/iterator/ArrayIterator#next else - unreachable + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next + else + unreachable + end end ) - (func $iterator/ArrayIterator#get:value (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:done (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + call $~lib/array/Array#get:length + i32.ge_s + ) + (func $std/iterator/ArrayIterator#get:value (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - call $iterator/ArrayIterator#get:done + call $std/iterator/ArrayIterator#get:done i32.eqz if local.get $0 @@ -2253,7 +3206,47 @@ end unreachable ) - (func $~lib/iterator/Iterator#get:value (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value + i32.load offset=4 + ) + (func $~lib/iterator/IteratorResult#get:value (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $std/iterator/ArrayIterator#get:value + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value + else + unreachable + end + end + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult#get:done (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -2265,22 +3258,62 @@ i32.eq if (result i32) local.get $0 - call $iterator/ArrayIterator#get:value + call $std/iterator/ArrayIterator#get:done + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done + else + unreachable + end + end + ) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 51 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 9 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value else unreachable end ) - (func $iterator/ArrayIterator#next (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:done (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 9 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + else + unreachable + end + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load - i32.const 1 - i32.add - i32.store + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + call $~lib/rt/stub/__release local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator#next (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -2288,15 +3321,61 @@ i32.load local.set $1 local.get $1 - i32.const 6 + i32.const 12 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#next + else + unreachable + end + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value + i32.load + call $~lib/rt/stub/__retain + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 56 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 12 + i32.eq + if (result i32) + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:value + else + unreachable + end + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:done (; 57 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 58 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 12 i32.eq if (result i32) local.get $0 - call $iterator/ArrayIterator#next + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:done else unreachable end ) - (func $null (; 28 ;) (type $FUNCSIG$v) + (func $null (; 59 ;) (type $FUNCSIG$v) ) ) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index d8244b6f3c..a86dfae56a 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -2383,7 +2383,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -3076,7 +3076,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -3819,7 +3819,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -4512,7 +4512,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -5257,7 +5257,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -6400,7 +6400,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -7463,7 +7463,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -8174,7 +8174,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index c64fdda949..8a8bbc7d2f 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -4003,7 +4003,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -4887,7 +4887,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -5785,7 +5785,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -6669,7 +6669,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -7571,7 +7571,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -8415,7 +8415,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -9349,7 +9349,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -10203,7 +10203,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -11061,7 +11061,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -11920,7 +11920,7 @@ if i32.const 416 i32.const 472 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index be1bb940b2..a17529079b 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -32,7 +32,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -647,7 +647,7 @@ if i32.const 424 i32.const 376 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -709,7 +709,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -748,7 +748,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -787,7 +787,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/static-array.untouched.wat b/tests/compiler/std/static-array.untouched.wat index 14c250b2a8..4fba861c4f 100644 --- a/tests/compiler/std/static-array.untouched.wat +++ b/tests/compiler/std/static-array.untouched.wat @@ -60,7 +60,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -1843,7 +1843,7 @@ if i32.const 424 i32.const 376 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -1906,7 +1906,7 @@ if i32.const 320 i32.const 376 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -1950,7 +1950,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -1983,7 +1983,7 @@ if i32.const 320 i32.const 376 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -2027,7 +2027,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -2060,7 +2060,7 @@ if i32.const 320 i32.const 376 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable @@ -2104,7 +2104,7 @@ if i32.const 320 i32.const 376 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -2137,7 +2137,7 @@ if i32.const 320 i32.const 376 - i32.const 110 + i32.const 109 i32.const 21 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index 5ea002362f..e1174547db 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -5815,7 +5815,7 @@ if i32.const 9840 i32.const 11000 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -6100,7 +6100,7 @@ if i32.const 240 i32.const 11000 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -6120,7 +6120,7 @@ call $~lib/rt/pure/__release i32.const 11048 i32.const 11000 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/string.untouched.wat b/tests/compiler/std/string.untouched.wat index a811789f64..da82ce61c9 100644 --- a/tests/compiler/std/string.untouched.wat +++ b/tests/compiler/std/string.untouched.wat @@ -8746,7 +8746,7 @@ if i32.const 9840 i32.const 11000 - i32.const 15 + i32.const 14 i32.const 47 call $~lib/builtins/abort unreachable @@ -9153,7 +9153,7 @@ if i32.const 240 i32.const 11000 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -9169,7 +9169,7 @@ call $~lib/rt/pure/__release i32.const 11048 i32.const 11000 - i32.const 98 + i32.const 97 i32.const 39 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index c0cca2db27..9c5de995df 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -684,7 +684,7 @@ if i32.const 200 i32.const 256 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -1239,7 +1239,7 @@ if i32.const 200 i32.const 256 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index 30d2887e1d..eb1d1ac143 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -997,7 +997,7 @@ call $~lib/rt/stub/__release i32.const 200 i32.const 256 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable @@ -1750,7 +1750,7 @@ if i32.const 200 i32.const 256 - i32.const 111 + i32.const 179 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index dc963cce3a..b31290d17a 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -3629,7 +3629,7 @@ if i32.const 280 i32.const 512 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -3848,7 +3848,7 @@ if i32.const 280 i32.const 512 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/typedarray.untouched.wat b/tests/compiler/std/typedarray.untouched.wat index fc1d2f9229..319bdeda1a 100644 --- a/tests/compiler/std/typedarray.untouched.wat +++ b/tests/compiler/std/typedarray.untouched.wat @@ -5559,7 +5559,7 @@ if i32.const 280 i32.const 512 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable @@ -5867,7 +5867,7 @@ if i32.const 280 i32.const 512 - i32.const 94 + i32.const 93 i32.const 41 call $~lib/builtins/abort unreachable From 99721dba18d678591fe617bada5c7e746a8db203 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 6 Dec 2019 16:55:58 -0500 Subject: [PATCH 26/47] Added inheritance --- src/compiler.ts | 27 +- src/program.ts | 26 +- src/resolver.ts | 2 +- tests/compiler/interface-fail.ts | 2 +- tests/compiler/interface-inherit-bad.json | 16 + .../interface-inherit-bad.optimized.wat | 90 ++++ tests/compiler/interface-inherit-bad.ts | 29 ++ .../interface-inherit-bad.untouched.wat | 0 .../{iterator.json => interface-inherit.json} | 0 .../compiler/interface-inherit.optimized.wat | 265 ++++++++++ tests/compiler/interface-inherit.ts | 28 + .../compiler/interface-inherit.untouched.wat | 480 ++++++++++++++++++ tests/compiler/std/iterator.optimized.wat | 20 +- tests/compiler/std/iterator.ts | 16 +- tests/compiler/std/iterator.untouched.wat | 26 +- 15 files changed, 976 insertions(+), 51 deletions(-) create mode 100644 tests/compiler/interface-inherit-bad.json create mode 100644 tests/compiler/interface-inherit-bad.optimized.wat create mode 100644 tests/compiler/interface-inherit-bad.ts create mode 100644 tests/compiler/interface-inherit-bad.untouched.wat rename tests/compiler/{iterator.json => interface-inherit.json} (100%) create mode 100644 tests/compiler/interface-inherit.optimized.wat create mode 100644 tests/compiler/interface-inherit.ts create mode 100644 tests/compiler/interface-inherit.untouched.wat diff --git a/src/compiler.ts b/src/compiler.ts index fb909d0f3a..ba620488b0 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9167,15 +9167,15 @@ export class Compiler extends DiagnosticEmitter { const _class = fromType.classReference!; var imems: Map; var mems: Map | null; - if (_interface.prototype.instanceMembers == null) { + if (_interface.members == null) { return true; } - imems = _interface.prototype.instanceMembers; - mems = _class.prototype.instanceMembers; + imems = _interface.members; + mems = _class.members; var error = false; var incorrectMember = false; - for (const [name, imem] of imems.entries()) { + for (let [name, imem] of imems.entries()) { error = error || incorrectMember; incorrectMember = true; if (mems == null || mems.get(name) == null) { @@ -9192,8 +9192,8 @@ export class Compiler extends DiagnosticEmitter { let mem = mems.get(name)!; if (imem.kind != mem.kind) { // Interfaces can't have properties - if ((mem.kind != ElementKind.PROPERTY_PROTOTYPE && mem.kind != ElementKind.FIELD_PROTOTYPE) && - (imem.kind == ElementKind.PROPERTY)) { + if ((mem.kind != ElementKind.PROPERTY_PROTOTYPE && mem.kind != ElementKind.FIELD_PROTOTYPE && mem.kind != ElementKind.FIELD && + imem.kind == ElementKind.PROPERTY)) { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, (mem).declaration.range, @@ -9205,11 +9205,19 @@ export class Compiler extends DiagnosticEmitter { } let from: Type = Type.void, to: Type = Type.void; switch (mem.kind) { + case ElementKind.FIELD: { + mem = (mem).prototype; + imem = (imem).prototype; + } case ElementKind.FIELD_PROTOTYPE: { from = this.resolver.resolveType((mem).typeNode!, _class)!; to = this.resolver.resolveType((imem).getterPrototype!.functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!.signatureReference!.returnType; break; } + case ElementKind.FUNCTION: { + mem = (mem).prototype; + imem = (mem).prototype; + } case ElementKind.FUNCTION_PROTOTYPE: { let func = (mem); mem.parent = _class; @@ -9218,6 +9226,10 @@ export class Compiler extends DiagnosticEmitter { to = this.resolver.resolveType((imem).functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!; break; } + case ElementKind.PROPERTY: { + mem = (mem).prototype; + imem = (imem).prototype; + } case ElementKind.PROPERTY_PROTOTYPE: { const property = mem; const iproperty = imem; @@ -9283,6 +9295,9 @@ export class Compiler extends DiagnosticEmitter { const interfaces = this.program.interfaces; for (let i: i32 = 0; i < interfaces.length; i++) { const _interface = interfaces[i]; + if (_interface.implementers.size == 0) { + continue; + } this.compileInterfaceProperties(_interface); this.compileInterfacePropertiesSetters(_interface); this.compileInterfaceMethods(_interface); diff --git a/src/program.ts b/src/program.ts index 8eac99041b..b0d4303d98 100644 --- a/src/program.ts +++ b/src/program.ts @@ -761,7 +761,7 @@ export class Program extends DiagnosticEmitter { break; } case NodeKind.INTERFACEDECLARATION: { - this.initializeInterface(statement, file); + this.initializeInterface(statement, file, queuedExtends); break; } case NodeKind.NAMESPACEDECLARATION: { @@ -922,7 +922,7 @@ export class Program extends DiagnosticEmitter { let extendsNode = assert(thisPrototype.extendsNode); // must be present if in queuedExtends let baseElement = resolver.resolveTypeName(extendsNode.name, thisPrototype.parent); // reports if (!baseElement) continue; - if (baseElement.kind == ElementKind.CLASS_PROTOTYPE) { + if (baseElement.kind == ElementKind.CLASS_PROTOTYPE || baseElement.kind == ElementKind.INTERFACE_PROTOTYPE) { let basePrototype = baseElement; if (basePrototype.hasDecorator(DecoratorFlags.SEALED)) { this.error( @@ -1699,7 +1699,7 @@ export class Program extends DiagnosticEmitter { break; } case NodeKind.INTERFACEDECLARATION: { - element = this.initializeInterface(declaration, parent); + element = this.initializeInterface(declaration, parent, queuedExtends); break; } case NodeKind.NAMESPACEDECLARATION: { @@ -1830,7 +1830,9 @@ export class Program extends DiagnosticEmitter { /** The declaration to initialize. */ declaration: InterfaceDeclaration, /** Parent element, usually a file or namespace. */ - parent: Element + parent: Element, + /** So far queued `extends` clauses. */ + queuedExtends: ClassPrototype[], ): InterfacePrototype | null { var name = declaration.name.text; var element = new InterfacePrototype( @@ -1843,6 +1845,7 @@ export class Program extends DiagnosticEmitter { ); if (!parent.add(name, element)) return null; var memberDeclarations = declaration.members; + if (declaration.extendsType) queuedExtends.push(element); var instanceDeclarations = new Array(); /** * Must convert field declarations to property declarations @@ -1922,7 +1925,7 @@ export class Program extends DiagnosticEmitter { break; } case NodeKind.INTERFACEDECLARATION: { - this.initializeInterface(member, original); + this.initializeInterface(member, original, queuedExtends); break; } case NodeKind.NAMESPACEDECLARATION: { @@ -3731,16 +3734,15 @@ export class Interface extends Class { // FIXME } get methodInstances(): Function[] { - var funcs: Function[] = []; + var funcs: Set = new Set(); for (let func of this.methods) { - if (func.instances == null) continue; - map(func.instances.values(), (func: Function): void => { - if (funcs.findIndex((f: Function): bool => f.signature.id == func.signature.id) < 0) { - funcs.push(func); + if (func.instances) { + for (let i of func.instances.values()){ + funcs.add(i); } - }); + } } - return funcs; + return Array.from(funcs); } addImplementer(_class: Class): void { diff --git a/src/resolver.ts b/src/resolver.ts index 43f4a7eb8e..638c5646c3 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -1388,7 +1388,7 @@ export class Resolver extends DiagnosticEmitter { return members.get(propertyName)!; // instance FIELD, static GLOBAL, FUNCTION_PROTOTYPE... } // traverse inherited static members on the base prototype if target is a class prototype - if (target.kind == ElementKind.CLASS_PROTOTYPE) { + if (target.kind == ElementKind.CLASS_PROTOTYPE || target.kind == ElementKind.INTERFACE_PROTOTYPE) { if ((target).basePrototype) { target = (target).basePrototype; } else { diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index db8969e1f4..e09a1f5e32 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -47,7 +47,7 @@ class BadProps implements Properties { const badProp = new BadProps(); -const val = badProp.val; +const badVal = badProp.val; function badFunc(prop: Properties): void { const val = prop.val; } diff --git a/tests/compiler/interface-inherit-bad.json b/tests/compiler/interface-inherit-bad.json new file mode 100644 index 0000000000..075a2ee841 --- /dev/null +++ b/tests/compiler/interface-inherit-bad.json @@ -0,0 +1,16 @@ +{ + "asc_flags": [ + "--runtime none" + ], + "stderr": [ + "TS2741: Property 'a' is missing in type 'BadAC' but required in type 'BadIC'.", + "class BadAC implements IC {", + + "TS2420: Class 'interface-inherit-bad/BadAC' incorrectly implements interface 'interface-inherit-bad/BadIC'.", + "class BadAC implements IC {", + + "TS2322: Type 'interface-inherit-bad/BadAC' is not assignable to type 'interface-inherit-bad/BadIC'.", + + "testbadIC(badac);" + ] +} \ No newline at end of file diff --git a/tests/compiler/interface-inherit-bad.optimized.wat b/tests/compiler/interface-inherit-bad.optimized.wat new file mode 100644 index 0000000000..ca1d43de06 --- /dev/null +++ b/tests/compiler/interface-inherit-bad.optimized.wat @@ -0,0 +1,90 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$v (func)) + (memory $0 0) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-inherit-bad/badac (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 0 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 1 ;) (result i32) + (local $0 i32) + (local $1 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const -1 + i32.store offset=4 + local.get $0 + i32.const 3 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $1 + ) + (func $start (; 2 ;) (type $FUNCSIG$v) + i32.const 16 + global.set $~lib/rt/stub/startOffset + i32.const 16 + global.set $~lib/rt/stub/offset + call $~lib/rt/stub/__alloc + global.set $interface-inherit-bad/badac + ) + (func $null (; 3 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/interface-inherit-bad.ts b/tests/compiler/interface-inherit-bad.ts new file mode 100644 index 0000000000..583e5aa557 --- /dev/null +++ b/tests/compiler/interface-inherit-bad.ts @@ -0,0 +1,29 @@ + +interface BadIA { + a(): i32; +} + +interface BadIB extends BadIA { + b(): string; +} + +interface BadIC extends BadIB { + c(): bool; +} +//@ts-ignore + +class BadAC implements IC { + b(): string { return "hello world"; } + c(): bool { return true; } +} + +let badac = new BadAC(); + +function testbadIC(ic: BadIC): void { + assert(ic.a() == 42); + assert(ic.b() == "hello world"); + assert(ic.c()); +} +//@ts-ignore + +testbadIC(badac); \ No newline at end of file diff --git a/tests/compiler/interface-inherit-bad.untouched.wat b/tests/compiler/interface-inherit-bad.untouched.wat new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/compiler/iterator.json b/tests/compiler/interface-inherit.json similarity index 100% rename from tests/compiler/iterator.json rename to tests/compiler/interface-inherit.json diff --git a/tests/compiler/interface-inherit.optimized.wat b/tests/compiler/interface-inherit.optimized.wat new file mode 100644 index 0000000000..23b11a8e4e --- /dev/null +++ b/tests/compiler/interface-inherit.optimized.wat @@ -0,0 +1,265 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00i\00n\00h\00e\00r\00i\00t\00.\00t\00s") + (data (i32.const 64) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d") + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-inherit/ac (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (result i32) + (local $0 i32) + (local $1 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const -1 + i32.store offset=4 + local.get $0 + i32.const 3 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $1 + ) + (func $~lib/string/String#get:length (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 4 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 7 + i32.and + local.get $1 + i32.const 7 + i32.and + i32.or + i32.eqz + i32.const 0 + local.get $2 + i32.const 4 + i32.ge_u + select + if + loop $continue|0 + local.get $0 + i64.load + local.get $1 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + local.get $2 + i32.const 4 + i32.sub + local.tee $2 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + loop $continue|1 + block $break|1 + local.get $2 + local.tee $3 + i32.const 1 + i32.sub + local.set $2 + local.get $3 + i32.eqz + br_if $break|1 + local.get $1 + i32.load16_u + local.tee $3 + local.get $0 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $4 + local.get $3 + i32.sub + return + else + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + br $continue|1 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/string/String.__eq (; 5 ;) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 80 + i32.eq + if + i32.const 1 + return + end + block $folding-inner0 + i32.const 0 + i32.const 1 + local.get $0 + select + br_if $folding-inner0 + local.get $0 + call $~lib/string/String#get:length + local.tee $1 + i32.const 80 + call $~lib/string/String#get:length + i32.ne + br_if $folding-inner0 + local.get $0 + i32.const 80 + local.get $1 + call $~lib/util/string/compareImpl + i32.eqz + return + end + i32.const 0 + ) + (func $interface-inherit/testIC (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.ne + if + unreachable + end + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.ne + if + unreachable + end + i32.const 80 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 24 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.ne + if + unreachable + end + ) + (func $start (; 7 ;) (type $FUNCSIG$v) + i32.const 112 + global.set $~lib/rt/stub/startOffset + i32.const 112 + global.set $~lib/rt/stub/offset + call $~lib/rt/stub/__alloc + global.set $interface-inherit/ac + global.get $interface-inherit/ac + call $interface-inherit/testIC + ) + (func $interface-inherit/AC#a (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $interface-inherit/AC#b (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 80 + ) + (func $interface-inherit/AC#c (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $null (; 11 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/interface-inherit.ts b/tests/compiler/interface-inherit.ts new file mode 100644 index 0000000000..c990fc7f39 --- /dev/null +++ b/tests/compiler/interface-inherit.ts @@ -0,0 +1,28 @@ + +interface IA { + a(): i32; +} + +interface IB extends IA { + b(): string; +} + +interface IC extends IB { + c(): bool; +} + +class AC implements IC { + a(): i32 { return 42; } + b(): string { return "hello world"; } + c(): bool { return true; } +} + +let ac = new AC(); + +function testIC(ic: IC): void { + assert(ic.a() == 42); + assert(ic.b() == "hello world"); + assert(ic.c()); +} + +testIC(ac); \ No newline at end of file diff --git a/tests/compiler/interface-inherit.untouched.wat b/tests/compiler/interface-inherit.untouched.wat new file mode 100644 index 0000000000..68a99a8cd5 --- /dev/null +++ b/tests/compiler/interface-inherit.untouched.wat @@ -0,0 +1,480 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00i\00n\00h\00e\00r\00i\00t\00.\00t\00s\00") + (data (i32.const 64) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d\00") + (table $0 4 funcref) + (elem (i32.const 0) $null $interface-inherit/AC#a $interface-inherit/AC#b $interface-inherit/AC#c) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-inherit/ac (mut i32) (i32.const 0)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 104)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $interface-inherit/AC#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + ) + (func $~lib/rt/stub/__release (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $~lib/string/String#get:length (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 7 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $break|0 + loop $continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + i32.eqz + br_if $break|1 + local.get $5 + i32.load16_u + local.set $7 + local.get $6 + i32.load16_u + local.set $8 + local.get $7 + local.get $8 + i32.ne + if + local.get $7 + local.get $8 + i32.sub + local.set $9 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $9 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $continue|1 + end + unreachable + end + i32.const 0 + local.set $8 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $8 + ) + (func $~lib/string/String.__eq (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $interface-inherit/testIC (; 9 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $interface-inherit/IC#a + i32.const 42 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 23 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $interface-inherit/IC#b + local.tee $1 + i32.const 80 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 24 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $interface-inherit/IC#c + i32.const 0 + i32.ne + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 25 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:interface-inherit (; 10 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $interface-inherit/AC#constructor + global.set $interface-inherit/ac + global.get $interface-inherit/ac + call $interface-inherit/testIC + ) + (func $start (; 11 ;) (type $FUNCSIG$v) + call $start:interface-inherit + ) + (func $interface-inherit/AC#a (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $interface-inherit/IC#a (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-inherit/AC#a + else + unreachable + end + ) + (func $interface-inherit/AC#b (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 80 + call $~lib/rt/stub/__retain + ) + (func $interface-inherit/IC#b (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-inherit/AC#b + else + unreachable + end + ) + (func $interface-inherit/AC#c (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface-inherit/IC#c (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-inherit/AC#c + else + unreachable + end + ) + (func $null (; 18 ;) (type $FUNCSIG$v) + ) +) diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat index 154d060e65..b98ac5d66d 100644 --- a/tests/compiler/std/iterator.optimized.wat +++ b/tests/compiler/std/iterator.optimized.wat @@ -24,8 +24,8 @@ (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $std/iterator/iter (mut i32) (i32.const 0)) - (global $std/iterator/res (mut i32) (i32.const 0)) - (global $std/iterator/i (mut i32) (i32.const 0)) + (global $std/iterator/iterres (mut i32) (i32.const 0)) + (global $std/iterator/arri (mut i32) (i32.const 0)) (global $std/iterator/arr2 (mut i32) (i32.const 0)) (global $std/iterator/map (mut i32) (i32.const 0)) (global $std/iterator/entries (mut i32) (i32.const 0)) @@ -1391,20 +1391,20 @@ global.set $std/iterator/iter global.get $std/iterator/iter call $~lib/iterator/Iterator#next - global.set $std/iterator/res + global.set $std/iterator/iterres loop $continue|0 - global.get $std/iterator/res + global.get $std/iterator/iterres call $~lib/iterator/IteratorResult#get:done i32.eqz if - global.get $std/iterator/res + global.get $std/iterator/iterres call $~lib/iterator/IteratorResult#get:value local.set $0 - global.get $std/iterator/i + global.get $std/iterator/arri local.tee $1 i32.const 1 i32.add - global.set $std/iterator/i + global.set $std/iterator/arri i32.const 56 local.get $1 call $~lib/array/Array#__get @@ -1420,7 +1420,7 @@ else global.get $std/iterator/iter call $~lib/iterator/Iterator#next - global.set $std/iterator/res + global.set $std/iterator/iterres br $continue|0 end unreachable @@ -1430,8 +1430,8 @@ call $std/iterator/IterableArray#get:iterator call $~lib/array/Array.from global.set $std/iterator/arr2 - i32.const 68 - i32.load + global.get $std/iterator/arr2 + i32.load offset=12 i32.const 3 i32.ne if diff --git a/tests/compiler/std/iterator.ts b/tests/compiler/std/iterator.ts index 3149d58fb1..4d6459ce48 100644 --- a/tests/compiler/std/iterator.ts +++ b/tests/compiler/std/iterator.ts @@ -30,22 +30,22 @@ class IterableArray extends Array implements Iterable { } -let arr: Array = [1,3,5]; -let iterableArr = > arr; +let arri32: Array = [1,3,5]; +let iterableArr = > arri32; let iter = iterableArr.iterator; -let res = iter.next(); -let i: i32 = 0; -while (!res.done){ - assert(res.value == arr[i++]); - res = iter.next() +let iterres = iter.next(); +let arri: i32 = 0; +while (!iterres.done){ + assert(iterres.value == arri32[arri++]); + iterres = iter.next() } let arr2: Array = Array.from(iterableArr.iterator); // assert (arr2 != null); -assert(arr.length == 3); +assert(arr2.length == 3); assert(arr2[0]== 1) assert(arr2[1]== 3) diff --git a/tests/compiler/std/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat index 56eb33f4f3..9f43f144c3 100644 --- a/tests/compiler/std/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -23,13 +23,13 @@ (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d\00") (table $0 11 funcref) (elem (i32.const 0) $null $std/iterator/ArrayIterator#constructor $std/iterator/IterableArray#get:iterator $~lib/map/EntriesIter<~lib/string/String,i32>#constructor $~lib/map/EntriesIter<~lib/string/String,i32>#get:done $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry $~lib/map/EntriesIter<~lib/string/String,i32>#next $std/iterator/ArrayIterator#next $std/iterator/ArrayIterator#get:done $std/iterator/ArrayIterator#get:value $~lib/map/EntriesIter<~lib/string/String,i32>#get:value) - (global $std/iterator/arr (mut i32) (i32.const 56)) + (global $std/iterator/arri32 (mut i32) (i32.const 56)) (global $std/iterator/iterableArr (mut i32) (i32.const 0)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $std/iterator/iter (mut i32) (i32.const 0)) - (global $std/iterator/res (mut i32) (i32.const 0)) - (global $std/iterator/i (mut i32) (i32.const 0)) + (global $std/iterator/iterres (mut i32) (i32.const 0)) + (global $std/iterator/arri (mut i32) (i32.const 0)) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $std/iterator/arr2 (mut i32) (i32.const 0)) (global $std/iterator/map (mut i32) (i32.const 0)) @@ -2956,7 +2956,7 @@ (local $0 i32) (local $1 i32) (local $2 i32) - global.get $std/iterator/arr + global.get $std/iterator/arri32 call $~lib/rt/stub/__retain global.set $std/iterator/iterableArr global.get $~lib/heap/__heap_base @@ -2976,22 +2976,22 @@ global.set $std/iterator/iter global.get $std/iterator/iter call $~lib/iterator/Iterator#next - global.set $std/iterator/res + global.set $std/iterator/iterres block $break|0 loop $continue|0 - global.get $std/iterator/res + global.get $std/iterator/iterres call $~lib/iterator/IteratorResult#get:done i32.eqz i32.eqz br_if $break|0 - global.get $std/iterator/res + global.get $std/iterator/iterres call $~lib/iterator/IteratorResult#get:value - global.get $std/iterator/arr - global.get $std/iterator/i + global.get $std/iterator/arri32 + global.get $std/iterator/arri local.tee $0 i32.const 1 i32.add - global.set $std/iterator/i + global.set $std/iterator/arri local.get $0 call $~lib/array/Array#__get i32.eq @@ -3007,10 +3007,10 @@ global.get $std/iterator/iter call $~lib/iterator/Iterator#next local.set $0 - global.get $std/iterator/res + global.get $std/iterator/iterres call $~lib/rt/stub/__release local.get $0 - global.set $std/iterator/res + global.set $std/iterator/iterres br $continue|0 end unreachable @@ -3020,7 +3020,7 @@ local.tee $0 call $~lib/array/Array.from global.set $std/iterator/arr2 - global.get $std/iterator/arr + global.get $std/iterator/arr2 call $~lib/array/Array#get:length i32.const 3 i32.eq From 3c813b366eb78850c90adbf661845cf9dc50e4fb Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 8 Dec 2019 15:37:59 -0500 Subject: [PATCH 27/47] Simplified and improved Inheritance --- src/compiler.ts | 241 ++++++------------ src/program.ts | 4 + .../compiler/interface-generic.optimized.wat | 70 ++--- .../compiler/interface-generic.untouched.wat | 72 +++--- .../compiler/interface-inherit.optimized.wat | 93 +++++-- tests/compiler/interface-inherit.ts | 37 ++- .../compiler/interface-inherit.untouched.wat | 123 +++++++-- tests/compiler/interface.optimized.wat | 105 +++----- tests/compiler/interface.ts | 4 +- tests/compiler/interface.untouched.wat | 123 ++++----- tests/compiler/std/iterator.optimized.wat | 86 +++---- tests/compiler/std/iterator.untouched.wat | 111 +++----- 12 files changed, 521 insertions(+), 548 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index ba620488b0..d9c9f80c88 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -186,7 +186,8 @@ import { writeI64, writeF32, writeF64, - makeMap + makeMap, + addAll } from "./util"; /** Compiler options. */ @@ -319,6 +320,8 @@ export class Compiler extends DiagnosticEmitter { events: Map = new Map(); /** Classes that implement an interface */ implementers: Class[] = []; + /** Interface methods that need to be compiled */ + interfaceMethods: Set = new Set(); /** Compiles a {@link Program} to a {@link Module} using the specified options. */ static compile(program: Program, options: Options | null = null): Module { @@ -1362,6 +1365,7 @@ export class Compiler extends DiagnosticEmitter { null, module.nop() ); + this.interfaceMethods.add(instance); // imported function } else { if (!instance.is(CommonFlags.AMBIENT)) { @@ -1382,9 +1386,6 @@ export class Compiler extends DiagnosticEmitter { ); } funcRef = module.getFunction(instance.internalName); - if (instance.prototype.isBound && (instance.parent).prototype.implementsNodes) { - this.ensureFunctionTableEntry(instance); - } instance.finalize(module, funcRef); this.currentType = previousType; @@ -3052,7 +3053,7 @@ export class Compiler extends DiagnosticEmitter { toType.toString()); } else { if (this.checkInterfaceImplementation(toType, fromType, reportNode)) { - (toType.classReference).implementers.add(fromType.classReference); + (toType.classReference).addImplementer(fromType.classReference); } else { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, @@ -9220,10 +9221,8 @@ export class Compiler extends DiagnosticEmitter { } case ElementKind.FUNCTION_PROTOTYPE: { let func = (mem); - mem.parent = _class; - imem.parent = _interface; - from = this.resolver.resolveType(func.functionTypeNode, func, _class.contextualTypeArguments)!;//, ReportMode.REPORT, false)!.type; - to = this.resolver.resolveType((imem).functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!; + from = this.resolver.resolveType(func.functionTypeNode, func, _class.contextualTypeArguments)!; + to = this.resolver.resolveType((imem).functionTypeNode, imem, _interface.contextualTypeArguments)!; break; } case ElementKind.PROPERTY: { @@ -9292,180 +9291,110 @@ export class Compiler extends DiagnosticEmitter { } compileInterfaces(): void { - const interfaces = this.program.interfaces; - for (let i: i32 = 0; i < interfaces.length; i++) { - const _interface = interfaces[i]; - if (_interface.implementers.size == 0) { - continue; - } - this.compileInterfaceProperties(_interface); - this.compileInterfacePropertiesSetters(_interface); - this.compileInterfaceMethods(_interface); - } - } - - compileInterfaceMethods(_interface: Interface): void { const module = this.module; - const ifuncs = _interface.methodInstances; - const classes = Array.from(_interface.implementers); - - for (let i = 0; i < ifuncs.length; i++) { - const ifunc = ifuncs[i]; - const classIDLocal = ifunc.addLocal(Type.i32); - const returnType = ifunc!.signature.returnType.toNativeType(); + for (let ifunc of this.interfaceMethods) { + let classes = (ifunc.parent).implementers; + const classIDLocal = ifunc.localsByIndex.length const typeRef = this.ensureSignature(ifunc!.signature); - const relooper = this.module.createRelooper(); // Condition to switch on - const first = relooper.addBlock(module.local_set(classIDLocal.index, loadClassID(module))); + const first = relooper.addBlock(module.local_set(classIDLocal, loadClassID(module))); const last = relooper.addBlock(module.unreachable()); relooper.addBranch(first, last); - for (let c = 0; c < classes.length; c ++) { - const _class = classes[c]; - let prop = _class.members!.get(ifunc.name)!; - switch (prop.kind){ - case ElementKind.FUNCTION_PROTOTYPE: { - let p = prop; - let newFunc = this.resolver.resolveFunction(p, null, ifunc.contextualTypeArguments); - if (newFunc == null) { - throw new Error(`Couldn't resolve ${p.name}`); - } - prop = newFunc; - } - case ElementKind.FUNCTION:{ - this.compileFunction( prop); - break - } - default: - throw Error("Class " + classes[c].name + " must have property " + prop.name); - } - const locals: usize[] = []; - for (let i: i32 = 0; i < classIDLocal.index; i++) { - const local = ifunc.localsByIndex[i]; - locals.push(module.local_get(local.index, local.type.toNativeType())); - } - const callExpr = module.call(prop.internalName, locals, returnType) - const returnBlock = relooper.addBlock(callExpr); - const loadLocal = loadClassArg(module, classIDLocal.index); + for (let _class of classes) { + const expr = this.compileInterfaceMethod(ifunc, _class, classIDLocal); + const returnBlock = relooper.addBlock(expr); + const loadLocal = loadClassArg(module, classIDLocal); const classID = module.i32(_class.id); relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); } // Remove the nop standin module.removeFunction(ifunc.internalName); - module.addFunction(ifunc.internalName, typeRef, [NativeType.I32], relooper.renderAndDispose(first, 0)); + module.addFunction(ifunc.internalName, typeRef, [this.nativeUsizeType], relooper.renderAndDispose(first, 0)); } } - compileInterfaceProperties(_interface: Interface): void { + compileInterfaceMethod(ifunc: Function, _class: Class, classIDLocal: i32): ExpressionRef { const module = this.module; - const iprops = _interface.getters; - const classes = Array.from(_interface.implementers); - - for (let i = 0; i < iprops.length; i++) { - const iprop = iprops[i]; - const returnType = iprop.getterInstance!.signature.returnType.toNativeType(); - const typeRef = this.ensureSignature(iprop.getterInstance!.signature); - - const relooper = this.module.createRelooper(); - - // Condition to switch on - const first = relooper.addBlock(module.local_set(1, loadClassID(module))); - const last = relooper.addBlock(module.unreachable()); - relooper.addBranch(first, last); - for (let c = 0; c < classes.length; c ++) { - const _class = classes[c]; - const prop = _class.members!.get(iprop.name)!; - let expr: ExpressionRef; - let thisExpr = loadClassArg(module, 0); - if (prop.kind == ElementKind.PROPERTY) { - let p = prop; - let getter = p.getterInstance!; - this.compileFunction(getter); - expr = module.call(getter.internalName, [thisExpr], getter.signature.returnType.toNativeType()); - }else if(prop.kind == ElementKind.FIELD) { - let target = prop; - assert((target).memoryOffset >= 0); - this.currentType = (target).type; - expr = module.load( - (target).type.byteSize, - (target).type.is(TypeFlags.SIGNED | TypeFlags.INTEGER), - thisExpr, - (target).type.toNativeType(), - (target).memoryOffset) - } else { - throw Error("Class " + classes[c].name + " must have property " + prop.name); + let name: string = ifunc.name; + if (ifunc.isAny(CommonFlags.GET | CommonFlags.SET)){ + name = name.substr("get:".length); + } + let prop = _class.members!.get(name)!; + let method: Function; + + const returnType = ifunc!.signature.returnType.toNativeType(); + switch (prop.kind){ + case ElementKind.FUNCTION_PROTOTYPE: { + let p = prop; + let newFunc = this.resolver.resolveFunction(p, null, (p.parent).contextualTypeArguments); + if (newFunc == null) { + throw new Error(`Couldn't resolve ${p.name}`); } - const returnBlock = relooper.addBlock(expr); - const loadLocal = loadClassArg(module, 1); - const classID = module.i32(_class.id); - relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); + prop = newFunc; } - // Remove the nop standin - module.removeFunction(iprop.getterInstance!.internalName); - module.addFunction(iprop.getterInstance!.internalName, typeRef, [this.nativeUsizeType], relooper.renderAndDispose(first, 0)); - } - } - - compileInterfacePropertiesSetters(_interface: Interface): void { - const module = this.module; - const iprops = _interface.setters; - const classes = Array.from(_interface.implementers); - - for (let i = 0; i < iprops.length; i++) { - const iprop = iprops[i]; - const relooper = this.module.createRelooper(); - const setter = iprop.setterInstance!; - const classIDIndex = setter.localsByIndex.length; - const typeRef = this.ensureSignature(setter.signature); - - // Condition to switch on - const first = relooper.addBlock(module.local_set(classIDIndex, loadClassID(module))); - const last = relooper.addBlock(module.unreachable()); - relooper.addBranch(first, last); - - for (let c = 0; c < classes.length; c++) { - let _class = classes[c]; - const prop = _class.members!.get(iprop.name)!; - let expr: ExpressionRef; - let thisExpr = this.loadClassArg(0); - if (prop.kind == ElementKind.PROPERTY) { - let p = prop; - let setter = p.setterInstance!; - this.compileFunction(setter); - expr = module.call(setter.internalName, - [thisExpr, this.module.local_get(1, p.type.toNativeType())], - setter.signature.returnType.toNativeType()); - }else if(prop.kind == ElementKind.FIELD) { - let field = prop; - var type = field.type; - var nativeType = type.toNativeType(); - var usizeType = this.options.usizeType; - var nativeSizeType = usizeType.toNativeType(); + case ElementKind.FUNCTION:{ + method = prop; + break; + } + case ElementKind.FIELD: { + let field = prop; + var type = field.type; + var nativeType = type.toNativeType(); + const thisExpr = module.local_get(0, this.nativeUsizeType); + if (ifunc.is(CommonFlags.SET)){ + assert(ifunc.signature.parameterTypes.length == 1); + if (ifunc.signature.parameterTypes[0] != type){ + return module.nop(); + } var valueExpr = module.local_get(1, nativeType); - expr = module.store( + return module.store( type.byteSize, - module.local_get(0, nativeSizeType), + thisExpr, valueExpr, nativeType, field.memoryOffset - ) - } else { - throw Error("Class " + classes[c].name + " must have property " + prop.name); + ); + } + if (ifunc.is(CommonFlags.GET)){ + if (ifunc.signature.returnType != type){ + return module.nop(); + } + assert(field.memoryOffset >= 0); + return this.module.load( + field.type.byteSize, + field.type.is(TypeFlags.SIGNED | TypeFlags.INTEGER), + thisExpr, + field.type.toNativeType(), + field.memoryOffset) } - const returnBlock = relooper.addBlock(expr); - const loadLocal = this.loadClassArg(classIDIndex); - const classID = module.i32(_class.id); - relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); } - // Remove the nop standin - module.removeFunction(setter.internalName); - module.addFunction(setter.internalName, - typeRef, - [this.nativeUsizeType], - relooper.renderAndDispose(first, 0)); + case ElementKind.PROPERTY: { + let p = prop; + if (ifunc.is(CommonFlags.SET)){ + method = p.setterInstance!; + + }else if (ifunc.is(CommonFlags.GET)){ + method = p.getterInstance!; + }else { + throw Error("Interface method " + ifunc.name + " should be a property"); + } + break; + + } + default: + throw Error("Class " + _class.name + " must have property " + prop.name); + } + + this.compileFunction(method); + const locals: usize[] = []; + for (let i: i32 = 0; i < classIDLocal; i++) { + const local = ifunc.localsByIndex[i]; + locals.push(this.module.local_get(local.index, local.type.toNativeType())); } + return this.module.call(method.internalName, locals, returnType) } diff --git a/src/program.ts b/src/program.ts index b0d4303d98..320d3e6f38 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3747,6 +3747,10 @@ export class Interface extends Class { // FIXME addImplementer(_class: Class): void { this.implementers.add(_class); + if (this.base == null){ + return; + } + (this.base).addImplementer(_class); } checkClass(_class: Class): FunctionPrototype[] { diff --git a/tests/compiler/interface-generic.optimized.wat b/tests/compiler/interface-generic.optimized.wat index 54b4ad4df0..c2a2fa1245 100644 --- a/tests/compiler/interface-generic.optimized.wat +++ b/tests/compiler/interface-generic.optimized.wat @@ -3,7 +3,6 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) @@ -118,16 +117,19 @@ unreachable end local.get $0 - call $interface-generic/GFoo#faa - i32.const 4 + i32.const 8 + i32.sub + i32.load + local.tee $0 + i32.const 3 i32.ne if - i32.const 0 - i32.const 24 - i32.const 42 - i32.const 2 - call $~lib/builtins/abort - unreachable + local.get $0 + i32.const 4 + i32.ne + if + unreachable + end end ) (func $interface-generic/expectGX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) @@ -204,39 +206,13 @@ (func $start (; 6 ;) (type $FUNCSIG$v) call $start:interface-generic ) - (func $interface-generic/AGFoo#get:x (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 - ) - (func $interface-generic/GFoo#get:x (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $interface-generic/AGFoo#foo (; 7 ;) (param $0 i32) (result i32) local.get $0 - i32.const 8 - i32.sub i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) - i32.const 1 - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else - unreachable - end - end - ) - (func $interface-generic/AGFoo#foo (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 + i32.const 1 i32.add ) - (func $interface-generic/GFoo#foo (; 10 ;) (param $0 i32) (result i32) + (func $interface-generic/GFoo#foo (; 8 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -247,7 +223,6 @@ i32.eq if (result i32) local.get $0 - i32.const 1 call $interface-generic/AGFoo#foo else local.get $1 @@ -255,19 +230,13 @@ i32.eq if (result i32) local.get $0 - i32.const 1 call $interface-generic/AGFoo#foo else unreachable end end ) - (func $interface-generic/AGFoo#faa (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $interface-generic/GFoo#faa (; 12 ;) (param $0 i32) (result i32) + (func $interface-generic/GFoo#get:x (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -277,25 +246,20 @@ i32.const 3 i32.eq if (result i32) - local.get $0 i32.const 1 - i32.const 3 - call $interface-generic/AGFoo#faa else local.get $1 i32.const 4 i32.eq if (result i32) local.get $0 - i32.const 1 - i32.const 3 - call $interface-generic/AGFoo#faa + i32.load8_u offset=4 else unreachable end end ) - (func $null (; 13 ;) (type $FUNCSIG$v) + (func $null (; 10 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface-generic.untouched.wat b/tests/compiler/interface-generic.untouched.wat index 23acf7645c..9fd6822b9e 100644 --- a/tests/compiler/interface-generic.untouched.wat +++ b/tests/compiler/interface-generic.untouched.wat @@ -9,8 +9,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00g\00e\00n\00e\00r\00i\00c\00.\00t\00s\00") - (table $0 4 funcref) - (elem (i32.const 0) $null $interface-generic/AGFoo#get:x $interface-generic/AGFoo#foo $interface-generic/AGFoo#faa) + (table $0 1 funcref) + (elem (i32.const 0) $null) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface-generic/aGFoo (mut i32) (i32.const 0)) @@ -275,47 +275,19 @@ (func $start (; 10 ;) (type $FUNCSIG$v) call $start:interface-generic ) - (func $interface-generic/AGFoo#get:x (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 - ) - (func $interface-generic/GFoo#get:x (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface-generic/AGFoo#get:x - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else - unreachable - end - end - ) - (func $interface-generic/AGFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface-generic/AGFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface-generic/StructurallyImplementsGFoo#foo (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface-generic/StructurallyImplementsGFoo#foo (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load local.get $1 i32.add ) - (func $interface-generic/GFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface-generic/GFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 i32.const 8 @@ -342,17 +314,17 @@ end end ) - (func $interface-generic/AGFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface-generic/AGFoo#faa (; 14 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface-generic/StructurallyImplementsGFoo#faa (; 17 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface-generic/StructurallyImplementsGFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 local.get $2 i32.add ) - (func $interface-generic/GFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $interface-generic/GFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) local.get $0 i32.const 8 @@ -381,6 +353,34 @@ end end ) + (func $interface-generic/AGFoo#get:x (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 1 + ) + (func $interface-generic/GFoo#get:x (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-generic/AGFoo#get:x + else + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load8_u offset=4 + else + unreachable + end + end + ) (func $null (; 19 ;) (type $FUNCSIG$v) ) ) diff --git a/tests/compiler/interface-inherit.optimized.wat b/tests/compiler/interface-inherit.optimized.wat index 23b11a8e4e..7ceb425ac1 100644 --- a/tests/compiler/interface-inherit.optimized.wat +++ b/tests/compiler/interface-inherit.optimized.wat @@ -9,6 +9,7 @@ (data (i32.const 64) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d") (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-inherit/aa (mut i32) (i32.const 0)) (global $interface-inherit/ac (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) @@ -54,32 +55,32 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 2 ;) (result i32) - (local $0 i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) (local $1 i32) + (local $2 i32) global.get $~lib/rt/stub/offset i32.const 16 i32.add - local.tee $1 + local.tee $2 i32.const 16 i32.add call $~lib/rt/stub/maybeGrowMemory - local.get $1 + local.get $2 i32.const 16 i32.sub - local.tee $0 + local.tee $1 i32.const 16 i32.store - local.get $0 + local.get $1 i32.const -1 i32.store offset=4 + local.get $1 local.get $0 - i32.const 3 i32.store offset=8 - local.get $0 + local.get $1 i32.const 0 i32.store offset=12 - local.get $1 + local.get $2 ) (func $~lib/string/String#get:length (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -202,19 +203,22 @@ ) (func $interface-inherit/testIC (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 3 + call $interface-inherit/IA#a + i32.const 42 i32.ne if + i32.const 0 + i32.const 24 + i32.const 34 + i32.const 2 + call $~lib/builtins/abort unreachable end local.get $0 i32.const 8 i32.sub i32.load - i32.const 3 + i32.const 4 i32.ne if unreachable @@ -225,7 +229,7 @@ if i32.const 0 i32.const 24 - i32.const 24 + i32.const 35 i32.const 2 call $~lib/builtins/abort unreachable @@ -234,7 +238,7 @@ i32.const 8 i32.sub i32.load - i32.const 3 + i32.const 4 i32.ne if unreachable @@ -245,21 +249,60 @@ global.set $~lib/rt/stub/startOffset i32.const 112 global.set $~lib/rt/stub/offset + i32.const 3 + call $~lib/rt/stub/__alloc + global.set $interface-inherit/aa + i32.const 4 call $~lib/rt/stub/__alloc global.set $interface-inherit/ac global.get $interface-inherit/ac - call $interface-inherit/testIC - ) - (func $interface-inherit/AC#a (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + call $interface-inherit/IA#a i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 30 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + global.get $interface-inherit/ac + call $interface-inherit/testIC + global.get $interface-inherit/aa + call $interface-inherit/IA#a + i32.const 84 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end ) - (func $interface-inherit/AC#b (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 80 - ) - (func $interface-inherit/AC#c (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 1 + (func $interface-inherit/IA#a (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.tee $0 + i32.const 4 + i32.eq + if (result i32) + i32.const 42 + else + local.get $0 + i32.const 3 + i32.ne + if + unreachable + end + i32.const 84 + end ) - (func $null (; 11 ;) (type $FUNCSIG$v) + (func $null (; 9 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface-inherit.ts b/tests/compiler/interface-inherit.ts index c990fc7f39..8b64d46c3b 100644 --- a/tests/compiler/interface-inherit.ts +++ b/tests/compiler/interface-inherit.ts @@ -11,6 +11,13 @@ interface IC extends IB { c(): bool; } +class AA { + a(): i32 { return 84; } +} + +let aa = new AA(); +// assert(aa.a() == 84); + class AC implements IC { a(): i32 { return 42; } b(): string { return "hello world"; } @@ -19,10 +26,38 @@ class AC implements IC { let ac = new AC(); +function testIA(ia: IA): void { + assert(ia.a() == 42); +} + function testIC(ic: IC): void { assert(ic.a() == 42); assert(ic.b() == "hello world"); assert(ic.c()); } +testIA(ac); +testIC(ac); + +function testGIC(gic: T): void { + assert(gic.a() == 84); +} + +testGIC(aa); + +// interface FromClass extends AA { +// d(): f32; +// } + +// class AFromClass { +// a(): i32 { return 84; } +// d(): f32 { return 3.14; } +// } +// let aFromClass = new AFromClass(); + +// testGIC(aFromClass); + +// function testFromClass(i: FromClass): void { +// assert(Math.abs(i.d() - 3.14) < 0.00001 ); +// } -testIC(ac); \ No newline at end of file +// testFromClass(aFromClass); \ No newline at end of file diff --git a/tests/compiler/interface-inherit.untouched.wat b/tests/compiler/interface-inherit.untouched.wat index 68a99a8cd5..15688c700c 100644 --- a/tests/compiler/interface-inherit.untouched.wat +++ b/tests/compiler/interface-inherit.untouched.wat @@ -9,10 +9,11 @@ (memory $0 1) (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00-\00i\00n\00h\00e\00r\00i\00t\00.\00t\00s\00") (data (i32.const 64) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d\00") - (table $0 4 funcref) - (elem (i32.const 0) $null $interface-inherit/AC#a $interface-inherit/AC#b $interface-inherit/AC#c) + (table $0 1 funcref) + (elem (i32.const 0) $null) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $interface-inherit/aa (mut i32) (i32.const 0)) (global $interface-inherit/ac (mut i32) (i32.const 0)) (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 104)) @@ -128,7 +129,7 @@ (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 ) - (func $interface-inherit/AC#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/AA#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.eqz if @@ -140,10 +141,42 @@ end local.get $0 ) - (func $~lib/rt/stub/__release (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface-inherit/AC#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $~lib/string/String#get:length (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/testIA (; 7 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $interface-inherit/IA#a + i32.const 42 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 30 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $~lib/string/String#get:length (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub @@ -151,7 +184,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/string/compareImpl (; 7 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (func $~lib/util/string/compareImpl (; 9 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) (local $5 i32) (local $6 i32) (local $7 i32) @@ -271,7 +304,7 @@ call $~lib/rt/stub/__release local.get $8 ) - (func $~lib/string/String.__eq (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -344,26 +377,26 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $interface-inherit/testIC (; 9 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $interface-inherit/testIC (; 11 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) local.get $0 call $~lib/rt/stub/__retain local.set $0 local.get $0 - call $interface-inherit/IC#a + call $interface-inherit/IA#a i32.const 42 i32.eq i32.eqz if i32.const 0 i32.const 24 - i32.const 23 + i32.const 34 i32.const 2 call $~lib/builtins/abort unreachable end local.get $0 - call $interface-inherit/IC#b + call $interface-inherit/IB#b local.tee $1 i32.const 80 call $~lib/string/String.__eq @@ -371,7 +404,7 @@ if i32.const 0 i32.const 24 - i32.const 24 + i32.const 35 i32.const 2 call $~lib/builtins/abort unreachable @@ -384,7 +417,7 @@ if i32.const 0 i32.const 24 - i32.const 25 + i32.const 36 i32.const 2 call $~lib/builtins/abort unreachable @@ -394,7 +427,27 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:interface-inherit (; 10 ;) (type $FUNCSIG$v) + (func $interface-inherit/testGIC (; 12 ;) (type $FUNCSIG$vi) (param $0 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $interface-inherit/IA#a + i32.const 84 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 42 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:interface-inherit (; 13 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -406,18 +459,28 @@ global.get $~lib/rt/stub/startOffset global.set $~lib/rt/stub/offset i32.const 0 + call $interface-inherit/AA#constructor + global.set $interface-inherit/aa + i32.const 0 call $interface-inherit/AC#constructor global.set $interface-inherit/ac global.get $interface-inherit/ac + call $interface-inherit/testIA + global.get $interface-inherit/ac call $interface-inherit/testIC + global.get $interface-inherit/aa + call $interface-inherit/testGIC ) - (func $start (; 11 ;) (type $FUNCSIG$v) + (func $start (; 14 ;) (type $FUNCSIG$v) call $start:interface-inherit ) - (func $interface-inherit/AC#a (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/AC#a (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 42 ) - (func $interface-inherit/IC#a (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/AA#a (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 84 + ) + (func $interface-inherit/IA#a (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -425,20 +488,28 @@ i32.load local.set $1 local.get $1 - i32.const 3 + i32.const 4 i32.eq if (result i32) local.get $0 call $interface-inherit/AC#a else - unreachable + local.get $1 + i32.const 3 + i32.eq + if (result i32) + local.get $0 + call $interface-inherit/AA#a + else + unreachable + end end ) - (func $interface-inherit/AC#b (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/AC#b (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 80 call $~lib/rt/stub/__retain ) - (func $interface-inherit/IC#b (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/IB#b (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -446,7 +517,7 @@ i32.load local.set $1 local.get $1 - i32.const 3 + i32.const 4 i32.eq if (result i32) local.get $0 @@ -455,10 +526,10 @@ unreachable end ) - (func $interface-inherit/AC#c (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/AC#c (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 1 ) - (func $interface-inherit/IC#c (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface-inherit/IC#c (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -466,7 +537,7 @@ i32.load local.set $1 local.get $1 - i32.const 3 + i32.const 4 i32.eq if (result i32) local.get $0 @@ -475,6 +546,6 @@ unreachable end ) - (func $null (; 18 ;) (type $FUNCSIG$v) + (func $null (; 22 ;) (type $FUNCSIG$v) ) ) diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 0d1da99f22..30419ce309 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -1,9 +1,7 @@ (module - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) @@ -100,23 +98,33 @@ unreachable end local.get $0 - call $interface/IFoo#faa - i32.const 4 + i32.const 8 + i32.sub + i32.load + local.tee $0 + i32.const 3 i32.ne if - i32.const 0 - i32.const 24 - i32.const 43 - i32.const 2 - call $~lib/builtins/abort - unreachable + local.get $0 + i32.const 4 + i32.ne + if + unreachable + end end ) - (func $interface/expectX (; 4 ;) (param $0 i32) + (func $interface/expectX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 + local.get $1 call $interface/IFoo#set:x local.get $0 call $interface/IFoo#get:x + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.ne if i32.const 0 i32.const 24 @@ -157,8 +165,10 @@ global.get $interface/sFoo call $interface/passAnInterface global.get $interface/aFoo + i32.const 0 call $interface/expectX global.get $interface/sFoo + i32.const 1 call $interface/expectX global.get $interface/aFoo global.set $interface/iFoo @@ -180,11 +190,13 @@ (func $start (; 6 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#get:x (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/AFoo#foo (; 7 ;) (param $0 i32) (result i32) local.get $0 - i32.load8_u offset=4 + i32.load + i32.const 1 + i32.add ) - (func $interface/IFoo#get:x (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/IFoo#foo (; 8 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -195,83 +207,46 @@ i32.eq if (result i32) local.get $0 - i32.load8_u offset=4 + call $interface/AFoo#foo else local.get $1 i32.const 4 i32.eq if (result i32) local.get $0 - i32.load8_u offset=4 + call $interface/AFoo#foo else unreachable end end ) - (func $interface/IFoo#set:x (; 9 ;) (param $0 i32) - (local $1 i32) + (func $interface/IFoo#set:x (; 9 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) local.get $0 i32.const 8 i32.sub i32.load - local.tee $1 + local.tee $2 i32.const 3 i32.eq if local.get $0 - i32.const 0 + local.get $1 i32.store8 offset=4 else - local.get $1 + local.get $2 i32.const 4 i32.eq if local.get $0 - i32.const 0 + local.get $1 i32.store8 offset=4 else unreachable end end ) - (func $interface/AFoo#foo (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add - ) - (func $interface/IFoo#foo (; 11 ;) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - i32.const 1 - call $interface/AFoo#foo - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.const 1 - call $interface/AFoo#foo - else - unreachable - end - end - ) - (func $interface/AFoo#faa (; 12 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $interface/IFoo#faa (; 13 ;) (param $0 i32) (result i32) + (func $interface/IFoo#get:x (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -282,24 +257,20 @@ i32.eq if (result i32) local.get $0 - i32.const 1 - i32.const 3 - call $interface/AFoo#faa + i32.load8_u offset=4 else local.get $1 i32.const 4 i32.eq if (result i32) local.get $0 - i32.const 1 - i32.const 3 - call $interface/AFoo#faa + i32.load8_u offset=4 else unreachable end end ) - (func $null (; 14 ;) (type $FUNCSIG$v) + (func $null (; 11 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index 3a2c1ce0eb..c337ded1e1 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -48,11 +48,11 @@ passAnInterface(sFoo); function expectX(foo: IFoo, x: bool): void { foo.x = x; - assert(!foo.x); + assert(foo.x == x); } expectX(aFoo, false); -expectX(sFoo, false); +expectX(sFoo, true); const iFoo = aFoo; const ibool = iFoo.x; diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index abddd03103..3df536152c 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -9,8 +9,8 @@ (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\18\00\00\00\01\00\00\00\01\00\00\00\18\00\00\00i\00n\00t\00e\00r\00f\00a\00c\00e\00.\00t\00s\00") - (table $0 5 funcref) - (elem (i32.const 0) $null $interface/AFoo#get:x $interface/AFoo#set:x $interface/AFoo#foo $interface/AFoo#faa) + (table $0 1 funcref) + (elem (i32.const 0) $null) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $interface/aFoo (mut i32) (i32.const 0)) @@ -214,7 +214,12 @@ call $interface/IFoo#set:x local.get $0 call $interface/IFoo#get:x - i32.eqz + i32.const 0 + i32.ne + local.get $1 + i32.const 0 + i32.ne + i32.eq i32.eqz if i32.const 0 @@ -252,7 +257,7 @@ i32.const 0 call $interface/expectX global.get $interface/sFoo - i32.const 0 + i32.const 1 call $interface/expectX global.get $interface/aFoo call $~lib/rt/stub/__retain @@ -277,80 +282,90 @@ (func $start (; 10 ;) (type $FUNCSIG$v) call $start:interface ) - (func $interface/AFoo#get:x (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $interface/AFoo#foo (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 - i32.load8_u offset=4 + i32.load + local.get $1 + i32.add ) - (func $interface/IFoo#get:x (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $interface/StructurallyImplementsIFoo#foo (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load + local.get $1 + i32.add + ) + (func $interface/IFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) local.get $0 i32.const 8 i32.sub i32.load - local.set $1 - local.get $1 + local.set $2 + local.get $2 i32.const 3 i32.eq if (result i32) local.get $0 - call $interface/AFoo#get:x - else local.get $1 + call $interface/AFoo#foo + else + local.get $2 i32.const 4 i32.eq if (result i32) local.get $0 - i32.load8_u offset=4 + local.get $1 + call $interface/StructurallyImplementsIFoo#foo else unreachable end end ) - (func $interface/AFoo#set:x (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - local.get $0 + (func $interface/AFoo#faa (; 14 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 - i32.store8 offset=4 + local.get $2 + i32.add ) - (func $interface/IFoo#set:x (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - (local $2 i32) + (func $interface/StructurallyImplementsIFoo#faa (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $1 + local.get $2 + i32.add + ) + (func $interface/IFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) local.get $0 i32.const 8 i32.sub i32.load - local.set $2 - local.get $2 + local.set $3 + local.get $3 i32.const 3 i32.eq - if + if (result i32) local.get $0 local.get $1 - call $interface/AFoo#set:x - else local.get $2 + call $interface/AFoo#faa + else + local.get $3 i32.const 4 i32.eq - if + if (result i32) local.get $0 local.get $1 - i32.store8 offset=4 + local.get $2 + call $interface/StructurallyImplementsIFoo#faa else unreachable end end ) - (func $interface/AFoo#foo (; 15 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/AFoo#set:x (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 - i32.load local.get $1 - i32.add - ) - (func $interface/StructurallyImplementsIFoo#foo (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load - local.get $1 - i32.add + i32.store8 offset=4 ) - (func $interface/IFoo#foo (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $interface/IFoo#set:x (; 18 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 i32.const 8 @@ -360,57 +375,47 @@ local.get $2 i32.const 3 i32.eq - if (result i32) + if local.get $0 local.get $1 - call $interface/AFoo#foo + call $interface/AFoo#set:x else local.get $2 i32.const 4 i32.eq - if (result i32) + if local.get $0 local.get $1 - call $interface/StructurallyImplementsIFoo#foo + i32.store8 offset=4 else unreachable end end ) - (func $interface/AFoo#faa (; 18 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add - ) - (func $interface/StructurallyImplementsIFoo#faa (; 19 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - local.get $1 - local.get $2 - i32.add + (func $interface/AFoo#get:x (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load8_u offset=4 ) - (func $interface/IFoo#faa (; 20 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) + (func $interface/IFoo#get:x (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) local.get $0 i32.const 8 i32.sub i32.load - local.set $3 - local.get $3 + local.set $1 + local.get $1 i32.const 3 i32.eq if (result i32) local.get $0 - local.get $1 - local.get $2 - call $interface/AFoo#faa + call $interface/AFoo#get:x else - local.get $3 + local.get $1 i32.const 4 i32.eq if (result i32) local.get $0 - local.get $1 - local.get $2 - call $interface/StructurallyImplementsIFoo#faa + i32.load8_u offset=4 else unreachable end diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat index b98ac5d66d..35fc7c3bd6 100644 --- a/tests/compiler/std/iterator.optimized.wat +++ b/tests/compiler/std/iterator.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -123,7 +122,7 @@ i32.store offset=12 local.get $3 ) - (func $std/iterator/IterableArray#get:iterator (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#constructor (; 3 ;) (param $0 i32) (result i32) (local $1 i32) i32.const 8 i32.const 6 @@ -1305,31 +1304,26 @@ i32.store end ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 22 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 16 - i32.const 9 - call $~lib/rt/stub/__alloc - local.set $0 - end - local.get $0 + (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 22 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + i32.const 16 + i32.const 9 + call $~lib/rt/stub/__alloc + local.tee $3 i32.const 0 i32.store + local.get $3 local.get $0 - local.get $1 i32.store offset=4 - local.get $0 - local.get $2 + local.get $3 + local.get $1 i32.store offset=8 - local.get $0 local.get $3 + local.get $2 i32.store offset=12 - local.get $0 + local.get $3 ) (func $~lib/map/Map<~lib/string/String,i32>#entries (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 0 local.get $0 local.get $0 i32.load offset=8 @@ -1387,7 +1381,7 @@ i32.const 448 global.set $~lib/rt/stub/offset i32.const 56 - call $std/iterator/IterableArray#get:iterator + call $std/iterator/ArrayIterator#constructor global.set $std/iterator/iter global.get $std/iterator/iter call $~lib/iterator/Iterator#next @@ -1427,7 +1421,7 @@ end end global.get $std/iterator/iterableArr - call $std/iterator/IterableArray#get:iterator + call $std/iterator/ArrayIterator#constructor call $~lib/array/Array.from global.set $std/iterator/arr2 global.get $std/iterator/arr2 @@ -1635,9 +1629,30 @@ i32.load offset=12 i32.ge_s ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:done (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.const 8 + i32.sub + i32.load + local.tee $1 + i32.const 6 + i32.eq + if (result i32) + local.get $0 + call $std/iterator/ArrayIterator#get:done + else + local.get $1 + i32.const 14 + i32.eq + if (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + else + unreachable + end + end ) (func $~lib/iterator/IteratorResult#get:value (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) @@ -1680,32 +1695,7 @@ end local.get $0 ) - (func $~lib/iterator/IteratorResult#get:done (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $std/iterator/ArrayIterator#get:done - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done - else - unreachable - end - end - ) - (func $null (; 35 ;) (type $FUNCSIG$v) + (func $null (; 34 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat index 9f43f144c3..beaa2aacf2 100644 --- a/tests/compiler/std/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -21,8 +21,8 @@ (data (i32.const 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") (data (i32.const 376) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00h\00e\00l\00l\00o\00") (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d\00") - (table $0 11 funcref) - (elem (i32.const 0) $null $std/iterator/ArrayIterator#constructor $std/iterator/IterableArray#get:iterator $~lib/map/EntriesIter<~lib/string/String,i32>#constructor $~lib/map/EntriesIter<~lib/string/String,i32>#get:done $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry $~lib/map/EntriesIter<~lib/string/String,i32>#next $std/iterator/ArrayIterator#next $std/iterator/ArrayIterator#get:done $std/iterator/ArrayIterator#get:value $~lib/map/EntriesIter<~lib/string/String,i32>#get:value) + (table $0 1 funcref) + (elem (i32.const 0) $null) (global $std/iterator/arri32 (mut i32) (i32.const 56)) (global $std/iterator/iterableArr (mut i32) (i32.const 0)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) @@ -3192,31 +3192,12 @@ call $~lib/array/Array#get:length i32.ge_s ) - (func $std/iterator/ArrayIterator#get:value (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - call $std/iterator/ArrayIterator#get:done - i32.eqz - if - local.get $0 - i32.load offset=4 - local.get $0 - i32.load - call $~lib/array/Array#__get - return - end - unreachable - ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value - i32.load offset=4 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult#get:value (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:done (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -3228,25 +3209,44 @@ i32.eq if (result i32) local.get $0 - call $std/iterator/ArrayIterator#get:value + call $std/iterator/ArrayIterator#get:done else local.get $1 i32.const 14 i32.eq if (result i32) local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done else unreachable end end ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $std/iterator/ArrayIterator#get:done + i32.eqz + if + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get + return + end + unreachable + ) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + ) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value + i32.load offset=4 ) - (func $~lib/iterator/IteratorResult#get:done (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:value (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -3258,14 +3258,14 @@ i32.eq if (result i32) local.get $0 - call $std/iterator/ArrayIterator#get:done + call $std/iterator/ArrayIterator#get:value else local.get $1 i32.const 14 i32.eq if (result i32) local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value else unreachable end @@ -3288,24 +3288,7 @@ unreachable end ) - (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:done (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 9 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done - else - unreachable - end - ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next @@ -3313,7 +3296,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator<~lib/string/String>#next (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -3330,14 +3313,14 @@ unreachable end ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value i32.load call $~lib/rt/stub/__retain ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 56 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 8 @@ -3354,28 +3337,6 @@ unreachable end ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:done (; 57 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done - ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 58 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 12 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#get:done - else - unreachable - end - ) - (func $null (; 59 ;) (type $FUNCSIG$v) + (func $null (; 56 ;) (type $FUNCSIG$v) ) ) From c2f72bd682ee622e390586dc42a5f84481ef4ec9 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Sun, 8 Dec 2019 17:05:56 -0500 Subject: [PATCH 28/47] Remove unneeded methods --- src/program.ts | 73 ++------------------------------------------------ 1 file changed, 2 insertions(+), 71 deletions(-) diff --git a/src/program.ts b/src/program.ts index 320d3e6f38..3dc96d21a2 100644 --- a/src/program.ts +++ b/src/program.ts @@ -3714,80 +3714,11 @@ export class Interface extends Class { // FIXME ); } - get memberValues(): Iterable { - if (this.members != null) return this.members.values(); - return []; - } - - get methods(): FunctionPrototype[] { - if (this.members == null) return []; - return filter(this.members.values(), - (v: DeclaredElement): bool => v.kind == ElementKind.FUNCTION_PROTOTYPE); - } - - get getters(): Property[] { - return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY && (v).getterInstance != null); - } - - get setters(): Property[] { - return filter(this.memberValues, v => v.kind == ElementKind.PROPERTY && (v).setterInstance != null); - } - - get methodInstances(): Function[] { - var funcs: Set = new Set(); - for (let func of this.methods) { - if (func.instances) { - for (let i of func.instances.values()){ - funcs.add(i); - } - } - } - return Array.from(funcs); - } - addImplementer(_class: Class): void { this.implementers.add(_class); - if (this.base == null){ - return; - } - (this.base).addImplementer(_class); - } - - checkClass(_class: Class): FunctionPrototype[] { - const res = []; - for (const ifunc of this.methods) { - let func = this.getFunc(_class, ifunc); - if (func == null || !(ifunc.equals(func))) res.push(ifunc); - } - return res; - } - - private getFunc(_class: Class, ifunc: FunctionPrototype): FunctionPrototype | null { - if (_class.members == null) return null; - return _class.members.get(ifunc.name); - } - - private getProp(_class: Class, iprop: PropertyPrototype): PropertyPrototype | null { - if (_class.members == null) return null; - return _class.members.get(iprop.name); - } - - getPropImplementations(iprop: Property): PropertyPrototype[] { - return map(this.implementers, _class => this.getProp(_class, iprop.prototype)) - .filter(notNull); - } - - getFuncImplementations(ifunc: Function): FunctionPrototype[] { - return map(this.implementers, _class => this.getFunc(_class, ifunc.prototype)) - .filter(notNull); - } - - get methodsToCompile(): FunctionPrototype[] { - var funcs: FunctionPrototype[] = []; - for (let func of this.methodInstances) { - funcs.concat(this.getFuncImplementations(func)); + if (this.base != null){ + (this.base).addImplementer(_class); } - return funcs; } } From 7992d0250319e796a42cd0f7181119cbd85187a6 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 09:23:39 -0500 Subject: [PATCH 29/47] fix tests --- src/compiler.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 0da06abe0a..8c8808240e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9518,10 +9518,9 @@ export function defaulType(nativeType: NativeType, module: Module): ExpressionRe case NativeType.I64: return module.i64(0); case NativeType.F32: return module.f32(0); case NativeType.F64: return module.f64(0); - case NativeType.V128: return module.v128(new Uint8Array); + case NativeType.V128: return module.v128(new Uint8Array()); case NativeType.I32: case NativeType.Anyref: - case NativeType.Exnref: default: { return module.i32(0); } From 88db5975e12e56391e29f92f2a21590f10fa3f93 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 10:59:28 -0500 Subject: [PATCH 30/47] Added Abstract Methods --- src/compiler.ts | 12 +- src/parser.ts | 3 +- src/program.ts | 62 +++-- src/types.ts | 7 + tests/compiler/abstract-method.json | 5 + tests/compiler/abstract-method.optimized.wat | 156 +++++++++++ tests/compiler/abstract-method.ts | 23 ++ tests/compiler/abstract-method.untouched.wat | 265 +++++++++++++++++++ tests/compiler/interface-inherit.ts | 1 + 9 files changed, 506 insertions(+), 28 deletions(-) create mode 100644 tests/compiler/abstract-method.json create mode 100644 tests/compiler/abstract-method.optimized.wat create mode 100644 tests/compiler/abstract-method.ts create mode 100644 tests/compiler/abstract-method.untouched.wat diff --git a/src/compiler.ts b/src/compiler.ts index 8c8808240e..2a1034a6e4 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3044,16 +3044,17 @@ export class Compiler extends DiagnosticEmitter { if (this.currentFlow.isNonnull(expr, fromType)) fromType = fromType.nonNullableType; // Check if a converting to an Interface - if (toType.isInterface && !toType.isFunction) { - if (!fromType.isManaged || fromType.classReference == null) { + if ((toType.isInterface || toType.isAbstractClass) && !toType.isFunction) { + if ((!fromType.isManaged && toType.isManaged) || fromType.classReference == null) { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, reportNode.range, fromType.toString(), toType.toString()); } else { + //Also checks abstract methods if (this.checkInterfaceImplementation(toType, fromType, reportNode)) { - (toType.classReference).addImplementer(fromType.classReference); + toType.classReference!.addImplementer(fromType.classReference); } else { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, @@ -9279,6 +9280,9 @@ export class Compiler extends DiagnosticEmitter { var incorrectMember = false; for (let [name, imem] of imems.entries()) { error = error || incorrectMember; + if (!imem.is(CommonFlags.VIRTUAL)){ + continue; + } incorrectMember = true; if (mems == null || mems.get(name) == null) { // Error! @@ -9333,7 +9337,7 @@ export class Compiler extends DiagnosticEmitter { case ElementKind.PROPERTY_PROTOTYPE: { const property = mem; const iproperty = imem; - if (!iproperty.is(CommonFlags.READONLY)) { + if (!iproperty.isAny(CommonFlags.READONLY | CommonFlags.ABSTRACT)) { if (property.setterPrototype == null) { this.error( DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, diff --git a/src/parser.ts b/src/parser.ts index 27c8d8a9c5..13b988a025 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1843,6 +1843,7 @@ export class Parser extends DiagnosticEmitter { ); } flags |= CommonFlags.ABSTRACT; + flags |= CommonFlags.VIRTUAL; abstractStart = tn.tokenPos; abstractEnd = tn.pos; } @@ -2100,7 +2101,7 @@ export class Parser extends DiagnosticEmitter { } body = this.parseBlockStatement(tn, false); if (!body) return null; - } else if (!(flags & CommonFlags.AMBIENT) && !isInterface) { + } else if (!(flags & CommonFlags.AMBIENT) && !isInterface && !(flags & CommonFlags.ABSTRACT)) { this.error( DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration, tn.range() diff --git a/src/program.ts b/src/program.ts index 2380c5620b..97e387da56 100644 --- a/src/program.ts +++ b/src/program.ts @@ -934,20 +934,25 @@ export class Program extends DiagnosticEmitter { if (!baseElement) continue; if (baseElement.kind == ElementKind.CLASS_PROTOTYPE || baseElement.kind == ElementKind.INTERFACE_PROTOTYPE) { let basePrototype = baseElement; - if (basePrototype.hasDecorator(DecoratorFlags.SEALED)) { - this.error( - DiagnosticCode.Class_0_is_sealed_and_cannot_be_extended, - extendsNode.range, (baseElement).identifierNode.text - ); - } - if ( - basePrototype.hasDecorator(DecoratorFlags.UNMANAGED) != - thisPrototype.hasDecorator(DecoratorFlags.UNMANAGED) - ) { - this.error( - DiagnosticCode.Unmanaged_classes_cannot_extend_managed_classes_and_vice_versa, - Range.join(thisPrototype.identifierNode.range, extendsNode.range) - ); + if (thisPrototype.kind == ElementKind.INTERFACE_PROTOTYPE) { + // TODO: Interface extends class + // basePrototype = InterfacePrototype.fromClassPrototype(basePrototype); + } else { + if (basePrototype.hasDecorator(DecoratorFlags.SEALED)) { + this.error( + DiagnosticCode.Class_0_is_sealed_and_cannot_be_extended, + extendsNode.range, (baseElement).identifierNode.text + ); + } + if ( + basePrototype.hasDecorator(DecoratorFlags.UNMANAGED) != + thisPrototype.hasDecorator(DecoratorFlags.UNMANAGED) + ) { + this.error( + DiagnosticCode.Unmanaged_classes_cannot_extend_managed_classes_and_vice_versa, + Range.join(thisPrototype.identifierNode.range, extendsNode.range) + ); + } } thisPrototype.basePrototype = basePrototype; } else { @@ -3368,6 +3373,8 @@ export class Class extends TypedElement { rttiFlags: u32 = 0; /** Wrapped type, if a wrapper for a basic type. */ wrappedType: Type | null = null; + /** Each class that uses an abstract class or interface */ + implementers: Set = new Set(); /** Gets the unique runtime id of this class. */ get id(): u32 { @@ -3684,10 +3691,17 @@ export class Class extends TypedElement { } return false; } + + addImplementer(_class: Class): void { + this.implementers.add(_class); + if (this.base != null) { + (this.base).addImplementer(_class); + } + } } /** A yet unresolved interface. */ -export class InterfacePrototype extends ClassPrototype { // FIXME +export class InterfacePrototype extends ClassPrototype { /** Constructs a new interface prototype. */ constructor( @@ -3704,11 +3718,20 @@ export class InterfacePrototype extends ClassPrototype { // FIXME true ); } + /** Convert a class to an interface when an interface extends a class */ + static fromClassPrototype(cP: ClassPrototype): InterfacePrototype { + const cDecl = cP.declaration; + const iDecl = new InterfaceDeclaration(); + iDecl.typeParameters = cDecl.typeParameters; + iDecl.extendsType = cDecl.extendsType; + iDecl.implementsTypes = cDecl.implementsTypes; + iDecl.members = cDecl.members; + return new InterfacePrototype(cP.name, cP.parent, iDecl, cP.decoratorFlags); + } } /** A resolved interface. */ export class Interface extends Class { // FIXME - implementers: Set = new Set(); /** Constructs a new interface. */ constructor( nameInclTypeParameters: string, @@ -3724,13 +3747,6 @@ export class Interface extends Class { // FIXME true ); } - - addImplementer(_class: Class): void { - this.implementers.add(_class); - if (this.base != null){ - (this.base).addImplementer(_class); - } - } } /** Registers a concrete element with a program. */ diff --git a/src/types.ts b/src/types.ts index 4ad913ac8c..1f93cf59f0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,6 +14,7 @@ import { import { NativeType } from "./module"; +import { CommonFlags } from "./common"; /** Indicates the kind of a type. */ export const enum TypeKind { @@ -187,6 +188,12 @@ export class Type { return this.classReference != null && this.classReference.kind == ElementKind.INTERFACE; } + get isAbstractClass(): bool { + return this.classReference != null + && this.classReference.kind == ElementKind.CLASS + && this.classReference.is(CommonFlags.ABSTRACT); + } + /** Computes the sign-extending shift in the target type. */ computeSmallIntegerShift(targetType: Type): u32 { return targetType.size - this.size; diff --git a/tests/compiler/abstract-method.json b/tests/compiler/abstract-method.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/abstract-method.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/abstract-method.optimized.wat b/tests/compiler/abstract-method.optimized.wat new file mode 100644 index 0000000000..8129b4da20 --- /dev/null +++ b/tests/compiler/abstract-method.optimized.wat @@ -0,0 +1,156 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00a\00b\00s\00t\00r\00a\00c\00t\00-\00m\00e\00t\00h\00o\00d\00.\00t\00s") + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $abstract-method/aastract (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $2 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.tee $1 + i32.const 16 + i32.store + local.get $1 + i32.const -1 + i32.store offset=4 + local.get $1 + local.get $0 + i32.store offset=8 + local.get $1 + i32.const 4 + i32.store offset=12 + local.get $2 + ) + (func $abstract-method/testAbstract (; 3 ;) (param $0 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load + else + unreachable + end + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 19 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.eq + if (result i32) + local.get $0 + i32.load + i32.const 1 + i32.shl + else + unreachable + end + i32.const 84 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 20 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 4 ;) (type $FUNCSIG$v) + (local $0 i32) + i32.const 64 + global.set $~lib/rt/stub/startOffset + i32.const 64 + global.set $~lib/rt/stub/offset + i32.const 4 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.eqz + if + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + i32.const 42 + i32.store + local.get $0 + global.set $abstract-method/aastract + global.get $abstract-method/aastract + call $abstract-method/testAbstract + ) + (func $null (; 5 ;) (type $FUNCSIG$v) + unreachable + ) +) diff --git a/tests/compiler/abstract-method.ts b/tests/compiler/abstract-method.ts new file mode 100644 index 0000000000..f4715e36a6 --- /dev/null +++ b/tests/compiler/abstract-method.ts @@ -0,0 +1,23 @@ +abstract class Abstract { + x: i32 = 42; + abstract abstractMethod(): i32; + abstract get y(): i32; + +} + +class AAbstract extends Abstract { + abstractMethod(): i32 { + return this.x; + } + + get y(): i32 { return this.x * 2 } +} + +const aastract = new AAbstract(); + +function testAbstract(a: Abstract, expected: i32): void { + assert(a.abstractMethod() == expected); + assert(a.y == expected * 2); +} + +testAbstract(aastract, 42); \ No newline at end of file diff --git a/tests/compiler/abstract-method.untouched.wat b/tests/compiler/abstract-method.untouched.wat new file mode 100644 index 0000000000..8a7aba2203 --- /dev/null +++ b/tests/compiler/abstract-method.untouched.wat @@ -0,0 +1,265 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00a\00b\00s\00t\00r\00a\00c\00t\00-\00m\00e\00t\00h\00o\00d\00.\00t\00s\00") + (table $0 1 funcref) + (elem (i32.const 0) $null) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $abstract-method/aastract (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 60)) + (export "memory" (memory $0)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $abstract-method/Abstract#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const 42 + i32.store + local.get $0 + ) + (func $abstract-method/AAbstract#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $abstract-method/Abstract#constructor + local.set $0 + local.get $0 + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $abstract-method/testAbstract (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $abstract-method/Abstract#abstractMethod + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 19 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $abstract-method/Abstract#get:y + local.get $1 + i32.const 2 + i32.mul + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 20 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:abstract-method (; 8 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $abstract-method/AAbstract#constructor + global.set $abstract-method/aastract + global.get $abstract-method/aastract + i32.const 42 + call $abstract-method/testAbstract + ) + (func $start (; 9 ;) (type $FUNCSIG$v) + call $start:abstract-method + ) + (func $abstract-method/AAbstract#abstractMethod (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + ) + (func $abstract-method/Abstract#abstractMethod (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + call $abstract-method/AAbstract#abstractMethod + else + unreachable + end + ) + (func $abstract-method/AAbstract#get:y (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + i32.const 2 + i32.mul + ) + (func $abstract-method/Abstract#get:y (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + local.set $1 + local.get $1 + i32.const 4 + i32.eq + if (result i32) + local.get $0 + call $abstract-method/AAbstract#get:y + else + unreachable + end + ) + (func $null (; 14 ;) (type $FUNCSIG$v) + unreachable + ) +) diff --git a/tests/compiler/interface-inherit.ts b/tests/compiler/interface-inherit.ts index 8b64d46c3b..38a3030ef1 100644 --- a/tests/compiler/interface-inherit.ts +++ b/tests/compiler/interface-inherit.ts @@ -57,6 +57,7 @@ testGIC(aa); // testGIC(aFromClass); // function testFromClass(i: FromClass): void { +// assert(i.a() == 84); // assert(Math.abs(i.d() - 3.14) < 0.00001 ); // } From b9debc4c84adc23303b42491fc9663dd3cead891 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 11:05:57 -0500 Subject: [PATCH 31/47] fix uint8constructor issue --- src/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index 2a1034a6e4..5ba8b04e4e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9522,7 +9522,7 @@ export function defaulType(nativeType: NativeType, module: Module): ExpressionRe case NativeType.I64: return module.i64(0); case NativeType.F32: return module.f32(0); case NativeType.F64: return module.f64(0); - case NativeType.V128: return module.v128(new Uint8Array()); + case NativeType.V128: return module.v128(v128_zero); case NativeType.I32: case NativeType.Anyref: default: { From 54e35d95340428d657444871c255eb14a8c64583 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 11:55:13 -0500 Subject: [PATCH 32/47] remove unneeded methods --- src/compiler.ts | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 5ba8b04e4e..5c529f6601 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9404,14 +9404,14 @@ export class Compiler extends DiagnosticEmitter { const relooper = this.module.createRelooper(); // Condition to switch on - const first = relooper.addBlock(module.local_set(classIDLocal, loadClassID(module))); + const first = relooper.addBlock(module.local_set(classIDLocal, this.loadClassID())); const last = relooper.addBlock(module.unreachable()); relooper.addBranch(first, last); for (let _class of classes) { const expr = this.compileInterfaceMethod(ifunc, _class, classIDLocal); const returnBlock = relooper.addBlock(expr); - const loadLocal = loadClassArg(module, classIDLocal); + const loadLocal = this.loadClassArg(classIDLocal); const classID = module.i32(_class.id); relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); } @@ -9510,6 +9510,20 @@ export class Compiler extends DiagnosticEmitter { get nativeUsizeType(): NativeType { return this.options.usizeType.toNativeType(); } + + loadClassID(): ExpressionRef { + var module = this.module; + return module.load( + 4, + false, + module.binary( + BinaryOp.SubI32, + this.loadClassArg(0), + module.i32(8) + ), + NativeType.I32 + ); + } } // helpers @@ -9528,27 +9542,10 @@ export function defaulType(nativeType: NativeType, module: Module): ExpressionRe default: { return module.i32(0); } - } - -} +} -function loadClassArg(module: Module, index: number): ExpressionRef { - return module.local_get(index, Type.i32.toNativeType()); -} -function loadClassID(module: Module): ExpressionRef { - return module.load( - 4, - false, - module.binary( - BinaryOp.SubI32, - module.local_get(0, NativeType.I32), - module.i32(8) - ), - NativeType.I32 - ); -} function mangleImportName( element: Element, From 3e36c2615e1e023a9446acf4df572f50eee5e7d9 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 13:32:56 -0500 Subject: [PATCH 33/47] Moved to branch table Cleaned up source to pass linting check --- src/compiler.ts | 97 +++++----- src/program.ts | 16 +- src/types.ts | 4 +- std/assembly/index.d.ts | 4 + tests/compiler/abstract-method.optimized.wat | 22 +-- tests/compiler/abstract-method.ts | 4 +- tests/compiler/abstract-method.untouched.wat | 48 +++-- .../compiler/interface-generic.optimized.wat | 91 ++++----- .../compiler/interface-generic.untouched.wat | 111 +++++------ .../compiler/interface-inherit.optimized.wat | 33 ++-- tests/compiler/interface-inherit.ts | 6 +- .../compiler/interface-inherit.untouched.wat | 83 ++++---- tests/compiler/interface.optimized.wat | 133 ++++++------- tests/compiler/interface.untouched.wat | 150 +++++++-------- tests/compiler/std/iterator.optimized.wat | 144 +++++++------- tests/compiler/std/iterator.untouched.wat | 177 ++++++++---------- 16 files changed, 509 insertions(+), 614 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 5c529f6601..d39c2a5e92 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9280,7 +9280,7 @@ export class Compiler extends DiagnosticEmitter { var incorrectMember = false; for (let [name, imem] of imems.entries()) { error = error || incorrectMember; - if (!imem.is(CommonFlags.VIRTUAL)){ + if (!imem.is(CommonFlags.VIRTUAL)) { continue; } incorrectMember = true; @@ -9298,8 +9298,10 @@ export class Compiler extends DiagnosticEmitter { let mem = mems.get(name)!; if (imem.kind != mem.kind) { // Interfaces can't have properties - if ((mem.kind != ElementKind.PROPERTY_PROTOTYPE && mem.kind != ElementKind.FIELD_PROTOTYPE && mem.kind != ElementKind.FIELD && - imem.kind == ElementKind.PROPERTY)) { + if (mem.kind != ElementKind.PROPERTY_PROTOTYPE + && mem.kind != ElementKind.FIELD_PROTOTYPE + && mem.kind != ElementKind.FIELD + && imem.kind == ElementKind.PROPERTY) { this.error( DiagnosticCode.Type_0_is_not_assignable_to_type_1, (mem).declaration.range, @@ -9398,39 +9400,49 @@ export class Compiler extends DiagnosticEmitter { compileInterfaces(): void { const module = this.module; for (let ifunc of this.interfaceMethods) { - let classes = (ifunc.parent).implementers; - const classIDLocal = ifunc.localsByIndex.length - const typeRef = this.ensureSignature(ifunc!.signature); + let classes = (ifunc.parent).implementers; + const signature = ifunc.signature; + const returnType = signature.returnType; + const typeRef = this.ensureSignature(signature); const relooper = this.module.createRelooper(); - + const isVoid = returnType.toNativeType() == NativeType.None; + // Condition to switch on - const first = relooper.addBlock(module.local_set(classIDLocal, this.loadClassID())); + const first = relooper.addBlockWithSwitch(module.nop(), this.loadClassID()); + const defaultVal = defaultTypeValue(returnType.toNativeType(), module); const last = relooper.addBlock(module.unreachable()); relooper.addBranch(first, last); - for (let _class of classes) { - const expr = this.compileInterfaceMethod(ifunc, _class, classIDLocal); + // Add branch cases + for (let _class of classes) { + let expr = this.compileInterfaceMethod(ifunc, _class); + if (!isVoid) { + expr = module.return(expr); + } const returnBlock = relooper.addBlock(expr); - const loadLocal = this.loadClassArg(classIDLocal); - const classID = module.i32(_class.id); - relooper.addBranch(first, returnBlock, module.binary(BinaryOp.EqI32, loadLocal, classID)); + relooper.addBranchForSwitch(first, returnBlock, [_class.id]); } + + // finish relooper and prepare body of function + let switchExpression = relooper.renderAndDispose(first, 0); + let block = isVoid ? [switchExpression] : [switchExpression, defaultVal]; + let body = module.block(null, block, returnType.toNativeType()); + // Remove the nop standin module.removeFunction(ifunc.internalName); - module.addFunction(ifunc.internalName, typeRef, [this.nativeUsizeType], relooper.renderAndDispose(first, 0)); + module.addFunction(ifunc.internalName, typeRef, null, body); } } - compileInterfaceMethod(ifunc: Function, _class: Class, classIDLocal: i32): ExpressionRef { + compileInterfaceMethod(ifunc: Function, _class: Class): ExpressionRef { const module = this.module; - let name: string = ifunc.name; - if (ifunc.isAny(CommonFlags.GET | CommonFlags.SET)){ + var name: string = ifunc.name; + if (ifunc.isAny(CommonFlags.GET | CommonFlags.SET)) { name = name.substr("get:".length); } - let prop = _class.members!.get(name)!; - let method: Function; - + var prop = _class.members!.get(name)!; const returnType = ifunc!.signature.returnType.toNativeType(); + var method: Function; switch (prop.kind){ case ElementKind.FUNCTION_PROTOTYPE: { let p = prop; @@ -9440,21 +9452,21 @@ export class Compiler extends DiagnosticEmitter { } prop = newFunc; } - case ElementKind.FUNCTION:{ + case ElementKind.FUNCTION: { method = prop; break; } case ElementKind.FIELD: { let field = prop; - var type = field.type; - var nativeType = type.toNativeType(); + let type = field.type; + let nativeType = type.toNativeType(); const thisExpr = module.local_get(0, this.nativeUsizeType); - if (ifunc.is(CommonFlags.SET)){ + if (ifunc.is(CommonFlags.SET)) { assert(ifunc.signature.parameterTypes.length == 1); - if (ifunc.signature.parameterTypes[0] != type){ + if (ifunc.signature.parameterTypes[0] != type) { return module.nop(); } - var valueExpr = module.local_get(1, nativeType); + let valueExpr = module.local_get(1, nativeType); return module.store( type.byteSize, thisExpr, @@ -9463,8 +9475,8 @@ export class Compiler extends DiagnosticEmitter { field.memoryOffset ); } - if (ifunc.is(CommonFlags.GET)){ - if (ifunc.signature.returnType != type){ + if (ifunc.is(CommonFlags.GET)) { + if (ifunc.signature.returnType != type) { return module.nop(); } assert(field.memoryOffset >= 0); @@ -9473,15 +9485,14 @@ export class Compiler extends DiagnosticEmitter { field.type.is(TypeFlags.SIGNED | TypeFlags.INTEGER), thisExpr, field.type.toNativeType(), - field.memoryOffset) + field.memoryOffset); } } case ElementKind.PROPERTY: { let p = prop; - if (ifunc.is(CommonFlags.SET)){ + if (ifunc.is(CommonFlags.SET)) { method = p.setterInstance!; - - }else if (ifunc.is(CommonFlags.GET)){ + }else if (ifunc.is(CommonFlags.GET)) { method = p.getterInstance!; }else { throw Error("Interface method " + ifunc.name + " should be a property"); @@ -9489,17 +9500,18 @@ export class Compiler extends DiagnosticEmitter { break; } - default: + default: { throw Error("Class " + _class.name + " must have property " + prop.name); + } } this.compileFunction(method); const locals: usize[] = []; - for (let i: i32 = 0; i < classIDLocal; i++) { + for (let i: i32 = 0; i < ifunc.localsByIndex.length; i++) { const local = ifunc.localsByIndex[i]; locals.push(this.module.local_get(local.index, local.type.toNativeType())); } - return this.module.call(method.internalName, locals, returnType) + return this.module.call(method.internalName, locals, returnType); } @@ -9510,7 +9522,7 @@ export class Compiler extends DiagnosticEmitter { get nativeUsizeType(): NativeType { return this.options.usizeType.toNativeType(); } - + loadClassID(): ExpressionRef { var module = this.module; return module.load( @@ -9531,21 +9543,22 @@ export class Compiler extends DiagnosticEmitter { const v128_zero = new Uint8Array(16); /* Useful for adding to the end of a block that needs a type even if there is an unreachable(); */ -export function defaulType(nativeType: NativeType, module: Module): ExpressionRef { - switch(nativeType){ +export function defaultTypeValue(nativeType: NativeType, module: Module): ExpressionRef { + switch (nativeType) { case NativeType.I64: return module.i64(0); case NativeType.F32: return module.f32(0); case NativeType.F64: return module.f64(0); case NativeType.V128: return module.v128(v128_zero); + case NativeType.Unreachable: return module.unreachable(); + case NativeType.None: return module.nop(); case NativeType.I32: case NativeType.Anyref: - default: { + case NativeType.Exnref: + default: { return module.i32(0); } } -} - - +} function mangleImportName( element: Element, diff --git a/src/program.ts b/src/program.ts index 97e387da56..09ed37441a 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1861,16 +1861,16 @@ export class Program extends DiagnosticEmitter { if (!parent.add(name, element)) return null; var memberDeclarations = declaration.members; if (declaration.extendsType) queuedExtends.push(element); - var instanceDeclarations = new Array(); + var instanceDeclarations = new Array(); /** * Must convert field declarations to property declarations */ for (let i = 0, k = memberDeclarations.length; i < k; ++i) { let memberDeclaration = memberDeclarations[i]; - if (memberDeclaration.kind == NodeKind.FIELDDECLARATION){ + if (memberDeclaration.kind == NodeKind.FIELDDECLARATION) { let fieldDecl = memberDeclaration; - if (!fieldDecl.is(CommonFlags.READONLY)){ - const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range) + if (!fieldDecl.is(CommonFlags.READONLY)) { + const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range); const signature = Node.createFunctionType([param], Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); instanceDeclarations.push(Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.SET, fieldDecl.range)); } @@ -3229,12 +3229,6 @@ export class ClassPrototype extends DeclaredElement { /** Already resolved instances. */ instances: Map | null = null; - /** Instance Methods */ - get instanceMethods(): FunctionPrototype[] { - if (!this.instanceMembers) return []; - return filter(this.instanceMembers.values(), (mem: Element): bool => mem.kind == ElementKind.FUNCTION_PROTOTYPE); - } - constructor( /** Simple name. */ name: string, @@ -3694,7 +3688,7 @@ export class Class extends TypedElement { addImplementer(_class: Class): void { this.implementers.add(_class); - if (this.base != null) { + if (this.base != null) { (this.base).addImplementer(_class); } } diff --git a/src/types.ts b/src/types.ts index 1f93cf59f0..9abbf7da57 100644 --- a/src/types.ts +++ b/src/types.ts @@ -189,8 +189,8 @@ export class Type { } get isAbstractClass(): bool { - return this.classReference != null - && this.classReference.kind == ElementKind.CLASS + return this.classReference != null + && this.classReference.kind == ElementKind.CLASS && this.classReference.is(CommonFlags.ABSTRACT); } diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 6b03d4cf97..7446d93d2f 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1588,6 +1588,10 @@ interface SymbolConstructor { keyFor(sym: symbol): string | null; } +interface Symbol { + toString(): string +} + declare const Symbol: SymbolConstructor; interface IMath { diff --git a/tests/compiler/abstract-method.optimized.wat b/tests/compiler/abstract-method.optimized.wat index 8129b4da20..2343e3be76 100644 --- a/tests/compiler/abstract-method.optimized.wat +++ b/tests/compiler/abstract-method.optimized.wat @@ -85,13 +85,12 @@ i32.sub i32.load i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load - else + i32.sub + if unreachable end + local.get $0 + i32.load i32.const 42 i32.ne if @@ -107,15 +106,14 @@ i32.sub i32.load i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load - i32.const 1 - i32.shl - else + i32.sub + if unreachable end + local.get $0 + i32.load + i32.const 1 + i32.shl i32.const 84 i32.ne if diff --git a/tests/compiler/abstract-method.ts b/tests/compiler/abstract-method.ts index f4715e36a6..5d1328ce05 100644 --- a/tests/compiler/abstract-method.ts +++ b/tests/compiler/abstract-method.ts @@ -10,7 +10,7 @@ class AAbstract extends Abstract { return this.x; } - get y(): i32 { return this.x * 2 } + get y(): i32 { return this.x * 2; } } const aastract = new AAbstract(); @@ -20,4 +20,4 @@ function testAbstract(a: Abstract, expected: i32): void { assert(a.y == expected * 2); } -testAbstract(aastract, 42); \ No newline at end of file +testAbstract(aastract, 42); diff --git a/tests/compiler/abstract-method.untouched.wat b/tests/compiler/abstract-method.untouched.wat index 8a7aba2203..0bd4c5faaf 100644 --- a/tests/compiler/abstract-method.untouched.wat +++ b/tests/compiler/abstract-method.untouched.wat @@ -220,21 +220,19 @@ i32.load ) (func $abstract-method/Abstract#abstractMethod (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $abstract-method/AAbstract#abstractMethod - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $abstract-method/AAbstract#abstractMethod + return ) (func $abstract-method/AAbstract#get:y (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -243,21 +241,19 @@ i32.mul ) (func $abstract-method/Abstract#get:y (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $abstract-method/AAbstract#get:y - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $abstract-method/AAbstract#get:y + return ) (func $null (; 14 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/interface-generic.optimized.wat b/tests/compiler/interface-generic.optimized.wat index abae72ca9c..100732997c 100644 --- a/tests/compiler/interface-generic.optimized.wat +++ b/tests/compiler/interface-generic.optimized.wat @@ -116,20 +116,17 @@ call $~lib/builtins/abort unreachable end - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $0 - i32.const 3 - i32.ne - if - local.get $0 - i32.const 4 - i32.ne - if - unreachable + block $__inlined_func$interface-generic/GFoo#faa + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $__inlined_func$interface-generic/GFoo#faa $__inlined_func$interface-generic/GFoo#faa $switch$1$default end + unreachable end ) (func $interface-generic/expectGX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) @@ -213,51 +210,45 @@ i32.add ) (func $interface-generic/GFoo#foo (; 8 ;) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface-generic/AGFoo#foo - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $interface-generic/AGFoo#foo - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $interface-generic/AGFoo#foo + return end + local.get $0 + call $interface-generic/AGFoo#foo ) (func $interface-generic/GFoo#get:x (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) - i32.const 1 - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end + i32.const 1 + return end + local.get $0 + i32.load8_u offset=4 ) (func $null (; 10 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/interface-generic.untouched.wat b/tests/compiler/interface-generic.untouched.wat index ccc6b8b618..3a7bb7929f 100644 --- a/tests/compiler/interface-generic.untouched.wat +++ b/tests/compiler/interface-generic.untouched.wat @@ -288,31 +288,26 @@ i32.add ) (func $interface-generic/GFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $2 - local.get $2 - i32.const 3 - i32.eq - if (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $1 call $interface-generic/AGFoo#foo - else - local.get $2 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - local.get $1 - call $interface-generic/StructurallyImplementsGFoo#foo - else - unreachable - end + return end + local.get $0 + local.get $1 + call $interface-generic/StructurallyImplementsGFoo#foo + return ) (func $interface-generic/AGFoo#faa (; 14 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 @@ -325,61 +320,51 @@ i32.add ) (func $interface-generic/GFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $3 - local.get $3 - i32.const 3 - i32.eq - if (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $1 local.get $2 call $interface-generic/AGFoo#faa - else - local.get $3 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - local.get $1 - local.get $2 - call $interface-generic/StructurallyImplementsGFoo#faa - else - unreachable - end + return end + local.get $0 + local.get $1 + local.get $2 + call $interface-generic/StructurallyImplementsGFoo#faa + return ) (func $interface-generic/AGFoo#get:x (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 1 ) (func $interface-generic/GFoo#get:x (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface-generic/AGFoo#get:x - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $interface-generic/AGFoo#get:x + return end + local.get $0 + i32.load8_u offset=4 + return ) (func $null (; 19 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/interface-inherit.optimized.wat b/tests/compiler/interface-inherit.optimized.wat index 28f420a72f..68248dec4f 100644 --- a/tests/compiler/interface-inherit.optimized.wat +++ b/tests/compiler/interface-inherit.optimized.wat @@ -219,7 +219,7 @@ i32.sub i32.load i32.const 4 - i32.ne + i32.sub if unreachable end @@ -239,7 +239,7 @@ i32.sub i32.load i32.const 4 - i32.ne + i32.sub if unreachable end @@ -283,24 +283,23 @@ end ) (func $interface-inherit/IA#a (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $0 - i32.const 4 - i32.eq - if (result i32) - i32.const 42 - else - local.get $0 - i32.const 3 - i32.ne - if + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$4 $switch$1$case$3 $switch$1$default + end unreachable end - i32.const 84 + i32.const 42 + return end + i32.const 84 ) (func $null (; 9 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/interface-inherit.ts b/tests/compiler/interface-inherit.ts index 38a3030ef1..777ca8b00d 100644 --- a/tests/compiler/interface-inherit.ts +++ b/tests/compiler/interface-inherit.ts @@ -15,7 +15,7 @@ class AA { a(): i32 { return 84; } } -let aa = new AA(); +const aa = new AA(); // assert(aa.a() == 84); class AC implements IC { @@ -24,7 +24,7 @@ class AC implements IC { c(): bool { return true; } } -let ac = new AC(); +const ac = new AC(); function testIA(ia: IA): void { assert(ia.a() == 42); @@ -61,4 +61,4 @@ testGIC(aa); // assert(Math.abs(i.d() - 3.14) < 0.00001 ); // } -// testFromClass(aFromClass); \ No newline at end of file +// testFromClass(aFromClass); diff --git a/tests/compiler/interface-inherit.untouched.wat b/tests/compiler/interface-inherit.untouched.wat index ef4eefec2e..7987e11b38 100644 --- a/tests/compiler/interface-inherit.untouched.wat +++ b/tests/compiler/interface-inherit.untouched.wat @@ -481,69 +481,60 @@ i32.const 84 ) (func $interface-inherit/IA#a (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $interface-inherit/AC#a - else - local.get $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface-inherit/AA#a - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $interface-inherit/AC#a + return end + local.get $0 + call $interface-inherit/AA#a + return ) (func $interface-inherit/AC#b (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 80 ) (func $interface-inherit/IB#b (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $interface-inherit/AC#b - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $interface-inherit/AC#b + return ) (func $interface-inherit/AC#c (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 1 ) (func $interface-inherit/IC#c (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $interface-inherit/AC#c - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $interface-inherit/AC#c + return ) (func $null (; 22 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index a2d5293e33..48bae9508a 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -97,26 +97,35 @@ call $~lib/builtins/abort unreachable end - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $0 - i32.const 3 - i32.ne - if - local.get $0 - i32.const 4 - i32.ne - if - unreachable + block $__inlined_func$interface/IFoo#faa + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $__inlined_func$interface/IFoo#faa $__inlined_func$interface/IFoo#faa $switch$1$default end + unreachable end ) (func $interface/expectX (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + block $switch$1$leave + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$leave $switch$1$leave $switch$1$default + end + unreachable + end local.get $0 local.get $1 - call $interface/IFoo#set:x + i32.store8 offset=4 local.get $0 call $interface/IFoo#get:x i32.const 0 @@ -197,80 +206,48 @@ i32.add ) (func $interface/IFoo#foo (; 8 ;) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface/AFoo#foo - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - call $interface/AFoo#foo - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $interface/AFoo#foo + return end - ) - (func $interface/IFoo#set:x (; 9 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - (local $2 i32) local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $2 - i32.const 3 - i32.eq - if - local.get $0 - local.get $1 - i32.store8 offset=4 - else - local.get $2 - i32.const 4 - i32.eq - if - local.get $0 - local.get $1 - i32.store8 offset=4 - else + call $interface/AFoo#foo + ) + (func $interface/IFoo#get:x (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end - end - ) - (func $interface/IFoo#get:x (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 3 - i32.eq - if (result i32) local.get $0 i32.load8_u offset=4 - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else - unreachable - end + return end + local.get $0 + i32.load8_u offset=4 ) - (func $null (; 11 ;) (type $FUNCSIG$v) + (func $null (; 10 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 845a4e9f91..689130b33a 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -295,31 +295,26 @@ i32.add ) (func $interface/IFoo#foo (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $2 - local.get $2 - i32.const 3 - i32.eq - if (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $1 call $interface/AFoo#foo - else - local.get $2 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - local.get $1 - call $interface/StructurallyImplementsIFoo#foo - else - unreachable - end + return end + local.get $0 + local.get $1 + call $interface/StructurallyImplementsIFoo#foo + return ) (func $interface/AFoo#faa (; 14 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $1 @@ -332,33 +327,28 @@ i32.add ) (func $interface/IFoo#faa (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $3 - local.get $3 - i32.const 3 - i32.eq - if (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $1 local.get $2 call $interface/AFoo#faa - else - local.get $3 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - local.get $1 - local.get $2 - call $interface/StructurallyImplementsIFoo#faa - else - unreachable - end + return end + local.get $0 + local.get $1 + local.get $2 + call $interface/StructurallyImplementsIFoo#faa + return ) (func $interface/AFoo#set:x (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 @@ -366,30 +356,27 @@ i32.store8 offset=4 ) (func $interface/IFoo#set:x (; 18 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - (local $2 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $2 - local.get $2 - i32.const 3 - i32.eq - if - local.get $0 - local.get $1 - call $interface/AFoo#set:x - else - local.get $2 - i32.const 4 - i32.eq - if + block $switch$1$leave + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $1 - i32.store8 offset=4 - else - unreachable + call $interface/AFoo#set:x + br $switch$1$leave end + local.get $0 + local.get $1 + i32.store8 offset=4 + br $switch$1$leave end ) (func $interface/AFoo#get:x (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -397,29 +384,24 @@ i32.load8_u offset=4 ) (func $interface/IFoo#get:x (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 3 - i32.eq - if (result i32) - local.get $0 - call $interface/AFoo#get:x - else - local.get $1 - i32.const 4 - i32.eq - if (result i32) - local.get $0 - i32.load8_u offset=4 - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $interface/AFoo#get:x + return end + local.get $0 + i32.load8_u offset=4 + return ) (func $null (; 21 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat index 8ad6ffada8..fda01d4fc0 100644 --- a/tests/compiler/std/iterator.optimized.wat +++ b/tests/compiler/std/iterator.optimized.wat @@ -1484,13 +1484,12 @@ i32.sub i32.load i32.const 9 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - else + i32.sub + if unreachable end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry i32.load i32.const 392 call $~lib/string/String.__eq @@ -1520,13 +1519,12 @@ i32.sub i32.load i32.const 12 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#next - else + i32.sub + if unreachable end + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next global.set $std/iterator/key global.get $std/iterator/key local.tee $0 @@ -1534,15 +1532,14 @@ i32.sub i32.load i32.const 12 - i32.eq - if (result i32) - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - i32.load - else + i32.sub + if unreachable end + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load i32.const 392 call $~lib/string/String.__eq i32.eqz @@ -1592,34 +1589,30 @@ local.get $0 ) (func $~lib/iterator/Iterator#next (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 6 - i32.eq - if + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end local.get $0 local.get $0 i32.load i32.const 1 i32.add i32.store - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#next - else - unreachable - end - local.set $0 + local.get $0 + return end local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next ) (func $std/iterator/ArrayIterator#get:done (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -1630,40 +1623,41 @@ i32.ge_s ) (func $~lib/iterator/IteratorResult#get:done (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.tee $1 - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $std/iterator/ArrayIterator#get:done - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $std/iterator/ArrayIterator#get:done + return end - ) - (func $~lib/iterator/IteratorResult#get:value (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) local.get $0 - i32.const 8 - i32.sub i32.load - local.tee $1 - i32.const 6 - i32.eq - if + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult#get:value (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end block $__inlined_func$std/iterator/ArrayIterator#get:value local.get $0 call $std/iterator/ArrayIterator#get:done @@ -1679,21 +1673,13 @@ end unreachable end - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - i32.load offset=4 - else - unreachable - end - local.set $0 + local.get $0 + return end local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=4 ) (func $null (; 34 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/std/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat index 14600b4b03..fb18898ea1 100644 --- a/tests/compiler/std/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -3160,29 +3160,24 @@ call $~lib/rt/stub/__retain ) (func $~lib/iterator/Iterator#next (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $std/iterator/ArrayIterator#next - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#next - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $std/iterator/ArrayIterator#next + return end + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#next + return ) (func $std/iterator/ArrayIterator#get:done (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -3198,29 +3193,24 @@ call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) (func $~lib/iterator/IteratorResult#get:done (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $std/iterator/ArrayIterator#get:done - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $std/iterator/ArrayIterator#get:done + return end + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done + return ) (func $std/iterator/ArrayIterator#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -3247,46 +3237,39 @@ i32.load offset=4 ) (func $~lib/iterator/IteratorResult#get:value (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 6 - i32.eq - if (result i32) - local.get $0 - call $std/iterator/ArrayIterator#get:value - else - local.get $1 - i32.const 14 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value - else + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end unreachable end + local.get $0 + call $std/iterator/ArrayIterator#get:value + return end + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value + return ) (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 51 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 9 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value + return ) (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -3297,21 +3280,19 @@ call $~lib/rt/stub/__retain ) (func $~lib/iterator/Iterator<~lib/string/String>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 12 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#next - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#next + return ) (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -3321,21 +3302,19 @@ call $~lib/rt/stub/__retain ) (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - local.get $0 - i32.const 8 - i32.sub - i32.load - local.set $1 - local.get $1 - i32.const 12 - i32.eq - if (result i32) - local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#get:value - else + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end unreachable end + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:value + return ) (func $null (; 56 ;) (type $FUNCSIG$v) unreachable From 43d943005fd91ce0001270263d47e4b8c1ae9f84 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 13:41:50 -0500 Subject: [PATCH 34/47] Added abstract SubClass to abstract method test --- tests/compiler/abstract-method.optimized.wat | 109 +++++++++++++----- tests/compiler/abstract-method.ts | 14 +++ tests/compiler/abstract-method.untouched.wat | 113 ++++++++++++++----- 3 files changed, 177 insertions(+), 59 deletions(-) diff --git a/tests/compiler/abstract-method.optimized.wat b/tests/compiler/abstract-method.optimized.wat index 2343e3be76..e714081d36 100644 --- a/tests/compiler/abstract-method.optimized.wat +++ b/tests/compiler/abstract-method.optimized.wat @@ -1,5 +1,7 @@ (module (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) @@ -8,6 +10,7 @@ (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $abstract-method/aastract (mut i32) (i32.const 0)) + (global $abstract-method/aAnotherAbstract (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) @@ -79,53 +82,48 @@ i32.store offset=12 local.get $2 ) - (func $abstract-method/testAbstract (; 3 ;) (param $0 i32) + (func $abstract-method/Abstract#constructor (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 4 - i32.sub + i32.eqz if - unreachable + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 end local.get $0 - i32.load i32.const 42 + i32.store + local.get $0 + ) + (func $abstract-method/testAbstract (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $abstract-method/Abstract#abstractMethod + local.get $1 i32.ne if i32.const 0 i32.const 24 - i32.const 19 + i32.const 32 i32.const 2 call $~lib/builtins/abort unreachable end local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 4 - i32.sub - if - unreachable - end - local.get $0 - i32.load + call $abstract-method/Abstract#get:y + local.get $1 i32.const 1 i32.shl - i32.const 84 i32.ne if i32.const 0 i32.const 24 - i32.const 20 + i32.const 33 i32.const 2 call $~lib/builtins/abort unreachable end ) - (func $start (; 4 ;) (type $FUNCSIG$v) + (func $start (; 5 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 64 global.set $~lib/rt/stub/startOffset @@ -133,22 +131,73 @@ global.set $~lib/rt/stub/offset i32.const 4 call $~lib/rt/stub/__alloc + call $abstract-method/Abstract#constructor + global.set $abstract-method/aastract + i32.const 6 + call $~lib/rt/stub/__alloc local.tee $0 - i32.eqz - if - i32.const 3 + if (result i32) + local.get $0 + else + i32.const 5 call $~lib/rt/stub/__alloc - local.set $0 end - local.get $0 - i32.const 42 + call $abstract-method/Abstract#constructor + local.tee $0 + i32.const 21 i32.store local.get $0 - global.set $abstract-method/aastract + global.set $abstract-method/aAnotherAbstract global.get $abstract-method/aastract + i32.const 42 + call $abstract-method/testAbstract + global.get $abstract-method/aAnotherAbstract + i32.const 21 call $abstract-method/testAbstract ) - (func $null (; 5 ;) (type $FUNCSIG$v) + (func $abstract-method/Abstract#abstractMethod (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + i32.load + return + end + i32.const 21 + ) + (func $abstract-method/Abstract#get:y (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + i32.load + i32.const 1 + i32.shl + return + end + i32.const 42 + ) + (func $null (; 8 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/abstract-method.ts b/tests/compiler/abstract-method.ts index 5d1328ce05..4da2257dd2 100644 --- a/tests/compiler/abstract-method.ts +++ b/tests/compiler/abstract-method.ts @@ -5,6 +5,14 @@ abstract class Abstract { } +abstract class SubAstract extends Abstract { + constructor() { + super(); + this.x = 21; + } + get y(): i32 { return 42; } +} + class AAbstract extends Abstract { abstractMethod(): i32 { return this.x; @@ -13,7 +21,12 @@ class AAbstract extends Abstract { get y(): i32 { return this.x * 2; } } +class AAnotherAbstract extends SubAstract { + abstractMethod(): i32 { return 21; } +} + const aastract = new AAbstract(); +const aAnotherAbstract = new AAnotherAbstract(); function testAbstract(a: Abstract, expected: i32): void { assert(a.abstractMethod() == expected); @@ -21,3 +34,4 @@ function testAbstract(a: Abstract, expected: i32): void { } testAbstract(aastract, 42); +testAbstract(aAnotherAbstract, 21); diff --git a/tests/compiler/abstract-method.untouched.wat b/tests/compiler/abstract-method.untouched.wat index 0bd4c5faaf..1177aa7a31 100644 --- a/tests/compiler/abstract-method.untouched.wat +++ b/tests/compiler/abstract-method.untouched.wat @@ -13,6 +13,7 @@ (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $abstract-method/aastract (mut i32) (i32.const 0)) + (global $abstract-method/aAnotherAbstract (mut i32) (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 60)) (export "memory" (memory $0)) (start $start) @@ -156,10 +157,42 @@ local.set $0 local.get $0 ) - (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $abstract-method/SubAstract#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + if (result i32) + local.get $0 + else + i32.const 4 + i32.const 5 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + end + call $abstract-method/Abstract#constructor + local.set $0 + local.get $0 + i32.const 21 + i32.store + local.get $0 + ) + (func $abstract-method/AAnotherAbstract#constructor (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 6 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $abstract-method/SubAstract#constructor + local.set $0 + local.get $0 + ) + (func $~lib/rt/stub/__release (; 8 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $abstract-method/testAbstract (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $abstract-method/testAbstract (; 9 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 call $~lib/rt/stub/__retain local.set $0 @@ -171,7 +204,7 @@ if i32.const 0 i32.const 24 - i32.const 19 + i32.const 32 i32.const 2 call $~lib/builtins/abort unreachable @@ -186,7 +219,7 @@ if i32.const 0 i32.const 24 - i32.const 20 + i32.const 33 i32.const 2 call $~lib/builtins/abort unreachable @@ -194,7 +227,7 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:abstract-method (; 8 ;) (type $FUNCSIG$v) + (func $start:abstract-method (; 10 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -208,54 +241,76 @@ i32.const 0 call $abstract-method/AAbstract#constructor global.set $abstract-method/aastract + i32.const 0 + call $abstract-method/AAnotherAbstract#constructor + global.set $abstract-method/aAnotherAbstract global.get $abstract-method/aastract i32.const 42 call $abstract-method/testAbstract + global.get $abstract-method/aAnotherAbstract + i32.const 21 + call $abstract-method/testAbstract ) - (func $start (; 9 ;) (type $FUNCSIG$v) + (func $start (; 11 ;) (type $FUNCSIG$v) call $start:abstract-method ) - (func $abstract-method/AAbstract#abstractMethod (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/AAbstract#abstractMethod (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load ) - (func $abstract-method/Abstract#abstractMethod (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + (func $abstract-method/AAnotherAbstract#abstractMethod (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 21 + ) + (func $abstract-method/Abstract#abstractMethod (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable end - unreachable + local.get $0 + call $abstract-method/AAbstract#abstractMethod + return end local.get $0 - call $abstract-method/AAbstract#abstractMethod + call $abstract-method/AAnotherAbstract#abstractMethod return ) - (func $abstract-method/AAbstract#get:y (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/AAbstract#get:y (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load i32.const 2 i32.mul ) - (func $abstract-method/Abstract#get:y (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + (func $abstract-method/SubAstract#get:y (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $abstract-method/Abstract#get:y (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable end - unreachable + local.get $0 + call $abstract-method/AAbstract#get:y + return end local.get $0 - call $abstract-method/AAbstract#get:y + call $abstract-method/SubAstract#get:y return ) - (func $null (; 14 ;) (type $FUNCSIG$v) + (func $null (; 18 ;) (type $FUNCSIG$v) unreachable ) ) From 7e904a5bce4537816941738bbd2a1b69e72236a8 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 13:57:20 -0500 Subject: [PATCH 35/47] [skip ci] remove unused methods --- src/program.ts | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/program.ts b/src/program.ts index 09ed37441a..0fabfc1a79 100644 --- a/src/program.ts +++ b/src/program.ts @@ -91,10 +91,7 @@ import { writeI16, writeI32, writeF32, - writeF64, - filter, - map, - notNull + writeF64 } from "./util"; import { @@ -509,20 +506,6 @@ export class Program extends DiagnosticEmitter { return null; } - get interfaces(): Interface[] { - return this.getInstanceByKind(ElementKind.INTERFACE); - } - - getInstanceByKind(kind: ElementKind): Element[] { - const res = []; - for (const element of this.instancesByName.values()) { - if (element.kind == kind) { - res.push(element); - } - } - return res; - } - /** Writes a common runtime header to the specified buffer. */ writeRuntimeHeader(buffer: Uint8Array, offset: i32, classInstance: Class, payloadSize: u32): void { // BLOCK { From de3d6ad6b88198d52d024de637c1ed6846cbb38d Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Mon, 9 Dec 2019 14:02:57 -0500 Subject: [PATCH 36/47] More clean up --- src/ast.ts | 53 -------------------------------------------------- src/program.ts | 5 ----- 2 files changed, 58 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index d9d6b2bda0..2980df67b7 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1041,10 +1041,6 @@ export abstract class Node { // types -interface Comparable { - equals(other: Comparable): bool; -} - export abstract class TypeNode extends Node { // kind varies @@ -1081,20 +1077,6 @@ export abstract class TypeNode extends Node { } return false; } - - /** Method for determine type equality. */ - abstract equals(node: TypeNode): bool; - - static arrayEquals(node: Comparable[] | null, other: Comparable[] | null): bool { - if (node == other) return true; - if (!node || !other) return false; - const len = other.length; - if (node.length !== len) return false; - for (let i = 0; i < len; i++) { - if (!node[i].equals(other[i])) return false; - } - return true; - } } /** Represents a type name. */ @@ -1105,13 +1087,6 @@ export class TypeName extends Node { identifier: IdentifierExpression; /** Next part of the type name or `null` if this is the last part. */ next: TypeName | null; - - equals(node: TypeName): bool { - if (node.identifier.symbol !== this.identifier.symbol) return false; - if (node.next == null && this.next == null) return true; - if (node.next == null || this.next == null) return false; - return this.next.equals(node.next); - } } /** Represents a named type. */ @@ -1122,11 +1097,6 @@ export class NamedTypeNode extends TypeNode { name: TypeName; /** Type argument references. */ typeArguments: TypeNode[] | null; - equals(node: NamedTypeNode): bool { - if (!this.name.equals(node.name)) return false; - return TypeNode.arrayEquals(this.typeArguments, node.typeArguments); - - } } /** Represents a function type. */ @@ -1139,22 +1109,6 @@ export class FunctionTypeNode extends TypeNode { returnType: TypeNode; /** Explicitly provided this type, if any. */ explicitThisType: NamedTypeNode | null; // can't be a function - - equals(node: FunctionTypeNode): bool { - if (!TypeNode.arrayEquals(this.parameterTypes, node.parameterTypes)) return false; - if (!this.returnType.equals(node.returnType)) return false; - if ((this.explicitThisType == null && node.explicitThisType == null)) return true; - if (this.explicitThisType == null || node.explicitThisType == null) return false; - return true; - } - - get parameterTypes(): TypeNode[] { - const res: TypeNode[] = []; - for (let i: i32 = 0 ; i < this.parameters.length; i++) { - res.push(this.parameters[i].type); - } - return res; - } } /** Represents a type parameter. */ @@ -1167,13 +1121,6 @@ export class TypeParameterNode extends Node { extendsType: NamedTypeNode | null; // can't be a function /** Default type if omitted, if any. */ defaultType: NamedTypeNode | null; // can't be a function - - equals(node: TypeParameterNode): bool { - if (this.name != node.name) return false; - if ((this.extendsType == null && node.extendsType == null)) return true; - if (this.extendsType == null || node.extendsType == null) return false; - return true; - } } /** Represents the kind of a parameter. */ diff --git a/src/program.ts b/src/program.ts index 0fabfc1a79..036946c4bf 100644 --- a/src/program.ts +++ b/src/program.ts @@ -2821,11 +2821,6 @@ export class FunctionPrototype extends DeclaredElement { lookup(name: string): Element | null { return this.parent.lookup(name); } - - equals(func: FunctionPrototype): bool { - return this.functionTypeNode.equals(func.functionTypeNode) && - TypeNode.arrayEquals(func.typeParameterNodes, this.typeParameterNodes); - } } /** A resolved function. */ From 34dba5d990a9e1360315c7334ea90b5550ba5be0 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 11 Dec 2019 11:31:31 -0500 Subject: [PATCH 37/47] Added Virtual Decorator for methods --- src/ast.ts | 7 +- src/compiler.ts | 49 +++- src/program.ts | 7 +- tests/compiler/abstract-method.optimized.wat | 49 +++- tests/compiler/abstract-method.ts | 8 + tests/compiler/abstract-method.untouched.wat | 118 +++++++-- tests/compiler/class-overloading-virtual.json | 5 + .../class-overloading-virtual.optimized.wat | 152 +++++++++++ tests/compiler/class-overloading-virtual.ts | 24 ++ .../class-overloading-virtual.untouched.wat | 237 ++++++++++++++++++ tests/compiler/interface-generic.ts | 5 +- 11 files changed, 620 insertions(+), 41 deletions(-) create mode 100644 tests/compiler/class-overloading-virtual.json create mode 100644 tests/compiler/class-overloading-virtual.optimized.wat create mode 100644 tests/compiler/class-overloading-virtual.ts create mode 100644 tests/compiler/class-overloading-virtual.untouched.wat diff --git a/src/ast.ts b/src/ast.ts index 2980df67b7..95061ba287 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1174,7 +1174,8 @@ export enum DecoratorKind { EXTERNAL, BUILTIN, LAZY, - UNSAFE + UNSAFE, + VIRTUAL, } export namespace DecoratorKind { @@ -1219,6 +1220,10 @@ export namespace DecoratorKind { if (nameStr == "unsafe") return DecoratorKind.UNSAFE; break; } + case CharCode.v: { + if (nameStr == "virtual") return DecoratorKind.VIRTUAL; + break; + } } } else if ( nameNode.kind == NodeKind.PROPERTYACCESS && diff --git a/src/compiler.ts b/src/compiler.ts index d39c2a5e92..bbaa1733fc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -463,7 +463,7 @@ export class Compiler extends DiagnosticEmitter { if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory); // set up virtual table - this.compileInterfaces(); + this.compileVirtualMethods(); // set up function table var functionTable = this.functionTable; @@ -1297,8 +1297,19 @@ export class Compiler extends DiagnosticEmitter { // concrete function if (bodyNode) { - - // must not be ambient + // Check if instance method is virtual so that overloading will use dynamic dispatch + if (instance.prototype.isBound && instance.hasDecorator(DecoratorFlags.VIRTUAL) && !this.interfaceMethods.has(instance)) { + this.interfaceMethods.add(instance); + assert(instance.parent.kind == ElementKind.CLASS); + (instance.parent).addImplementer(instance.parent); + funcRef = module.addFunction( + instance.internalName, + typeRef, + null, + module.nop() + ); + }else { + // must not be ambient if (instance.is(CommonFlags.AMBIENT)) { this.error( DiagnosticCode.An_implementation_cannot_be_declared_in_ambient_contexts, @@ -1358,8 +1369,9 @@ export class Compiler extends DiagnosticEmitter { typesToNativeTypes(instance.additionalLocals), flatten(module, stmts, instance.signature.returnType.toNativeType()) ); - // Virtual Methods - } else if (instance.is( CommonFlags.VIRTUAL)) { + } + // Interface or Abstract Methods + } else if (instance.is(CommonFlags.VIRTUAL)) { funcRef = module.addFunction(instance.internalName, typeRef, null, @@ -3080,6 +3092,12 @@ export class Compiler extends DiagnosticEmitter { } } + if (fromType.classReference && toType.classReference) { + if (fromType.classReference.extends(toType.classReference.prototype)){ + toType.classReference.addImplementer(fromType.classReference); + } + } + if (fromType.is(TypeFlags.FLOAT)) { // float to float @@ -9397,10 +9415,14 @@ export class Compiler extends DiagnosticEmitter { return !error; } - compileInterfaces(): void { + /** + * Compiles interfaces methods, abstract methods, and methods decorated with '@virtual' + */ + compileVirtualMethods(): void { const module = this.module; for (let ifunc of this.interfaceMethods) { let classes = (ifunc.parent).implementers; + const name = ifunc.internalName; const signature = ifunc.signature; const returnType = signature.returnType; const typeRef = this.ensureSignature(signature); @@ -9428,9 +9450,12 @@ export class Compiler extends DiagnosticEmitter { let block = isVoid ? [switchExpression] : [switchExpression, defaultVal]; let body = module.block(null, block, returnType.toNativeType()); + // if (ifunc.hasDecorator(DecoratorFlags.VIRTUAL)) { + // ifunc.internalName = ifunc.internalName.substr(0, ifunc.internalName.length - "~virtual".length); + // } // Remove the nop standin - module.removeFunction(ifunc.internalName); - module.addFunction(ifunc.internalName, typeRef, null, body); + module.removeFunction(name); + module.addFunction(name, typeRef, null, body); } } @@ -9504,7 +9529,15 @@ export class Compiler extends DiagnosticEmitter { throw Error("Class " + _class.name + " must have property " + prop.name); } } + var methodName = method.internalName; + /** + * If method is virtual it must be renamed to not overlap with actual implementation. + */ + if (ifunc.hasDecorator(DecoratorFlags.VIRTUAL) && ifunc.parent == method.parent) { + method.internalName = method.internalName + "~virtual"; + method.unset(CommonFlags.COMPILED); + } this.compileFunction(method); const locals: usize[] = []; for (let i: i32 = 0; i < ifunc.localsByIndex.length; i++) { diff --git a/src/program.ts b/src/program.ts index 036946c4bf..d157a59443 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1373,7 +1373,7 @@ export class Program extends DiagnosticEmitter { ): void { var name = declaration.name.text; var isStatic = declaration.is(CommonFlags.STATIC); - var acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE; + var acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE | DecoratorFlags.VIRTUAL; if (!declaration.is(CommonFlags.GENERIC)) { acceptedFlags |= DecoratorFlags.OPERATOR_BINARY | DecoratorFlags.OPERATOR_PREFIX @@ -2085,7 +2085,9 @@ export enum DecoratorFlags { /** Is compiled lazily. */ LAZY = 1 << 9, /** Is considered unsafe code. */ - UNSAFE = 1 << 10 + UNSAFE = 1 << 10, + /** Is a virtual method when inherited. */ + VIRTUAL = 1 << 11, } export namespace DecoratorFlags { @@ -2105,6 +2107,7 @@ export namespace DecoratorFlags { case DecoratorKind.BUILTIN: return DecoratorFlags.BUILTIN; case DecoratorKind.LAZY: return DecoratorFlags.LAZY; case DecoratorKind.UNSAFE: return DecoratorFlags.UNSAFE; + case DecoratorKind.VIRTUAL: return DecoratorFlags.VIRTUAL; default: return DecoratorFlags.NONE; } } diff --git a/tests/compiler/abstract-method.optimized.wat b/tests/compiler/abstract-method.optimized.wat index e714081d36..424ed933ba 100644 --- a/tests/compiler/abstract-method.optimized.wat +++ b/tests/compiler/abstract-method.optimized.wat @@ -123,7 +123,39 @@ unreachable end ) - (func $start (; 5 ;) (type $FUNCSIG$v) + (func $abstract-method/AAbstract#get:y (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + i32.const 1 + i32.shl + ) + (func $abstract-method/testGeneric (; 6 ;) (param $0 i32) + local.get $0 + i32.load + i32.const 42 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 40 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $abstract-method/AAbstract#get:y + i32.const 84 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start:abstract-method (; 7 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 64 global.set $~lib/rt/stub/startOffset @@ -154,8 +186,13 @@ global.get $abstract-method/aAnotherAbstract i32.const 21 call $abstract-method/testAbstract + global.get $abstract-method/aastract + call $abstract-method/testGeneric + ) + (func $start (; 8 ;) (type $FUNCSIG$v) + call $start:abstract-method ) - (func $abstract-method/Abstract#abstractMethod (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/Abstract#abstractMethod (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -175,7 +212,7 @@ end i32.const 21 ) - (func $abstract-method/Abstract#get:y (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/Abstract#get:y (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -190,14 +227,12 @@ unreachable end local.get $0 - i32.load - i32.const 1 - i32.shl + call $abstract-method/AAbstract#get:y return end i32.const 42 ) - (func $null (; 8 ;) (type $FUNCSIG$v) + (func $null (; 11 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/abstract-method.ts b/tests/compiler/abstract-method.ts index 4da2257dd2..6b8572abc9 100644 --- a/tests/compiler/abstract-method.ts +++ b/tests/compiler/abstract-method.ts @@ -35,3 +35,11 @@ function testAbstract(a: Abstract, expected: i32): void { testAbstract(aastract, 42); testAbstract(aAnotherAbstract, 21); + +function testGeneric(a: T, expected: i32): void { + assert(a.abstractMethod() == expected); + assert(a.y == expected * 2); +} + +testGeneric(aastract, 42); +testGeneric(aAnotherAbstract, 21); diff --git a/tests/compiler/abstract-method.untouched.wat b/tests/compiler/abstract-method.untouched.wat index 1177aa7a31..d03f9b7a68 100644 --- a/tests/compiler/abstract-method.untouched.wat +++ b/tests/compiler/abstract-method.untouched.wat @@ -227,7 +227,93 @@ local.get $0 call $~lib/rt/stub/__release ) - (func $start:abstract-method (; 10 ;) (type $FUNCSIG$v) + (func $abstract-method/AAbstract#abstractMethod (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + ) + (func $abstract-method/AAbstract#get:y (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + i32.const 2 + i32.mul + ) + (func $abstract-method/testGeneric (; 12 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $abstract-method/AAbstract#abstractMethod + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 40 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $abstract-method/AAbstract#get:y + local.get $1 + i32.const 2 + i32.mul + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $abstract-method/AAnotherAbstract#abstractMethod (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 21 + ) + (func $abstract-method/SubAstract#get:y (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $abstract-method/testGeneric (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $abstract-method/AAnotherAbstract#abstractMethod + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 40 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $abstract-method/SubAstract#get:y + local.get $1 + i32.const 2 + i32.mul + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:abstract-method (; 16 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -250,18 +336,17 @@ global.get $abstract-method/aAnotherAbstract i32.const 21 call $abstract-method/testAbstract + global.get $abstract-method/aastract + i32.const 42 + call $abstract-method/testGeneric + global.get $abstract-method/aAnotherAbstract + i32.const 21 + call $abstract-method/testGeneric ) - (func $start (; 11 ;) (type $FUNCSIG$v) + (func $start (; 17 ;) (type $FUNCSIG$v) call $start:abstract-method ) - (func $abstract-method/AAbstract#abstractMethod (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.load - ) - (func $abstract-method/AAnotherAbstract#abstractMethod (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 21 - ) - (func $abstract-method/Abstract#abstractMethod (; 14 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/Abstract#abstractMethod (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -281,16 +366,7 @@ call $abstract-method/AAnotherAbstract#abstractMethod return ) - (func $abstract-method/AAbstract#get:y (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.load - i32.const 2 - i32.mul - ) - (func $abstract-method/SubAstract#get:y (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 42 - ) - (func $abstract-method/Abstract#get:y (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $abstract-method/Abstract#get:y (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -310,7 +386,7 @@ call $abstract-method/SubAstract#get:y return ) - (func $null (; 18 ;) (type $FUNCSIG$v) + (func $null (; 20 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/class-overloading-virtual.json b/tests/compiler/class-overloading-virtual.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/class-overloading-virtual.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/class-overloading-virtual.optimized.wat b/tests/compiler/class-overloading-virtual.optimized.wat new file mode 100644 index 0000000000..4d333e584f --- /dev/null +++ b/tests/compiler/class-overloading-virtual.optimized.wat @@ -0,0 +1,152 @@ +(module + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s") + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $class-overloading-virtual/f (mut i32) (i32.const 0)) + (global $class-overloading-virtual/b (mut i32) (i32.const 0)) + (export "memory" (memory $0)) + (export "test" (func $class-overloading-virtual/test)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $2 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.tee $1 + i32.const 16 + i32.store + local.get $1 + i32.const -1 + i32.store offset=4 + local.get $1 + local.get $0 + i32.store offset=8 + local.get $1 + i32.const 0 + i32.store offset=12 + local.get $2 + ) + (func $class-overloading-virtual/Foo#constructor (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + ) + (func $class-overloading-virtual/test (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + block $__inlined_func$class-overloading-virtual/Foo#baz (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + i32.const 42 + br $__inlined_func$class-overloading-virtual/Foo#baz + end + i32.const 84 + end + local.get $1 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 16 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start:class-overloading-virtual (; 5 ;) (type $FUNCSIG$v) + i32.const 80 + global.set $~lib/rt/stub/startOffset + i32.const 80 + global.set $~lib/rt/stub/offset + i32.const 0 + call $class-overloading-virtual/Foo#constructor + global.set $class-overloading-virtual/f + i32.const 4 + call $~lib/rt/stub/__alloc + call $class-overloading-virtual/Foo#constructor + global.set $class-overloading-virtual/b + global.get $class-overloading-virtual/f + i32.const 42 + call $class-overloading-virtual/test + global.get $class-overloading-virtual/b + i32.const 84 + call $class-overloading-virtual/test + ) + (func $start (; 6 ;) (type $FUNCSIG$v) + call $start:class-overloading-virtual + ) + (func $null (; 7 ;) (type $FUNCSIG$v) + unreachable + ) +) diff --git a/tests/compiler/class-overloading-virtual.ts b/tests/compiler/class-overloading-virtual.ts new file mode 100644 index 0000000000..8dec3519f5 --- /dev/null +++ b/tests/compiler/class-overloading-virtual.ts @@ -0,0 +1,24 @@ +class Foo { + //@ts-ignore: decorator + @virtual + baz(): i32 { + return 42; + } +} + +class Bar extends Foo { + baz(): i32 { + return 84; + } +} + +export function test(foo: Foo, expected: i32): void { + assert(foo.baz() == expected); +} + +const f = new Foo(); +const b = new Bar(); + +test(f, 42); // calls Foo's baz +test(b, 84); // calls Bar's baz + diff --git a/tests/compiler/class-overloading-virtual.untouched.wat b/tests/compiler/class-overloading-virtual.untouched.wat new file mode 100644 index 0000000000..1779bd8ca2 --- /dev/null +++ b/tests/compiler/class-overloading-virtual.untouched.wat @@ -0,0 +1,237 @@ +(module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$v (func)) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s\00") + (table $0 1 funcref) + (elem (i32.const 0) $null) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $class-overloading-virtual/f (mut i32) (i32.const 0)) + (global $class-overloading-virtual/b (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 80)) + (export "memory" (memory $0)) + (export "test" (func $class-overloading-virtual/test)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $class-overloading-virtual/Foo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + ) + (func $class-overloading-virtual/Bar#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $class-overloading-virtual/Foo#constructor + local.set $0 + local.get $0 + ) + (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $class-overloading-virtual/test (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $0 + call $class-overloading-virtual/Foo#baz + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 16 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/stub/__release + ) + (func $start:class-overloading-virtual (; 8 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $class-overloading-virtual/Foo#constructor + global.set $class-overloading-virtual/f + i32.const 0 + call $class-overloading-virtual/Bar#constructor + global.set $class-overloading-virtual/b + global.get $class-overloading-virtual/f + i32.const 42 + call $class-overloading-virtual/test + global.get $class-overloading-virtual/b + i32.const 84 + call $class-overloading-virtual/test + ) + (func $start (; 9 ;) (type $FUNCSIG$v) + call $start:class-overloading-virtual + ) + (func $class-overloading-virtual/Foo#baz~virtual (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $class-overloading-virtual/Bar#baz (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 84 + ) + (func $class-overloading-virtual/Foo#baz (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading-virtual/Foo#baz~virtual + return + end + local.get $0 + call $class-overloading-virtual/Bar#baz + return + ) + (func $null (; 13 ;) (type $FUNCSIG$v) + unreachable + ) +) diff --git a/tests/compiler/interface-generic.ts b/tests/compiler/interface-generic.ts index 5ccbec3fea..7aebec55f4 100644 --- a/tests/compiler/interface-generic.ts +++ b/tests/compiler/interface-generic.ts @@ -23,7 +23,7 @@ class AGFoo implements GFoo { class StructurallyImplementsGFoo { i: i32 = 41; x: bool = false; - + foo(i: i32): i32 { return this.i + i; } @@ -54,4 +54,5 @@ expectGX(sGFoo, false); const gFoo = > aGFoo; const igbool = gFoo.x; -assert(igbool) \ No newline at end of file +assert(igbool); + From 516324db009703d0feda6047cf0395ed9bfca9ca Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 11 Dec 2019 11:47:00 -0500 Subject: [PATCH 38/47] Added more virtual overloading tests --- src/compiler.ts | 2 +- .../class-overloading-virtual.optimized.wat | 268 +++++++++++- tests/compiler/class-overloading-virtual.ts | 36 +- .../class-overloading-virtual.untouched.wat | 380 +++++++++++++++++- 4 files changed, 653 insertions(+), 33 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index bbaa1733fc..b0dae022bb 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -3093,7 +3093,7 @@ export class Compiler extends DiagnosticEmitter { } if (fromType.classReference && toType.classReference) { - if (fromType.classReference.extends(toType.classReference.prototype)){ + if (fromType.classReference.extends(toType.classReference.prototype)) { toType.classReference.addImplementer(fromType.classReference); } } diff --git a/tests/compiler/class-overloading-virtual.optimized.wat b/tests/compiler/class-overloading-virtual.optimized.wat index 4d333e584f..0ecaa70149 100644 --- a/tests/compiler/class-overloading-virtual.optimized.wat +++ b/tests/compiler/class-overloading-virtual.optimized.wat @@ -1,18 +1,25 @@ (module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s") + (data (i32.const 80) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o") + (data (i32.const 112) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r") + (data (i32.const 144) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a") (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $class-overloading-virtual/f (mut i32) (i32.const 0)) (global $class-overloading-virtual/b (mut i32) (i32.const 0)) + (global $class-overloading-virtual/bb (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "test" (func $class-overloading-virtual/test)) + (export "testBar" (func $class-overloading-virtual/testBar)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) @@ -93,8 +100,177 @@ end local.get $0 ) - (func $class-overloading-virtual/test (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - block $__inlined_func$class-overloading-virtual/Foo#baz (result i32) + (func $class-overloading-virtual/Bar#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + call $class-overloading-virtual/Foo#constructor + ) + (func $~lib/string/String#get:length (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 6 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 7 + i32.and + local.get $1 + i32.const 7 + i32.and + i32.or + i32.eqz + i32.const 0 + local.get $2 + i32.const 4 + i32.ge_u + select + if + loop $continue|0 + local.get $0 + i64.load + local.get $1 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + local.get $2 + i32.const 4 + i32.sub + local.tee $2 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + loop $continue|1 + block $break|1 + local.get $2 + local.tee $3 + i32.const 1 + i32.sub + local.set $2 + local.get $3 + i32.eqz + br_if $break|1 + local.get $1 + i32.load16_u + local.tee $3 + local.get $0 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $4 + local.get $3 + i32.sub + return + else + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + br $continue|1 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/string/String.__eq (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + return + end + block $folding-inner0 + local.get $1 + i32.eqz + i32.const 1 + local.get $0 + select + br_if $folding-inner0 + local.get $0 + call $~lib/string/String#get:length + local.tee $2 + local.get $1 + call $~lib/string/String#get:length + i32.ne + br_if $folding-inner0 + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/string/compareImpl + i32.eqz + return + end + i32.const 0 + ) + (func $class-overloading-virtual/test (; 8 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $class-overloading-virtual/Foo#baz + local.get $1 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 38 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + i32.const 96 + i32.const 96 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 39 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $class-overloading-virtual/testBar (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $0 + call $class-overloading-virtual/Bar#baz + local.get $1 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 52 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + block $__inlined_func$class-overloading-virtual/Bar#foo (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -102,51 +278,109 @@ i32.const 8 i32.sub i32.load - i32.const 3 + i32.const 4 i32.sub br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default end unreachable end - i32.const 42 - br $__inlined_func$class-overloading-virtual/Foo#baz + i32.const 128 + br $__inlined_func$class-overloading-virtual/Bar#foo end - i32.const 84 + i32.const 160 end - local.get $1 - i32.ne + local.get $2 + call $~lib/string/String.__eq + i32.eqz if i32.const 0 i32.const 24 - i32.const 16 + i32.const 53 i32.const 2 call $~lib/builtins/abort unreachable end ) - (func $start:class-overloading-virtual (; 5 ;) (type $FUNCSIG$v) - i32.const 80 + (func $start:class-overloading-virtual (; 10 ;) (type $FUNCSIG$v) + i32.const 176 global.set $~lib/rt/stub/startOffset - i32.const 80 + i32.const 176 global.set $~lib/rt/stub/offset i32.const 0 call $class-overloading-virtual/Foo#constructor global.set $class-overloading-virtual/f - i32.const 4 - call $~lib/rt/stub/__alloc - call $class-overloading-virtual/Foo#constructor + i32.const 0 + call $class-overloading-virtual/Bar#constructor global.set $class-overloading-virtual/b + i32.const 5 + call $~lib/rt/stub/__alloc + call $class-overloading-virtual/Bar#constructor + global.set $class-overloading-virtual/bb global.get $class-overloading-virtual/f i32.const 42 call $class-overloading-virtual/test global.get $class-overloading-virtual/b i32.const 84 call $class-overloading-virtual/test + global.get $class-overloading-virtual/bb + i32.const 168 + call $class-overloading-virtual/test + global.get $class-overloading-virtual/b + i32.const 84 + i32.const 128 + call $class-overloading-virtual/testBar + global.get $class-overloading-virtual/bb + i32.const 168 + i32.const 160 + call $class-overloading-virtual/testBar ) - (func $start (; 6 ;) (type $FUNCSIG$v) + (func $start (; 11 ;) (type $FUNCSIG$v) call $start:class-overloading-virtual ) - (func $null (; 7 ;) (type $FUNCSIG$v) + (func $class-overloading-virtual/Foo#baz (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default + end + unreachable + end + i32.const 42 + return + end + local.get $0 + call $class-overloading-virtual/Bar#baz + return + end + i32.const 168 + ) + (func $class-overloading-virtual/Bar#baz (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + i32.const 84 + return + end + i32.const 168 + ) + (func $null (; 14 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/class-overloading-virtual.ts b/tests/compiler/class-overloading-virtual.ts index 8dec3519f5..e77a160c78 100644 --- a/tests/compiler/class-overloading-virtual.ts +++ b/tests/compiler/class-overloading-virtual.ts @@ -4,21 +4,53 @@ class Foo { baz(): i32 { return 42; } + + foo(): string { + return "In Foo"; + } } class Bar extends Foo { + //@ts-ignore + @virtual baz(): i32 { return 84; } + + @virtual + foo(): string { + return "In Bar"; + } +} + +class Baa extends Bar { + baz(): i32 { + return 168; + } + + foo(): string { + return "In Baa"; + } } -export function test(foo: Foo, expected: i32): void { - assert(foo.baz() == expected); +export function test(foo: Foo, e1: i32): void { + assert(foo.baz() == e1); + assert(foo.foo() == "In Foo"); } const f = new Foo(); const b = new Bar(); +const bb = new Baa(); test(f, 42); // calls Foo's baz test(b, 84); // calls Bar's baz +test(bb, 168); + +export function testBar(foo: Bar, e1: i32, e2: string): void { + //@ts-ignore + assert(foo.baz() == e1); + assert(foo.foo() == e2); +} +testBar(b, 84, "In Bar"); // calls Bar's baz +testBar(bb, 168, "In Baa"); diff --git a/tests/compiler/class-overloading-virtual.untouched.wat b/tests/compiler/class-overloading-virtual.untouched.wat index 1779bd8ca2..d94ba48024 100644 --- a/tests/compiler/class-overloading-virtual.untouched.wat +++ b/tests/compiler/class-overloading-virtual.untouched.wat @@ -4,19 +4,27 @@ (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s\00") + (data (i32.const 80) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o\00") + (data (i32.const 112) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r\00") + (data (i32.const 144) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a\00") (table $0 1 funcref) (elem (i32.const 0) $null) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $class-overloading-virtual/f (mut i32) (i32.const 0)) (global $class-overloading-virtual/b (mut i32) (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 80)) + (global $class-overloading-virtual/bb (mut i32) (i32.const 0)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 172)) (export "memory" (memory $0)) (export "test" (func $class-overloading-virtual/test)) + (export "testBar" (func $class-overloading-virtual/testBar)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) @@ -155,10 +163,230 @@ local.set $0 local.get $0 ) - (func $~lib/rt/stub/__release (; 6 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $class-overloading-virtual/Baa#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 5 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $class-overloading-virtual/Bar#constructor + local.set $0 + local.get $0 + ) + (func $class-overloading-virtual/Foo#foo (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 96 + ) + (func $~lib/rt/stub/__release (; 8 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $class-overloading-virtual/test (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/string/String#get:length (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 10 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $break|0 + loop $continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + i32.eqz + br_if $break|1 + local.get $5 + i32.load16_u + local.set $7 + local.get $6 + i32.load16_u + local.set $8 + local.get $7 + local.get $8 + i32.ne + if + local.get $7 + local.get $8 + i32.sub + local.set $9 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $9 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $continue|1 + end + unreachable + end + i32.const 0 + local.set $8 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $8 + ) + (func $~lib/string/String.__eq (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $class-overloading-virtual/test (; 12 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) local.get $0 call $~lib/rt/stub/__retain local.set $0 @@ -170,15 +398,73 @@ if i32.const 0 i32.const 24 - i32.const 16 + i32.const 38 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $class-overloading-virtual/Foo#foo + local.tee $2 + i32.const 96 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 39 i32.const 2 call $~lib/builtins/abort unreachable end + local.get $2 + call $~lib/rt/stub/__release local.get $0 call $~lib/rt/stub/__release ) - (func $start:class-overloading-virtual (; 8 ;) (type $FUNCSIG$v) + (func $class-overloading-virtual/testBar (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + call $class-overloading-virtual/Bar#baz + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 52 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $class-overloading-virtual/Bar#foo + local.tee $3 + local.get $2 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 53 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $3 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + ) + (func $start:class-overloading-virtual (; 14 ;) (type $FUNCSIG$v) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -195,23 +481,65 @@ i32.const 0 call $class-overloading-virtual/Bar#constructor global.set $class-overloading-virtual/b + i32.const 0 + call $class-overloading-virtual/Baa#constructor + global.set $class-overloading-virtual/bb global.get $class-overloading-virtual/f i32.const 42 call $class-overloading-virtual/test global.get $class-overloading-virtual/b i32.const 84 call $class-overloading-virtual/test + global.get $class-overloading-virtual/bb + i32.const 168 + call $class-overloading-virtual/test + global.get $class-overloading-virtual/b + i32.const 84 + i32.const 128 + call $class-overloading-virtual/testBar + global.get $class-overloading-virtual/bb + i32.const 168 + i32.const 160 + call $class-overloading-virtual/testBar ) - (func $start (; 9 ;) (type $FUNCSIG$v) + (func $start (; 15 ;) (type $FUNCSIG$v) call $start:class-overloading-virtual ) - (func $class-overloading-virtual/Foo#baz~virtual (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $class-overloading-virtual/Foo#baz~virtual (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 42 ) - (func $class-overloading-virtual/Bar#baz (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $class-overloading-virtual/Baa#baz (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 168 + ) + (func $class-overloading-virtual/Foo#baz (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading-virtual/Foo#baz~virtual + return + end + local.get $0 + call $class-overloading-virtual/Bar#baz + return + end + local.get $0 + call $class-overloading-virtual/Baa#baz + return + ) + (func $class-overloading-virtual/Bar#baz~virtual (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 84 ) - (func $class-overloading-virtual/Foo#baz (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $class-overloading-virtual/Bar#baz (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -219,19 +547,45 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default end unreachable end local.get $0 - call $class-overloading-virtual/Foo#baz~virtual + call $class-overloading-virtual/Bar#baz~virtual return end local.get $0 - call $class-overloading-virtual/Bar#baz + call $class-overloading-virtual/Baa#baz + return + ) + (func $class-overloading-virtual/Bar#foo~virtual (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 128 + ) + (func $class-overloading-virtual/Baa#foo (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 160 + ) + (func $class-overloading-virtual/Bar#foo (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading-virtual/Bar#foo~virtual + return + end + local.get $0 + call $class-overloading-virtual/Baa#foo return ) - (func $null (; 13 ;) (type $FUNCSIG$v) + (func $null (; 24 ;) (type $FUNCSIG$v) unreachable ) ) From 57f6a05e8534a20034afefc391c0794f62b1125d Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 11 Dec 2019 12:40:39 -0500 Subject: [PATCH 39/47] update wat files --- tests/compiler/class-overloading-virtual.optimized.wat | 8 ++++---- tests/compiler/class-overloading-virtual.untouched.wat | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/compiler/class-overloading-virtual.optimized.wat b/tests/compiler/class-overloading-virtual.optimized.wat index 0ecaa70149..62cf8198db 100644 --- a/tests/compiler/class-overloading-virtual.optimized.wat +++ b/tests/compiler/class-overloading-virtual.optimized.wat @@ -239,7 +239,7 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 37 i32.const 2 call $~lib/builtins/abort unreachable @@ -251,7 +251,7 @@ if i32.const 0 i32.const 24 - i32.const 39 + i32.const 38 i32.const 2 call $~lib/builtins/abort unreachable @@ -265,7 +265,7 @@ if i32.const 0 i32.const 24 - i32.const 52 + i32.const 51 i32.const 2 call $~lib/builtins/abort unreachable @@ -295,7 +295,7 @@ if i32.const 0 i32.const 24 - i32.const 53 + i32.const 52 i32.const 2 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/class-overloading-virtual.untouched.wat b/tests/compiler/class-overloading-virtual.untouched.wat index d94ba48024..a834f84a60 100644 --- a/tests/compiler/class-overloading-virtual.untouched.wat +++ b/tests/compiler/class-overloading-virtual.untouched.wat @@ -398,7 +398,7 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 37 i32.const 2 call $~lib/builtins/abort unreachable @@ -412,7 +412,7 @@ if i32.const 0 i32.const 24 - i32.const 39 + i32.const 38 i32.const 2 call $~lib/builtins/abort unreachable @@ -438,7 +438,7 @@ if i32.const 0 i32.const 24 - i32.const 52 + i32.const 51 i32.const 2 call $~lib/builtins/abort unreachable @@ -452,7 +452,7 @@ if i32.const 0 i32.const 24 - i32.const 53 + i32.const 52 i32.const 2 call $~lib/builtins/abort unreachable From f83772647933ebb6a1866df5ff87618773560b84 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 11 Dec 2019 17:44:41 -0500 Subject: [PATCH 40/47] Added virtual decorator to index.d.ts --- std/assembly/index.d.ts | 3 +++ tests/compiler/class-overloading-virtual.ts | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 7446d93d2f..9b85e0543b 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1784,3 +1784,6 @@ declare function lazy(...args: any[]): any; /** Annotates a function as the explicit start function. */ declare function start(...args: any[]): any; + +/** Annotates a method to be virtually overloaded. */ +declare function virtual(...args: any[]): any; diff --git a/tests/compiler/class-overloading-virtual.ts b/tests/compiler/class-overloading-virtual.ts index e77a160c78..f34d9e5571 100644 --- a/tests/compiler/class-overloading-virtual.ts +++ b/tests/compiler/class-overloading-virtual.ts @@ -1,5 +1,4 @@ class Foo { - //@ts-ignore: decorator @virtual baz(): i32 { return 42; @@ -11,7 +10,6 @@ class Foo { } class Bar extends Foo { - //@ts-ignore @virtual baz(): i32 { return 84; From 04e9672a38550981c42b552f48b0ca34023de788 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 11 Dec 2019 17:50:22 -0500 Subject: [PATCH 41/47] Apparently removing comments changed the binary? --- tests/compiler/class-overloading-virtual.optimized.wat | 8 ++++---- tests/compiler/class-overloading-virtual.untouched.wat | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/compiler/class-overloading-virtual.optimized.wat b/tests/compiler/class-overloading-virtual.optimized.wat index 62cf8198db..e27aa70d96 100644 --- a/tests/compiler/class-overloading-virtual.optimized.wat +++ b/tests/compiler/class-overloading-virtual.optimized.wat @@ -239,7 +239,7 @@ if i32.const 0 i32.const 24 - i32.const 37 + i32.const 35 i32.const 2 call $~lib/builtins/abort unreachable @@ -251,7 +251,7 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 36 i32.const 2 call $~lib/builtins/abort unreachable @@ -265,7 +265,7 @@ if i32.const 0 i32.const 24 - i32.const 51 + i32.const 49 i32.const 2 call $~lib/builtins/abort unreachable @@ -295,7 +295,7 @@ if i32.const 0 i32.const 24 - i32.const 52 + i32.const 50 i32.const 2 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/class-overloading-virtual.untouched.wat b/tests/compiler/class-overloading-virtual.untouched.wat index a834f84a60..969d862371 100644 --- a/tests/compiler/class-overloading-virtual.untouched.wat +++ b/tests/compiler/class-overloading-virtual.untouched.wat @@ -398,7 +398,7 @@ if i32.const 0 i32.const 24 - i32.const 37 + i32.const 35 i32.const 2 call $~lib/builtins/abort unreachable @@ -412,7 +412,7 @@ if i32.const 0 i32.const 24 - i32.const 38 + i32.const 36 i32.const 2 call $~lib/builtins/abort unreachable @@ -438,7 +438,7 @@ if i32.const 0 i32.const 24 - i32.const 51 + i32.const 49 i32.const 2 call $~lib/builtins/abort unreachable @@ -452,7 +452,7 @@ if i32.const 0 i32.const 24 - i32.const 52 + i32.const 50 i32.const 2 call $~lib/builtins/abort unreachable From f65e9c52530cc06493ff43375688d11858c2ecb6 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 12 Dec 2019 15:10:48 -0500 Subject: [PATCH 42/47] Methods are virtual by default @final prevents virtual overloading --- src/ast.ts | 6 +- src/compiler.ts | 154 +++-- src/program.ts | 8 +- std/assembly/index.d.ts | 4 +- tests/compiler/abstract-method.optimized.wat | 8 +- tests/compiler/abstract-method.untouched.wat | 6 +- .../class-overloading-virtual.optimized.wat | 386 ------------ tests/compiler/class-overloading-virtual.ts | 54 -- .../class-overloading-virtual.untouched.wat | 591 ------------------ .../compiler/class-overloading.optimized.wat | 381 ++++++++++- tests/compiler/class-overloading.ts | 54 +- .../compiler/class-overloading.untouched.wat | 570 ++++++++++++++++- 12 files changed, 1117 insertions(+), 1105 deletions(-) delete mode 100644 tests/compiler/class-overloading-virtual.optimized.wat delete mode 100644 tests/compiler/class-overloading-virtual.ts delete mode 100644 tests/compiler/class-overloading-virtual.untouched.wat diff --git a/src/ast.ts b/src/ast.ts index 95061ba287..ee66c5f5dd 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -1175,7 +1175,7 @@ export enum DecoratorKind { BUILTIN, LAZY, UNSAFE, - VIRTUAL, + FINAL, } export namespace DecoratorKind { @@ -1220,8 +1220,8 @@ export namespace DecoratorKind { if (nameStr == "unsafe") return DecoratorKind.UNSAFE; break; } - case CharCode.v: { - if (nameStr == "virtual") return DecoratorKind.VIRTUAL; + case CharCode.f: { + if (nameStr == "final") return DecoratorKind.FINAL; break; } } diff --git a/src/compiler.ts b/src/compiler.ts index b0dae022bb..a6207c7d01 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1297,18 +1297,6 @@ export class Compiler extends DiagnosticEmitter { // concrete function if (bodyNode) { - // Check if instance method is virtual so that overloading will use dynamic dispatch - if (instance.prototype.isBound && instance.hasDecorator(DecoratorFlags.VIRTUAL) && !this.interfaceMethods.has(instance)) { - this.interfaceMethods.add(instance); - assert(instance.parent.kind == ElementKind.CLASS); - (instance.parent).addImplementer(instance.parent); - funcRef = module.addFunction( - instance.internalName, - typeRef, - null, - module.nop() - ); - }else { // must not be ambient if (instance.is(CommonFlags.AMBIENT)) { this.error( @@ -1369,6 +1357,16 @@ export class Compiler extends DiagnosticEmitter { typesToNativeTypes(instance.additionalLocals), flatten(module, stmts, instance.signature.returnType.toNativeType()) ); + + if (instance.prototype.isBound // Is bound to a class + && !instance.hasDecorator(DecoratorFlags.SEALED) // Not sealed + && !( instance.is(CommonFlags.PRIVATE) // Not private + || instance.hasDecorator(DecoratorFlags.FINAL)) // does not have a final decorator + ) { + this.interfaceMethods.add(instance); + assert(instance.parent.kind == ElementKind.CLASS); + // Add to the instance's class's implementing classes. + (instance.parent).addImplementer(instance.parent); } // Interface or Abstract Methods } else if (instance.is(CommonFlags.VIRTUAL)) { @@ -3090,11 +3088,11 @@ export class Compiler extends DiagnosticEmitter { ); // recoverable } } - } - - if (fromType.classReference && toType.classReference) { - if (fromType.classReference.extends(toType.classReference.prototype)) { - toType.classReference.addImplementer(fromType.classReference); + } else { // Otherwise "class From extends To" + if (fromType.classReference && toType.classReference) { + if (fromType.classReference.extends(toType.classReference.prototype)) { + toType.classReference.addImplementer(fromType.classReference); + } } } @@ -9420,10 +9418,48 @@ export class Compiler extends DiagnosticEmitter { */ compileVirtualMethods(): void { const module = this.module; + const nop = module.nop(); for (let ifunc of this.interfaceMethods) { - let classes = (ifunc.parent).implementers; + let allClasses = (ifunc.parent).implementers; + + // Skip constructors and if sigleton classes + if (!ifunc.isAny(CommonFlags.VIRTUAL | CommonFlags.ABSTRACT) + && (ifunc.is(CommonFlags.CONSTRUCTOR) + || allClasses.size == 1)) { + continue; + } + const name = ifunc.internalName; const signature = ifunc.signature; + + /** + * + */ + const funcs = new Map>(); + + const getClassSet = (func: Element): Set => { + if (!funcs.has(func)) { + funcs.set(func, new Set()); + } + return funcs.get(func)!; + }; + + for (let _class of allClasses) { + let prop = this.getMethodOrField(ifunc, _class); + if (prop.is(CommonFlags.ABSTRACT)) { + continue; + } + getClassSet(prop).add(_class); + } + + // Skip if method's class is the only implementer + if (funcs.size == 1 && !ifunc.is(CommonFlags.VIRTUAL)) { + continue; + } + + + // Remove Function + module.removeFunction(name); const returnType = signature.returnType; const typeRef = this.ensureSignature(signature); const relooper = this.module.createRelooper(); @@ -9436,13 +9472,14 @@ export class Compiler extends DiagnosticEmitter { relooper.addBranch(first, last); // Add branch cases - for (let _class of classes) { - let expr = this.compileInterfaceMethod(ifunc, _class); + for (let [prop, classes] of funcs) { + let expr = this.compileInterfaceMethod(ifunc, prop); if (!isVoid) { expr = module.return(expr); } const returnBlock = relooper.addBlock(expr); - relooper.addBranchForSwitch(first, returnBlock, [_class.id]); + let classIds = Array.from(classes).map(c => c.id); + relooper.addBranchForSwitch(first, returnBlock, classIds); } // finish relooper and prepare body of function @@ -9450,28 +9487,67 @@ export class Compiler extends DiagnosticEmitter { let block = isVoid ? [switchExpression] : [switchExpression, defaultVal]; let body = module.block(null, block, returnType.toNativeType()); - // if (ifunc.hasDecorator(DecoratorFlags.VIRTUAL)) { - // ifunc.internalName = ifunc.internalName.substr(0, ifunc.internalName.length - "~virtual".length); - // } // Remove the nop standin - module.removeFunction(name); module.addFunction(name, typeRef, null, body); } - } +} - compileInterfaceMethod(ifunc: Function, _class: Class): ExpressionRef { - const module = this.module; - var name: string = ifunc.name; - if (ifunc.isAny(CommonFlags.GET | CommonFlags.SET)) { + getClassMember(func: Function, _class: Class): Element { + var name: string = func.name; + if (func.isAny(CommonFlags.GET | CommonFlags.SET)) { name = name.substr("get:".length); } - var prop = _class.members!.get(name)!; + return _class.members!.get(name)!; + } + + getMethodOrField(func: Function, _class: Class): Element { + var prop = this.getClassMember(func, _class); + var method: Function; + switch (prop.kind){ + case ElementKind.FUNCTION_PROTOTYPE: { + let p = prop; + let newFunc = this.resolver.resolveFunction(p, null, (func.parent).contextualTypeArguments); + if (newFunc == null) { + throw new Error(`Couldn't resolve ${p.name}`); + } + prop = newFunc; + } + case ElementKind.FUNCTION: { + method = prop; + break; + } + case ElementKind.FIELD: { + let field = prop; + return field; + } + case ElementKind.PROPERTY: { + let p = prop; + if (func.is(CommonFlags.SET)) { + method = p.setterInstance!; + }else if (func.is(CommonFlags.GET)) { + method = p.getterInstance!; + }else { + throw Error("Interface method " + func.name + " should be a property"); + } + break; + + } + default: { + throw Error("Class " + _class.name + " must have property " + prop.name); + } + } + return method; + } + + compileInterfaceMethod(ifunc: Function, prop: Element): ExpressionRef { + const module = this.module; + // var prop = this.getClassMember(ifunc, _class); const returnType = ifunc!.signature.returnType.toNativeType(); var method: Function; switch (prop.kind){ case ElementKind.FUNCTION_PROTOTYPE: { let p = prop; - let newFunc = this.resolver.resolveFunction(p, null, (p.parent).contextualTypeArguments); + let newFunc = this.resolver.resolveFunction(p, null, (ifunc.parent).contextualTypeArguments); if (newFunc == null) { throw new Error(`Couldn't resolve ${p.name}`); } @@ -9526,25 +9602,27 @@ export class Compiler extends DiagnosticEmitter { } default: { - throw Error("Class " + _class.name + " must have property " + prop.name); + throw Error("Class " + ifunc.parent.name + " must have property " + prop.name); } } - var methodName = method.internalName; - + var origMethodName = method.internalName; /** - * If method is virtual it must be renamed to not overlap with actual implementation. + * If method is not virtual it must be renamed to not overlap with actual implementation. */ - if (ifunc.hasDecorator(DecoratorFlags.VIRTUAL) && ifunc.parent == method.parent) { + if (!method.is(CommonFlags.VIRTUAL) && ifunc.parent == method.parent) { method.internalName = method.internalName + "~virtual"; method.unset(CommonFlags.COMPILED); } + this.compileFunction(method); const locals: usize[] = []; for (let i: i32 = 0; i < ifunc.localsByIndex.length; i++) { const local = ifunc.localsByIndex[i]; locals.push(this.module.local_get(local.index, local.type.toNativeType())); } - return this.module.call(method.internalName, locals, returnType); + const callExpr = this.module.call(method.internalName, locals, returnType); + method.internalName = origMethodName; + return callExpr; } diff --git a/src/program.ts b/src/program.ts index d157a59443..f16cad015b 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1373,7 +1373,7 @@ export class Program extends DiagnosticEmitter { ): void { var name = declaration.name.text; var isStatic = declaration.is(CommonFlags.STATIC); - var acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE | DecoratorFlags.VIRTUAL; + var acceptedFlags = DecoratorFlags.INLINE | DecoratorFlags.UNSAFE | DecoratorFlags.FINAL; if (!declaration.is(CommonFlags.GENERIC)) { acceptedFlags |= DecoratorFlags.OPERATOR_BINARY | DecoratorFlags.OPERATOR_PREFIX @@ -2086,8 +2086,8 @@ export enum DecoratorFlags { LAZY = 1 << 9, /** Is considered unsafe code. */ UNSAFE = 1 << 10, - /** Is a virtual method when inherited. */ - VIRTUAL = 1 << 11, + /** Is a final method that is not virtualized. */ + FINAL = 1 << 11, } export namespace DecoratorFlags { @@ -2107,7 +2107,7 @@ export namespace DecoratorFlags { case DecoratorKind.BUILTIN: return DecoratorFlags.BUILTIN; case DecoratorKind.LAZY: return DecoratorFlags.LAZY; case DecoratorKind.UNSAFE: return DecoratorFlags.UNSAFE; - case DecoratorKind.VIRTUAL: return DecoratorFlags.VIRTUAL; + case DecoratorKind.FINAL: return DecoratorFlags.FINAL; default: return DecoratorFlags.NONE; } } diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 9b85e0543b..eb80356902 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1785,5 +1785,5 @@ declare function lazy(...args: any[]): any; /** Annotates a function as the explicit start function. */ declare function start(...args: any[]): any; -/** Annotates a method to be virtually overloaded. */ -declare function virtual(...args: any[]): any; +/** Annotates a method to not be virtually overloaded. */ +declare function final(...args: any[]): any; diff --git a/tests/compiler/abstract-method.optimized.wat b/tests/compiler/abstract-method.optimized.wat index 424ed933ba..9f8f6c2540 100644 --- a/tests/compiler/abstract-method.optimized.wat +++ b/tests/compiler/abstract-method.optimized.wat @@ -222,15 +222,15 @@ i32.load i32.const 4 i32.sub - br_table $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$case$4 $switch$1$case$3 $switch$1$case$3 $switch$1$default end unreachable end - local.get $0 - call $abstract-method/AAbstract#get:y + i32.const 42 return end - i32.const 42 + local.get $0 + call $abstract-method/AAbstract#get:y ) (func $null (; 11 ;) (type $FUNCSIG$v) unreachable diff --git a/tests/compiler/abstract-method.untouched.wat b/tests/compiler/abstract-method.untouched.wat index d03f9b7a68..c097555981 100644 --- a/tests/compiler/abstract-method.untouched.wat +++ b/tests/compiler/abstract-method.untouched.wat @@ -374,16 +374,16 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$case$3 $switch$1$case$3 $switch$1$default end unreachable end local.get $0 - call $abstract-method/AAbstract#get:y + call $abstract-method/SubAstract#get:y return end local.get $0 - call $abstract-method/SubAstract#get:y + call $abstract-method/AAbstract#get:y return ) (func $null (; 20 ;) (type $FUNCSIG$v) diff --git a/tests/compiler/class-overloading-virtual.optimized.wat b/tests/compiler/class-overloading-virtual.optimized.wat deleted file mode 100644 index e27aa70d96..0000000000 --- a/tests/compiler/class-overloading-virtual.optimized.wat +++ /dev/null @@ -1,386 +0,0 @@ -(module - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) - (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$v (func)) - (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (memory $0 1) - (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s") - (data (i32.const 80) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o") - (data (i32.const 112) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r") - (data (i32.const 144) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a") - (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) - (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $class-overloading-virtual/f (mut i32) (i32.const 0)) - (global $class-overloading-virtual/b (mut i32) (i32.const 0)) - (global $class-overloading-virtual/bb (mut i32) (i32.const 0)) - (export "memory" (memory $0)) - (export "test" (func $class-overloading-virtual/test)) - (export "testBar" (func $class-overloading-virtual/testBar)) - (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) - (local $1 i32) - (local $2 i32) - local.get $0 - memory.size - local.tee $2 - i32.const 16 - i32.shl - local.tee $1 - i32.gt_u - if - local.get $2 - local.get $0 - local.get $1 - i32.sub - i32.const 65535 - i32.add - i32.const -65536 - i32.and - i32.const 16 - i32.shr_u - local.tee $1 - local.get $2 - local.get $1 - i32.gt_s - select - memory.grow - i32.const 0 - i32.lt_s - if - local.get $1 - memory.grow - i32.const 0 - i32.lt_s - if - unreachable - end - end - end - local.get $0 - global.set $~lib/rt/stub/offset - ) - (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - global.get $~lib/rt/stub/offset - i32.const 16 - i32.add - local.tee $2 - i32.const 16 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $2 - i32.const 16 - i32.sub - local.tee $1 - i32.const 16 - i32.store - local.get $1 - i32.const -1 - i32.store offset=4 - local.get $1 - local.get $0 - i32.store offset=8 - local.get $1 - i32.const 0 - i32.store offset=12 - local.get $2 - ) - (func $class-overloading-virtual/Foo#constructor (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 3 - call $~lib/rt/stub/__alloc - local.set $0 - end - local.get $0 - ) - (func $class-overloading-virtual/Bar#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 4 - call $~lib/rt/stub/__alloc - local.set $0 - end - local.get $0 - call $class-overloading-virtual/Foo#constructor - ) - (func $~lib/string/String#get:length (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - i32.const 1 - i32.shr_u - ) - (func $~lib/util/string/compareImpl (; 6 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - (local $4 i32) - local.get $0 - i32.const 7 - i32.and - local.get $1 - i32.const 7 - i32.and - i32.or - i32.eqz - i32.const 0 - local.get $2 - i32.const 4 - i32.ge_u - select - if - loop $continue|0 - local.get $0 - i64.load - local.get $1 - i64.load - i64.eq - if - local.get $0 - i32.const 8 - i32.add - local.set $0 - local.get $1 - i32.const 8 - i32.add - local.set $1 - local.get $2 - i32.const 4 - i32.sub - local.tee $2 - i32.const 4 - i32.ge_u - br_if $continue|0 - end - end - end - loop $continue|1 - block $break|1 - local.get $2 - local.tee $3 - i32.const 1 - i32.sub - local.set $2 - local.get $3 - i32.eqz - br_if $break|1 - local.get $1 - i32.load16_u - local.tee $3 - local.get $0 - i32.load16_u - local.tee $4 - i32.ne - if - local.get $4 - local.get $3 - i32.sub - return - else - local.get $0 - i32.const 2 - i32.add - local.set $0 - local.get $1 - i32.const 2 - i32.add - local.set $1 - br $continue|1 - end - unreachable - end - end - i32.const 0 - ) - (func $~lib/string/String.__eq (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $0 - local.get $1 - i32.eq - if - i32.const 1 - return - end - block $folding-inner0 - local.get $1 - i32.eqz - i32.const 1 - local.get $0 - select - br_if $folding-inner0 - local.get $0 - call $~lib/string/String#get:length - local.tee $2 - local.get $1 - call $~lib/string/String#get:length - i32.ne - br_if $folding-inner0 - local.get $0 - local.get $1 - local.get $2 - call $~lib/util/string/compareImpl - i32.eqz - return - end - i32.const 0 - ) - (func $class-overloading-virtual/test (; 8 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - local.get $0 - call $class-overloading-virtual/Foo#baz - local.get $1 - i32.ne - if - i32.const 0 - i32.const 24 - i32.const 35 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - i32.const 96 - i32.const 96 - call $~lib/string/String.__eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 36 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - ) - (func $class-overloading-virtual/testBar (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - local.get $0 - call $class-overloading-virtual/Bar#baz - local.get $1 - i32.ne - if - i32.const 0 - i32.const 24 - i32.const 49 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - block $__inlined_func$class-overloading-virtual/Bar#foo (result i32) - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 4 - i32.sub - br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default - end - unreachable - end - i32.const 128 - br $__inlined_func$class-overloading-virtual/Bar#foo - end - i32.const 160 - end - local.get $2 - call $~lib/string/String.__eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 50 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - ) - (func $start:class-overloading-virtual (; 10 ;) (type $FUNCSIG$v) - i32.const 176 - global.set $~lib/rt/stub/startOffset - i32.const 176 - global.set $~lib/rt/stub/offset - i32.const 0 - call $class-overloading-virtual/Foo#constructor - global.set $class-overloading-virtual/f - i32.const 0 - call $class-overloading-virtual/Bar#constructor - global.set $class-overloading-virtual/b - i32.const 5 - call $~lib/rt/stub/__alloc - call $class-overloading-virtual/Bar#constructor - global.set $class-overloading-virtual/bb - global.get $class-overloading-virtual/f - i32.const 42 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/b - i32.const 84 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/bb - i32.const 168 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/b - i32.const 84 - i32.const 128 - call $class-overloading-virtual/testBar - global.get $class-overloading-virtual/bb - i32.const 168 - i32.const 160 - call $class-overloading-virtual/testBar - ) - (func $start (; 11 ;) (type $FUNCSIG$v) - call $start:class-overloading-virtual - ) - (func $class-overloading-virtual/Foo#baz (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$5 - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 3 - i32.sub - br_table $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default - end - unreachable - end - i32.const 42 - return - end - local.get $0 - call $class-overloading-virtual/Bar#baz - return - end - i32.const 168 - ) - (func $class-overloading-virtual/Bar#baz (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 4 - i32.sub - br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default - end - unreachable - end - i32.const 84 - return - end - i32.const 168 - ) - (func $null (; 14 ;) (type $FUNCSIG$v) - unreachable - ) -) diff --git a/tests/compiler/class-overloading-virtual.ts b/tests/compiler/class-overloading-virtual.ts deleted file mode 100644 index f34d9e5571..0000000000 --- a/tests/compiler/class-overloading-virtual.ts +++ /dev/null @@ -1,54 +0,0 @@ -class Foo { - @virtual - baz(): i32 { - return 42; - } - - foo(): string { - return "In Foo"; - } -} - -class Bar extends Foo { - @virtual - baz(): i32 { - return 84; - } - - @virtual - foo(): string { - return "In Bar"; - } -} - -class Baa extends Bar { - baz(): i32 { - return 168; - } - - foo(): string { - return "In Baa"; - } -} - -export function test(foo: Foo, e1: i32): void { - assert(foo.baz() == e1); - assert(foo.foo() == "In Foo"); -} - -const f = new Foo(); -const b = new Bar(); -const bb = new Baa(); - -test(f, 42); // calls Foo's baz -test(b, 84); // calls Bar's baz -test(bb, 168); - -export function testBar(foo: Bar, e1: i32, e2: string): void { - //@ts-ignore - assert(foo.baz() == e1); - assert(foo.foo() == e2); -} - -testBar(b, 84, "In Bar"); // calls Bar's baz -testBar(bb, 168, "In Baa"); diff --git a/tests/compiler/class-overloading-virtual.untouched.wat b/tests/compiler/class-overloading-virtual.untouched.wat deleted file mode 100644 index 969d862371..0000000000 --- a/tests/compiler/class-overloading-virtual.untouched.wat +++ /dev/null @@ -1,591 +0,0 @@ -(module - (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) - (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) - (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$v (func)) - (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) - (memory $0 1) - (data (i32.const 8) "8\00\00\00\01\00\00\00\01\00\00\008\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00-\00v\00i\00r\00t\00u\00a\00l\00.\00t\00s\00") - (data (i32.const 80) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o\00") - (data (i32.const 112) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r\00") - (data (i32.const 144) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a\00") - (table $0 1 funcref) - (elem (i32.const 0) $null) - (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) - (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) - (global $class-overloading-virtual/f (mut i32) (i32.const 0)) - (global $class-overloading-virtual/b (mut i32) (i32.const 0)) - (global $class-overloading-virtual/bb (mut i32) (i32.const 0)) - (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 172)) - (export "memory" (memory $0)) - (export "test" (func $class-overloading-virtual/test)) - (export "testBar" (func $class-overloading-virtual/testBar)) - (start $start) - (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) - (local $1 i32) - (local $2 i32) - (local $3 i32) - (local $4 i32) - (local $5 i32) - memory.size - local.set $1 - local.get $1 - i32.const 16 - i32.shl - local.set $2 - local.get $0 - local.get $2 - i32.gt_u - if - local.get $0 - local.get $2 - i32.sub - i32.const 65535 - i32.add - i32.const 65535 - i32.const -1 - i32.xor - i32.and - i32.const 16 - i32.shr_u - local.set $3 - local.get $1 - local.tee $4 - local.get $3 - local.tee $5 - local.get $4 - local.get $5 - i32.gt_s - select - local.set $4 - local.get $4 - memory.grow - i32.const 0 - i32.lt_s - if - local.get $3 - memory.grow - i32.const 0 - i32.lt_s - if - unreachable - end - end - end - local.get $0 - global.set $~lib/rt/stub/offset - ) - (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 - i32.const 1073741808 - i32.gt_u - if - unreachable - end - global.get $~lib/rt/stub/offset - i32.const 16 - i32.add - local.set $2 - local.get $0 - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - local.tee $3 - i32.const 16 - local.tee $4 - local.get $3 - local.get $4 - i32.gt_u - select - local.set $5 - local.get $2 - local.get $5 - i32.add - call $~lib/rt/stub/maybeGrowMemory - local.get $2 - i32.const 16 - i32.sub - local.set $6 - local.get $6 - local.get $5 - i32.store - local.get $6 - i32.const -1 - i32.store offset=4 - local.get $6 - local.get $1 - i32.store offset=8 - local.get $6 - local.get $0 - i32.store offset=12 - local.get $2 - ) - (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - ) - (func $class-overloading-virtual/Foo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 0 - i32.const 3 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - ) - (func $class-overloading-virtual/Bar#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 0 - i32.const 4 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - call $class-overloading-virtual/Foo#constructor - local.set $0 - local.get $0 - ) - (func $class-overloading-virtual/Baa#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.eqz - if - i32.const 0 - i32.const 5 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - call $class-overloading-virtual/Bar#constructor - local.set $0 - local.get $0 - ) - (func $class-overloading-virtual/Foo#foo (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 96 - ) - (func $~lib/rt/stub/__release (; 8 ;) (type $FUNCSIG$vi) (param $0 i32) - nop - ) - (func $~lib/string/String#get:length (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - i32.const 16 - i32.sub - i32.load offset=12 - i32.const 1 - i32.shr_u - ) - (func $~lib/util/string/compareImpl (; 10 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) - (local $5 i32) - (local $6 i32) - (local $7 i32) - (local $8 i32) - (local $9 i32) - local.get $0 - call $~lib/rt/stub/__retain - local.set $0 - local.get $2 - call $~lib/rt/stub/__retain - local.set $2 - local.get $0 - local.get $1 - i32.const 1 - i32.shl - i32.add - local.set $5 - local.get $2 - local.get $3 - i32.const 1 - i32.shl - i32.add - local.set $6 - local.get $4 - i32.const 4 - i32.ge_u - if (result i32) - local.get $5 - i32.const 7 - i32.and - local.get $6 - i32.const 7 - i32.and - i32.or - i32.eqz - else - i32.const 0 - end - if - block $break|0 - loop $continue|0 - local.get $5 - i64.load - local.get $6 - i64.load - i64.ne - if - br $break|0 - end - local.get $5 - i32.const 8 - i32.add - local.set $5 - local.get $6 - i32.const 8 - i32.add - local.set $6 - local.get $4 - i32.const 4 - i32.sub - local.set $4 - local.get $4 - i32.const 4 - i32.ge_u - br_if $continue|0 - end - end - end - block $break|1 - loop $continue|1 - local.get $4 - local.tee $7 - i32.const 1 - i32.sub - local.set $4 - local.get $7 - i32.eqz - br_if $break|1 - local.get $5 - i32.load16_u - local.set $7 - local.get $6 - i32.load16_u - local.set $8 - local.get $7 - local.get $8 - i32.ne - if - local.get $7 - local.get $8 - i32.sub - local.set $9 - local.get $0 - call $~lib/rt/stub/__release - local.get $2 - call $~lib/rt/stub/__release - local.get $9 - return - end - local.get $5 - i32.const 2 - i32.add - local.set $5 - local.get $6 - i32.const 2 - i32.add - local.set $6 - br $continue|1 - end - unreachable - end - i32.const 0 - local.set $8 - local.get $0 - call $~lib/rt/stub/__release - local.get $2 - call $~lib/rt/stub/__release - local.get $8 - ) - (func $~lib/string/String.__eq (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - (local $3 i32) - local.get $0 - call $~lib/rt/stub/__retain - local.set $0 - local.get $1 - call $~lib/rt/stub/__retain - local.set $1 - local.get $0 - local.get $1 - i32.eq - if - i32.const 1 - local.set $2 - local.get $0 - call $~lib/rt/stub/__release - local.get $1 - call $~lib/rt/stub/__release - local.get $2 - return - end - local.get $0 - i32.const 0 - i32.eq - if (result i32) - i32.const 1 - else - local.get $1 - i32.const 0 - i32.eq - end - if - i32.const 0 - local.set $2 - local.get $0 - call $~lib/rt/stub/__release - local.get $1 - call $~lib/rt/stub/__release - local.get $2 - return - end - local.get $0 - call $~lib/string/String#get:length - local.set $3 - local.get $3 - local.get $1 - call $~lib/string/String#get:length - i32.ne - if - i32.const 0 - local.set $2 - local.get $0 - call $~lib/rt/stub/__release - local.get $1 - call $~lib/rt/stub/__release - local.get $2 - return - end - local.get $0 - i32.const 0 - local.get $1 - i32.const 0 - local.get $3 - call $~lib/util/string/compareImpl - i32.eqz - local.set $2 - local.get $0 - call $~lib/rt/stub/__release - local.get $1 - call $~lib/rt/stub/__release - local.get $2 - ) - (func $class-overloading-virtual/test (; 12 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - (local $2 i32) - local.get $0 - call $~lib/rt/stub/__retain - local.set $0 - local.get $0 - call $class-overloading-virtual/Foo#baz - local.get $1 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 35 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $0 - call $class-overloading-virtual/Foo#foo - local.tee $2 - i32.const 96 - call $~lib/string/String.__eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 36 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $2 - call $~lib/rt/stub/__release - local.get $0 - call $~lib/rt/stub/__release - ) - (func $class-overloading-virtual/testBar (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) - (local $3 i32) - local.get $0 - call $~lib/rt/stub/__retain - local.set $0 - local.get $2 - call $~lib/rt/stub/__retain - local.set $2 - local.get $0 - call $class-overloading-virtual/Bar#baz - local.get $1 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 49 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $0 - call $class-overloading-virtual/Bar#foo - local.tee $3 - local.get $2 - call $~lib/string/String.__eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 50 - i32.const 2 - call $~lib/builtins/abort - unreachable - end - local.get $3 - call $~lib/rt/stub/__release - local.get $0 - call $~lib/rt/stub/__release - local.get $2 - call $~lib/rt/stub/__release - ) - (func $start:class-overloading-virtual (; 14 ;) (type $FUNCSIG$v) - global.get $~lib/heap/__heap_base - i32.const 15 - i32.add - i32.const 15 - i32.const -1 - i32.xor - i32.and - global.set $~lib/rt/stub/startOffset - global.get $~lib/rt/stub/startOffset - global.set $~lib/rt/stub/offset - i32.const 0 - call $class-overloading-virtual/Foo#constructor - global.set $class-overloading-virtual/f - i32.const 0 - call $class-overloading-virtual/Bar#constructor - global.set $class-overloading-virtual/b - i32.const 0 - call $class-overloading-virtual/Baa#constructor - global.set $class-overloading-virtual/bb - global.get $class-overloading-virtual/f - i32.const 42 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/b - i32.const 84 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/bb - i32.const 168 - call $class-overloading-virtual/test - global.get $class-overloading-virtual/b - i32.const 84 - i32.const 128 - call $class-overloading-virtual/testBar - global.get $class-overloading-virtual/bb - i32.const 168 - i32.const 160 - call $class-overloading-virtual/testBar - ) - (func $start (; 15 ;) (type $FUNCSIG$v) - call $start:class-overloading-virtual - ) - (func $class-overloading-virtual/Foo#baz~virtual (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 42 - ) - (func $class-overloading-virtual/Baa#baz (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 168 - ) - (func $class-overloading-virtual/Foo#baz (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$5 - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default - end - unreachable - end - local.get $0 - call $class-overloading-virtual/Foo#baz~virtual - return - end - local.get $0 - call $class-overloading-virtual/Bar#baz - return - end - local.get $0 - call $class-overloading-virtual/Baa#baz - return - ) - (func $class-overloading-virtual/Bar#baz~virtual (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 84 - ) - (func $class-overloading-virtual/Bar#baz (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default - end - unreachable - end - local.get $0 - call $class-overloading-virtual/Bar#baz~virtual - return - end - local.get $0 - call $class-overloading-virtual/Baa#baz - return - ) - (func $class-overloading-virtual/Bar#foo~virtual (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 128 - ) - (func $class-overloading-virtual/Baa#foo (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 160 - ) - (func $class-overloading-virtual/Bar#foo (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default - end - unreachable - end - local.get $0 - call $class-overloading-virtual/Bar#foo~virtual - return - end - local.get $0 - call $class-overloading-virtual/Baa#foo - return - ) - (func $null (; 24 ;) (type $FUNCSIG$v) - unreachable - ) -) diff --git a/tests/compiler/class-overloading.optimized.wat b/tests/compiler/class-overloading.optimized.wat index 048fa39844..d9214d4f36 100644 --- a/tests/compiler/class-overloading.optimized.wat +++ b/tests/compiler/class-overloading.optimized.wat @@ -1,13 +1,386 @@ (module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$v (func)) - (memory $0 0) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00.\00t\00s") + (data (i32.const 64) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o") + (data (i32.const 96) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r") + (data (i32.const 128) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a") + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $class-overloading/f (mut i32) (i32.const 0)) + (global $class-overloading/b (mut i32) (i32.const 0)) + (global $class-overloading/bb (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "test" (func $class-overloading/test)) - (func $class-overloading/test (; 0 ;) (type $FUNCSIG$vi) (param $0 i32) - nop + (export "testBar" (func $class-overloading/testBar)) + (start $start) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + memory.size + local.tee $2 + i32.const 16 + i32.shl + local.tee $1 + i32.gt_u + if + local.get $2 + local.get $0 + local.get $1 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $1 + local.get $2 + local.get $1 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $1 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset ) - (func $null (; 1 ;) (type $FUNCSIG$v) + (func $~lib/rt/stub/__alloc (; 2 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $2 + i32.const 16 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.tee $1 + i32.const 16 + i32.store + local.get $1 + i32.const -1 + i32.store offset=4 + local.get $1 + local.get $0 + i32.store offset=8 + local.get $1 + i32.const 0 + i32.store offset=12 + local.get $2 + ) + (func $class-overloading/Foo#constructor (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + ) + (func $class-overloading/Bar#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + call $class-overloading/Foo#constructor + ) + (func $~lib/string/String#get:length (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 6 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.const 7 + i32.and + local.get $1 + i32.const 7 + i32.and + i32.or + i32.eqz + i32.const 0 + local.get $2 + i32.const 4 + i32.ge_u + select + if + loop $continue|0 + local.get $0 + i64.load + local.get $1 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $1 + i32.const 8 + i32.add + local.set $1 + local.get $2 + i32.const 4 + i32.sub + local.tee $2 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + loop $continue|1 + block $break|1 + local.get $2 + local.tee $3 + i32.const 1 + i32.sub + local.set $2 + local.get $3 + i32.eqz + br_if $break|1 + local.get $1 + i32.load16_u + local.tee $3 + local.get $0 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $4 + local.get $3 + i32.sub + return + else + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $1 + i32.const 2 + i32.add + local.set $1 + br $continue|1 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/string/String.__eq (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + return + end + block $folding-inner0 + local.get $1 + i32.eqz + i32.const 1 + local.get $0 + select + br_if $folding-inner0 + local.get $0 + call $~lib/string/String#get:length + local.tee $2 + local.get $1 + call $~lib/string/String#get:length + i32.ne + br_if $folding-inner0 + local.get $0 + local.get $1 + local.get $2 + call $~lib/util/string/compareImpl + i32.eqz + return + end + i32.const 0 + ) + (func $class-overloading/test (; 8 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + call $class-overloading/Foo#baz + local.get $1 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 33 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + i32.const 80 + i32.const 80 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 34 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $class-overloading/testBar (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $0 + call $class-overloading/Bar#baz + local.get $1 + i32.ne + if + i32.const 0 + i32.const 24 + i32.const 47 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + block $__inlined_func$class-overloading/Bar#foo (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + i32.const 112 + br $__inlined_func$class-overloading/Bar#foo + end + i32.const 144 + end + local.get $2 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 48 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + ) + (func $start:class-overloading (; 10 ;) (type $FUNCSIG$v) + i32.const 160 + global.set $~lib/rt/stub/startOffset + i32.const 160 + global.set $~lib/rt/stub/offset + i32.const 0 + call $class-overloading/Foo#constructor + global.set $class-overloading/f + i32.const 0 + call $class-overloading/Bar#constructor + global.set $class-overloading/b + i32.const 5 + call $~lib/rt/stub/__alloc + call $class-overloading/Bar#constructor + global.set $class-overloading/bb + global.get $class-overloading/f + i32.const 42 + call $class-overloading/test + global.get $class-overloading/b + i32.const 84 + call $class-overloading/test + global.get $class-overloading/bb + i32.const 168 + call $class-overloading/test + global.get $class-overloading/b + i32.const 84 + i32.const 112 + call $class-overloading/testBar + global.get $class-overloading/bb + i32.const 168 + i32.const 144 + call $class-overloading/testBar + ) + (func $start (; 11 ;) (type $FUNCSIG$v) + call $start:class-overloading + ) + (func $class-overloading/Foo#baz (; 12 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 3 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default + end + unreachable + end + i32.const 42 + return + end + local.get $0 + call $class-overloading/Bar#baz + return + end + i32.const 168 + ) + (func $class-overloading/Bar#baz (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + br_table $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + i32.const 84 + return + end + i32.const 168 + ) + (func $null (; 14 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/class-overloading.ts b/tests/compiler/class-overloading.ts index bbd64ac5c6..4f16a550b8 100644 --- a/tests/compiler/class-overloading.ts +++ b/tests/compiler/class-overloading.ts @@ -1,12 +1,52 @@ class Foo { - baz(): void {} + baz(): i32 { + return 42; + } + + @final + foo(): string { + return "In Foo"; + } } + class Bar extends Foo { - baz(): void {} + baz(): i32 { + return 84; + } + + foo(): string { + return "In Bar"; + } } -export function test(foo: Foo): void { - foo.baz(); + +class Baa extends Bar { + baz(): i32 { + return 168; + } + + foo(): string { + return "In Baa"; + } } -// FIXME: this results in a call to Foo.baz instead of Bar.baz above. -// ultimately, overloaded functions should implicitly become virtual. -test(changetype(0)); + +export function test(foo: Foo, e1: i32): void { + assert(foo.baz() == e1); + assert(foo.foo() == "In Foo"); +} + +const f = new Foo(); +const b = new Bar(); +const bb = new Baa(); + +test(f, 42); // calls Foo's baz +test(b, 84); // calls Bar's baz +test(bb, 168); + +export function testBar(foo: Bar, e1: i32, e2: string): void { + //@ts-ignore + assert(foo.baz() == e1); + assert(foo.foo() == e2); +} + +testBar(b, 84, "In Bar"); // calls Bar's baz +testBar(bb, 168, "In Baa"); diff --git a/tests/compiler/class-overloading.untouched.wat b/tests/compiler/class-overloading.untouched.wat index 7b605a30eb..adca2a8866 100644 --- a/tests/compiler/class-overloading.untouched.wat +++ b/tests/compiler/class-overloading.untouched.wat @@ -1,39 +1,591 @@ (module + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$viii (func (param i32 i32 i32))) (type $FUNCSIG$v (func)) - (memory $0 0) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 8) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00c\00l\00a\00s\00s\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00.\00t\00s\00") + (data (i32.const 64) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00F\00o\00o\00") + (data (i32.const 96) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00r\00") + (data (i32.const 128) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00I\00n\00 \00B\00a\00a\00") (table $0 1 funcref) (elem (i32.const 0) $null) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $class-overloading/f (mut i32) (i32.const 0)) + (global $class-overloading/b (mut i32) (i32.const 0)) + (global $class-overloading/bb (mut i32) (i32.const 0)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 156)) (export "memory" (memory $0)) (export "test" (func $class-overloading/test)) + (export "testBar" (func $class-overloading/testBar)) (start $start) - (func $~lib/rt/stub/__retain (; 0 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset ) - (func $class-overloading/Foo#baz (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) - nop + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$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.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + local.get $6 + i32.const -1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $class-overloading/Foo#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + ) + (func $class-overloading/Bar#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $class-overloading/Foo#constructor + local.set $0 + local.get $0 + ) + (func $class-overloading/Baa#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 0 + i32.const 5 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + call $class-overloading/Bar#constructor + local.set $0 + local.get $0 + ) + (func $class-overloading/Foo#foo (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 80 ) - (func $~lib/rt/stub/__release (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/stub/__release (; 8 ;) (type $FUNCSIG$vi) (param $0 i32) nop ) - (func $class-overloading/test (; 3 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/string/String#get:length (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (; 10 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $break|0 + loop $continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + br_if $continue|0 + end + end + end + block $break|1 + loop $continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + i32.eqz + br_if $break|1 + local.get $5 + i32.load16_u + local.set $7 + local.get $6 + i32.load16_u + local.set $8 + local.get $7 + local.get $8 + i32.ne + if + local.get $7 + local.get $8 + i32.sub + local.set $9 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $9 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $continue|1 + end + unreachable + end + i32.const 0 + local.set $8 + local.get $0 + call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release + local.get $8 + ) + (func $~lib/string/String.__eq (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/stub/__release + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $class-overloading/test (; 12 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) local.get $0 call $~lib/rt/stub/__retain local.set $0 local.get $0 call $class-overloading/Foo#baz + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 33 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $class-overloading/Foo#foo + local.tee $2 + i32.const 80 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 34 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $2 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + ) + (func $class-overloading/testBar (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + call $class-overloading/Bar#baz + local.get $1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 47 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $class-overloading/Bar#foo + local.tee $3 + local.get $2 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 48 + i32.const 2 + call $~lib/builtins/abort + unreachable + end + local.get $3 + call $~lib/rt/stub/__release local.get $0 call $~lib/rt/stub/__release + local.get $2 + call $~lib/rt/stub/__release ) - (func $start:class-overloading (; 4 ;) (type $FUNCSIG$v) + (func $start:class-overloading (; 14 ;) (type $FUNCSIG$v) + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + call $class-overloading/Foo#constructor + global.set $class-overloading/f i32.const 0 + call $class-overloading/Bar#constructor + global.set $class-overloading/b + i32.const 0 + call $class-overloading/Baa#constructor + global.set $class-overloading/bb + global.get $class-overloading/f + i32.const 42 + call $class-overloading/test + global.get $class-overloading/b + i32.const 84 + call $class-overloading/test + global.get $class-overloading/bb + i32.const 168 call $class-overloading/test + global.get $class-overloading/b + i32.const 84 + i32.const 112 + call $class-overloading/testBar + global.get $class-overloading/bb + i32.const 168 + i32.const 144 + call $class-overloading/testBar ) - (func $start (; 5 ;) (type $FUNCSIG$v) + (func $start (; 15 ;) (type $FUNCSIG$v) call $start:class-overloading ) - (func $null (; 6 ;) (type $FUNCSIG$v) + (func $class-overloading/Foo#baz~virtual (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 42 + ) + (func $class-overloading/Baa#baz (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 168 + ) + (func $class-overloading/Foo#baz (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$case$5 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading/Foo#baz~virtual + return + end + local.get $0 + call $class-overloading/Bar#baz + return + end + local.get $0 + call $class-overloading/Baa#baz + return + ) + (func $class-overloading/Bar#baz~virtual (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 84 + ) + (func $class-overloading/Bar#baz (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading/Bar#baz~virtual + return + end + local.get $0 + call $class-overloading/Baa#baz + return + ) + (func $class-overloading/Bar#foo~virtual (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 112 + ) + (func $class-overloading/Baa#foo (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 144 + ) + (func $class-overloading/Bar#foo (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $class-overloading/Bar#foo~virtual + return + end + local.get $0 + call $class-overloading/Baa#foo + return + ) + (func $null (; 24 ;) (type $FUNCSIG$v) unreachable ) ) From a54936048e8ab2102fe2362fcc392e634a17ca25 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 12 Dec 2019 16:02:06 -0500 Subject: [PATCH 43/47] pass linter --- src/compiler.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index a6207c7d01..2ee8d3da71 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9433,7 +9433,7 @@ export class Compiler extends DiagnosticEmitter { const signature = ifunc.signature; /** - * + * Maps functions and fields to classes that use it */ const funcs = new Map>(); @@ -9457,7 +9457,6 @@ export class Compiler extends DiagnosticEmitter { continue; } - // Remove Function module.removeFunction(name); const returnType = signature.returnType; @@ -9478,7 +9477,7 @@ export class Compiler extends DiagnosticEmitter { expr = module.return(expr); } const returnBlock = relooper.addBlock(expr); - let classIds = Array.from(classes).map(c => c.id); + let classIds = Array.from(classes).map((c: Class) => c.id); relooper.addBranchForSwitch(first, returnBlock, classIds); } From 767124a8fb71c7b35597cf92f1994a5a9171d806 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 12 Dec 2019 18:22:51 -0500 Subject: [PATCH 44/47] nits --- src/compiler.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 2ee8d3da71..e1bd099b89 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1396,7 +1396,6 @@ export class Compiler extends DiagnosticEmitter { ); } funcRef = module.getFunction(instance.internalName); - instance.finalize(module, funcRef); this.currentType = previousType; return true; @@ -9418,11 +9417,10 @@ export class Compiler extends DiagnosticEmitter { */ compileVirtualMethods(): void { const module = this.module; - const nop = module.nop(); for (let ifunc of this.interfaceMethods) { let allClasses = (ifunc.parent).implementers; - // Skip constructors and if sigleton classes + // Skip constructors and sigleton classes if (!ifunc.isAny(CommonFlags.VIRTUAL | CommonFlags.ABSTRACT) && (ifunc.is(CommonFlags.CONSTRUCTOR) || allClasses.size == 1)) { @@ -9464,10 +9462,10 @@ export class Compiler extends DiagnosticEmitter { const relooper = this.module.createRelooper(); const isVoid = returnType.toNativeType() == NativeType.None; - // Condition to switch on const first = relooper.addBlockWithSwitch(module.nop(), this.loadClassID()); const defaultVal = defaultTypeValue(returnType.toNativeType(), module); const last = relooper.addBlock(module.unreachable()); + // default branch relooper.addBranch(first, last); // Add branch cases From 9111134aac1c9d44b5cd41a264f64b62743066a8 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 13 Dec 2019 11:35:46 -0500 Subject: [PATCH 45/47] Updates to iterators and map/set/array.from Also fixed issue with extending interfaces --- src/program.ts | 20 +- std/assembly/array.ts | 19 +- std/assembly/index.d.ts | 12 +- std/assembly/iterator.ts | 30 +- std/assembly/map.ts | 40 +- std/assembly/set.ts | 46 +- tests/compiler/std/iterator.optimized.wat | 1197 ++++++++++++---- tests/compiler/std/iterator.ts | 64 +- tests/compiler/std/iterator.untouched.wat | 1539 +++++++++++++++++---- tests/compiler/std/map.optimized.wat | 16 +- tests/compiler/std/map.untouched.wat | 20 +- tests/compiler/std/symbol.optimized.wat | 4 +- tests/compiler/std/symbol.untouched.wat | 4 +- 13 files changed, 2384 insertions(+), 627 deletions(-) diff --git a/src/program.ts b/src/program.ts index f16cad015b..696aab2721 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1288,13 +1288,6 @@ export class Program extends DiagnosticEmitter { ); } } else if (numImplementsTypes) { - // remember classes that implement interfaces - // for (let i = 0; i < numImplementsTypes; ++i) { - // this.warning( // TODO: not yet supported - // DiagnosticCode.Operation_not_supported, - // implementsTypes[i].range - // ); - // } queuedImplements.push(element); } } @@ -3722,6 +3715,19 @@ export class Interface extends Class { // FIXME true ); } + // Overrides class.addImplementer for casses when implementer is also interfaces + addImplementer(_class: Class): void { + if (_class.kind == ElementKind.INTERFACE) { + _class.implementers.forEach((_class: Class) => { + this.addImplementer(_class); + }); + if (this.base != null) { + this.base.addImplementer(_class); + } + } else { + super.addImplementer(_class); + } + } } /** Registers a concrete element with a program. */ diff --git a/std/assembly/array.ts b/std/assembly/array.ts index c5e07a7d1a..36e361a859 100644 --- a/std/assembly/array.ts +++ b/std/assembly/array.ts @@ -489,16 +489,21 @@ export class Array extends ArrayBufferView { return this.join(); } - static from(iter: Iterator): Array { - var arr = new Array(); + static from(iterable: Iterable, mapFn: ((t: T) => U) | null = null): Array { + const arr = new Array(); + const iter = iterable.iterator; var res = iter.next(); - var len = 0; - while (!res.done){ - arr.push(res.value); + var length = 0; + while (!res.done) { + if (mapFn) { + arr[length++] = mapFn(res.value); + } else { + //@ts-ignore U = T + arr[length++] = res.value; + } res = iter.next(); - len++; } - arr.length = len; + arr.length = length; return arr; } diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index eb80356902..e36abf44eb 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1357,7 +1357,7 @@ declare class Float64Array extends TypedArray { /** Class representing a sequence of values of type `T`. */ declare class Array { // TODO: Add iterable types - static from(iterator: any): T[]; + static from(iteratable: Iterable): Array; /** Tests if a value is an array. */ static isArray(value: any): value is Array; @@ -1535,7 +1535,7 @@ interface Iterator { } interface Iterable { - iterator: Iterator; + readonly iterator: Iterator; } interface IterableIterator extends Iterator { @@ -1548,15 +1548,15 @@ declare class MapEntry { } declare class Map { - entries(): Iterator> + entries(): IterableIterator> readonly size: i32; has(key: K): bool; set(key: K, value: V): void; get(key: K): V; delete(key: K): bool; clear(): void; - keys(): Iterator; - values(): Iterator; + keys(): IterableIterator; + values(): IterableIterator; toString(): string; } @@ -1566,7 +1566,7 @@ declare class Set { add(value: K): void; delete(value: K): bool; clear(): void; - values(): K[]; // preliminary + values(): IterableIterator; // preliminary toString(): string; } diff --git a/std/assembly/iterator.ts b/std/assembly/iterator.ts index 4eef898992..97cf4dfdd4 100644 --- a/std/assembly/iterator.ts +++ b/std/assembly/iterator.ts @@ -8,33 +8,9 @@ export interface IteratorResult { } export interface Iterator { - - // private constructor(iterable: Iterable) { - // } - - // TODO: these need to evaluate the classId at the respective reference in order to obtain the - // next value, i.e. arrays work differently than maps. we'd then have: - // - // ╒═══════════════════ Iterator layout (32-bit) ══════════════════╕ - // 3 2 1 - // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits - // ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ - // │ index │ - // ├─────────────────────────────────────────────────────────┬───┬─┤ - // │ reference │ 0 │D│ - // └─────────────────────────────────────────────────────────┴───┴─┘ - // D: Done flag - - // get value(this: u64): T { - // ? - // } - - // next(this: u64): Iterator { - // ? - // } - - next(): IteratorResult; +} - +export interface IterableIterator extends Iterator { + readonly iterator: IterableIterator; } diff --git a/std/assembly/map.ts b/std/assembly/map.ts index 15815e6c5b..527724d926 100644 --- a/std/assembly/map.ts +++ b/std/assembly/map.ts @@ -62,9 +62,9 @@ function ENTRY_SIZE(): usize { return size; } -class EntriesIter implements Iterator> { - private index: usize = 0; - constructor(private _map: Map, protected start: usize, protected size: usize){} +class EntriesIter implements IterableIterator> { + private index: usize = -1; + constructor(protected start: usize, protected size: usize) {} get done(): bool { return this.index >= this.size; @@ -79,18 +79,20 @@ class EntriesIter implements Iterator> { } next(): IteratorResult> { - while (!this.done) { - if (!(this.entry.taggedNext & EMPTY)) { - break - } - this.index++ + this.index++; + while (!this.done && !!(this.entry.taggedNext & EMPTY)) { + this.index++; } return this; } + + get iterator(): IterableIterator> { + return this; + } } -class KeyIterator { - constructor(private entriesIter: EntriesIter){} +class KeyIterator implements IterableIterator { + constructor(private entriesIter: EntriesIter) {} get done(): bool { return this.entriesIter.done; @@ -104,9 +106,13 @@ class KeyIterator { this.entriesIter.next(); return this; } + + get iterator(): IterableIterator { + return this; + } } -class ValueIterator { +class ValueIterator implements IterableIterator { constructor(private entriesIter: EntriesIter){} get done(): bool { @@ -121,6 +127,10 @@ class ValueIterator { this.entriesIter.next(); return this; } + + get iterator(): IterableIterator { + return this; + } } export class Map { @@ -141,10 +151,10 @@ export class Map { this.clear(); } - public entries(): EntriesIter { + entries(): EntriesIter { var start = changetype(this._entries); var size = this.entriesOffset; - return new EntriesIter(this, start, size); + return new EntriesIter(start, size); } clear(): void { @@ -269,11 +279,11 @@ export class Map { this.entriesOffset = this.entriesCount; } - keys(): Iterator { + keys(): IterableIterator { return new KeyIterator(this.entries()); } - values(): Iterator { + values(): IterableIterator { return new ValueIterator(this.entries()); } diff --git a/std/assembly/set.ts b/std/assembly/set.ts index d0d2f2a90d..dbf206fb13 100644 --- a/std/assembly/set.ts +++ b/std/assembly/set.ts @@ -58,6 +58,35 @@ function ENTRY_SIZE(): usize { return size; } +export class SetIterator implements IterableIterator { + private index: usize = -1; + constructor(protected start: usize, protected size: usize) {} + + get done(): bool { + return this.index >= this.size; + } + + protected get entry(): SetEntry { + return changetype>(this.start + this.index * ENTRY_SIZE()); + } + + get value(): T { + return this.entry.key; + } + + get iterator(): IterableIterator { + return this; + } + + next(): IteratorResult { + this.index++; + while (!this.done && !!(this.entry.taggedNext & EMPTY)) { + this.index++; + } + return this; + } +} + export class Set { // buckets holding references to the respective first entry within @@ -178,21 +207,8 @@ export class Set { this.entriesOffset = this.entriesCount; } - values(): T[] { - // FIXME: this is preliminary, needs iterators/closures - var start = changetype(this.entries); - var size = this.entriesOffset; - var values = new Array(size); - var length = 0; - for (let i = 0; i < size; ++i) { - let entry = changetype>(start + i * ENTRY_SIZE()); - if (!(entry.taggedNext & EMPTY)) { - values.push(entry.key); - ++length; - } - } - values.length = length; - return values; + values(): IterableIterator { + return new SetIterator(changetype(this.entries), this.entriesOffset); } toString(): string { diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat index fda01d4fc0..8824f11937 100644 --- a/tests/compiler/std/iterator.optimized.wat +++ b/tests/compiler/std/iterator.optimized.wat @@ -1,27 +1,28 @@ (module - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) - (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05") + (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\0b\00\00\00\03\00\00\00\05") (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03") - (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") - (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") - (data (i32.const 176) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s") - (data (i32.const 224) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h") - (data (i32.const 272) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") - (data (i32.const 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s") + (data (i32.const 72) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h") + (data (i32.const 120) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") + (data (i32.const 176) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s") + (data (i32.const 224) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s") + (data (i32.const 272) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") + (data (i32.const 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s") (data (i32.const 376) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00h\00e\00l\00l\00o") (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d") - (global $std/iterator/iterableArr (mut i32) (i32.const 0)) + (data (i32.const 440) "^\00\00\00\01\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y") (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $std/iterator/iterableArr (mut i32) (i32.const 0)) (global $std/iterator/iter (mut i32) (i32.const 0)) (global $std/iterator/iterres (mut i32) (i32.const 0)) (global $std/iterator/arri (mut i32) (i32.const 0)) @@ -33,6 +34,8 @@ (global $std/iterator/key (mut i32) (i32.const 0)) (global $std/iterator/valIter (mut i32) (i32.const 0)) (global $std/iterator/val (mut i32) (i32.const 0)) + (global $std/iterator/strSet (mut i32) (i32.const 0)) + (global $std/iterator/mapArray (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) @@ -122,41 +125,7 @@ i32.store offset=12 local.get $3 ) - (func $std/iterator/ArrayIterator#constructor (; 3 ;) (param $0 i32) (result i32) - (local $1 i32) - i32.const 8 - i32.const 6 - call $~lib/rt/stub/__alloc - local.tee $1 - i32.const -1 - i32.store - local.get $1 - local.get $0 - i32.store offset=4 - local.get $1 - ) - (func $~lib/array/Array#__get (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $1 - local.get $0 - i32.load offset=12 - i32.ge_u - if - i32.const 88 - i32.const 144 - i32.const 93 - i32.const 41 - call $~lib/builtins/abort - unreachable - end - local.get $0 - i32.load offset=4 - local.get $1 - i32.const 2 - i32.shl - i32.add - i32.load - ) - (func $~lib/memory/memory.fill (; 5 ;) (param $0 i32) (param $1 i32) + (func $~lib/memory/memory.fill (; 3 ;) (param $0 i32) (param $1 i32) (local $2 i32) block $~lib/util/memory/memset|inlined.0 local.get $1 @@ -365,7 +334,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 6 ;) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 4 ;) (param $0 i32) (result i32) (local $1 i32) i32.const 0 i32.const 0 @@ -404,7 +373,26 @@ i32.store offset=8 local.get $0 ) - (func $~lib/memory/memory.copy (; 7 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#constructor (; 5 ;) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 16 + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + call $~lib/arraybuffer/ArrayBufferView#constructor + local.tee $0 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + ) + (func $~lib/memory/memory.copy (; 6 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) block $~lib/util/memory/memmove|inlined.0 @@ -579,7 +567,7 @@ end end ) - (func $~lib/rt/stub/__realloc (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/stub/__realloc (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -594,7 +582,7 @@ i32.eqz if i32.const 0 - i32.const 344 + i32.const 240 i32.const 43 i32.const 2 call $~lib/builtins/abort @@ -612,7 +600,7 @@ i32.ne if i32.const 0 - i32.const 344 + i32.const 240 i32.const 46 i32.const 13 call $~lib/builtins/abort @@ -690,7 +678,7 @@ i32.store offset=12 local.get $0 ) - (func $~lib/array/ensureSize (; 9 ;) (param $0 i32) (param $1 i32) + (func $~lib/array/ensureSize (; 8 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -706,8 +694,8 @@ i32.const 268435452 i32.gt_u if - i32.const 240 - i32.const 144 + i32.const 88 + i32.const 192 i32.const 14 i32.const 47 call $~lib/builtins/abort @@ -744,7 +732,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#push (; 10 ;) (param $0 i32) (param $1 i32) + (func $~lib/array/Array#push (; 9 ;) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) local.get $0 @@ -767,39 +755,120 @@ local.get $3 i32.store offset=12 ) - (func $~lib/array/Array.from (; 11 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#constructor (; 10 ;) (param $0 i32) (result i32) (local $1 i32) - (local $2 i32) - (local $3 i32) - i32.const 16 - i32.const 3 + i32.const 8 + i32.const 6 call $~lib/rt/stub/__alloc - call $~lib/arraybuffer/ArrayBufferView#constructor local.tee $1 - i32.const 0 - i32.store offset=12 + i32.const -1 + i32.store + local.get $1 + local.get $0 + i32.store offset=4 + local.get $1 + ) + (func $~lib/array/Array#__get (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/array/Array#__set (; 12 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + local.get $1 + i32.const 0 + i32.lt_s + if + i32.const 288 + i32.const 192 + i32.const 109 + i32.const 21 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + local.tee $3 + call $~lib/array/ensureSize + local.get $0 + local.get $3 + i32.store offset=12 + end + local.get $0 + i32.load offset=4 local.get $1 + i32.const 2 + i32.shl + i32.add + local.get $2 + i32.store + ) + (func $~lib/array/Array.from (; 13 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) i32.const 0 - i32.store offset=12 + call $~lib/array/Array#constructor + local.set $1 + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 4 + i32.sub + if + unreachable + end + local.get $0 + call $std/iterator/ArrayIterator#constructor + local.tee $0 + local.set $3 local.get $0 - local.tee $3 call $~lib/iterator/Iterator#next + local.set $2 + i32.const 0 local.set $0 loop $continue|0 - local.get $0 + local.get $2 call $~lib/iterator/IteratorResult#get:done i32.eqz if - local.get $1 local.get $0 + local.tee $4 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.get $4 + local.get $2 call $~lib/iterator/IteratorResult#get:value - call $~lib/array/Array#push + call $~lib/array/Array#__set local.get $3 call $~lib/iterator/Iterator#next - local.set $0 - local.get $2 - i32.const 1 - i32.add local.set $2 br $continue|0 end @@ -808,21 +877,21 @@ i32.load offset=12 drop local.get $1 - local.get $2 + local.get $0 call $~lib/array/ensureSize local.get $1 - local.get $2 + local.get $0 i32.store offset=12 local.get $1 ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 12 ;) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 14 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 1073741808 i32.gt_u if - i32.const 240 - i32.const 288 + i32.const 88 + i32.const 136 i32.const 54 i32.const 42 call $~lib/builtins/abort @@ -836,7 +905,7 @@ call $~lib/memory/memory.fill local.get $1 ) - (func $~lib/map/Map<~lib/string/String,i32>#clear (; 13 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/map/Map<~lib/string/String,i32>#clear (; 15 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) i32.const 16 call $~lib/arraybuffer/ArrayBuffer#constructor @@ -869,10 +938,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 14 ;) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 16 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 8 + i32.const 9 call $~lib/rt/stub/__alloc local.tee $0 i32.const 0 @@ -896,7 +965,7 @@ call $~lib/map/Map<~lib/string/String,i32>#clear local.get $0 ) - (func $~lib/string/String#get:length (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#get:length (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub @@ -904,7 +973,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/hash/hashStr (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/util/hash/hashStr (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -946,7 +1015,7 @@ end local.get $1 ) - (func $~lib/util/string/compareImpl (; 17 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 19 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -1026,7 +1095,7 @@ end i32.const 0 ) - (func $~lib/string/String.__eq (; 18 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 local.get $1 @@ -1058,7 +1127,7 @@ end i32.const 0 ) - (func $~lib/map/Map<~lib/string/String,i32>#find (; 19 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#find (; 21 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.load local.get $0 @@ -1101,7 +1170,7 @@ end i32.const 0 ) - (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 22 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1214,7 +1283,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map<~lib/string/String,i32>#set (; 21 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map<~lib/string/String,i32>#set (; 23 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1304,62 +1373,65 @@ i32.store end ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 22 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) - i32.const 16 - i32.const 9 + (func $~lib/map/Map<~lib/string/String,i32>#entries (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=8 + local.set $1 + local.get $0 + i32.load offset=16 + local.set $2 + i32.const 12 + i32.const 10 call $~lib/rt/stub/__alloc - local.tee $3 - i32.const 0 + local.tee $0 + i32.const -1 i32.store - local.get $3 local.get $0 - i32.store offset=4 - local.get $3 local.get $1 - i32.store offset=8 - local.get $3 - local.get $2 - i32.store offset=12 - local.get $3 - ) - (func $~lib/map/Map<~lib/string/String,i32>#entries (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 + i32.store offset=4 local.get $0 - i32.load offset=8 + local.get $2 + i32.store offset=8 local.get $0 - i32.load offset=16 - call $~lib/map/EntriesIter<~lib/string/String,i32>#constructor ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 - i32.load offset=12 + i32.load offset=8 i32.ge_u ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.load offset=8 + i32.load offset=4 local.get $0 i32.load i32.const 12 i32.mul i32.add ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store loop $continue|0 - block $break|0 - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done - br_if $break|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + if (result i32) + i32.const 0 + else local.get $0 call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry i32.load offset=8 i32.const 1 i32.and - i32.eqz - br_if $break|0 + end + if local.get $0 local.get $0 i32.load @@ -1371,58 +1443,545 @@ end local.get $0 ) - (func $start:std/iterator (; 27 ;) (type $FUNCSIG$v) - (local $0 i32) + (func $~lib/set/Set<~lib/string/String>#clear (; 28 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) - i32.const 56 - global.set $std/iterator/iterableArr - i32.const 448 - global.set $~lib/rt/stub/startOffset - i32.const 448 - global.set $~lib/rt/stub/offset - i32.const 56 - call $std/iterator/ArrayIterator#constructor - global.set $std/iterator/iter - global.get $std/iterator/iter - call $~lib/iterator/Iterator#next - global.set $std/iterator/iterres - loop $continue|0 - global.get $std/iterator/iterres - call $~lib/iterator/IteratorResult#get:done - i32.eqz - if - global.get $std/iterator/iterres - call $~lib/iterator/IteratorResult#get:value - local.set $0 - global.get $std/iterator/arri - local.tee $1 - i32.const 1 - i32.add - global.set $std/iterator/arri - i32.const 56 - local.get $1 - call $~lib/array/Array#__get - local.get $0 - i32.ne - if - i32.const 0 - i32.const 192 - i32.const 40 - i32.const 2 - call $~lib/builtins/abort - unreachable - else - global.get $std/iterator/iter - call $~lib/iterator/Iterator#next - global.set $std/iterator/iterres + i32.const 16 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $1 + local.get $0 + i32.load + drop + local.get $0 + local.get $1 + i32.store + local.get $0 + i32.const 3 + i32.store offset=4 + i32.const 32 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $1 + local.get $0 + i32.load offset=8 + drop + local.get $0 + local.get $1 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + ) + (func $~lib/set/Set<~lib/string/String>#constructor (; 29 ;) (result i32) + (local $0 i32) + i32.const 24 + i32.const 20 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + local.get $0 + call $~lib/set/Set<~lib/string/String>#clear + local.get $0 + ) + (func $~lib/set/Set<~lib/string/String>#find (; 30 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + local.get $2 + i32.and + i32.const 2 + i32.shl + i32.add + i32.load + local.set $0 + loop $continue|0 + local.get $0 + if + local.get $0 + i32.load offset=4 + i32.const 1 + i32.and + if (result i32) + i32.const 0 + else + local.get $0 + i32.load + local.get $1 + call $~lib/string/String.__eq + end + if + local.get $0 + return + else + local.get $0 + i32.load offset=4 + i32.const -2 + i32.and + local.set $0 + br $continue|0 + end + unreachable + end + end + i32.const 0 + ) + (func $~lib/set/Set<~lib/string/String>#rehash (; 31 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + local.get $1 + i32.const 1 + i32.add + local.tee $4 + i32.const 2 + i32.shl + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $5 + local.get $4 + i32.const 3 + i32.shl + i32.const 3 + i32.div_s + local.tee $6 + i32.const 3 + i32.shl + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $4 + local.get $0 + i32.load offset=8 + local.tee $2 + local.get $0 + i32.load offset=16 + i32.const 3 + i32.shl + i32.add + local.set $7 + local.get $4 + local.set $3 + loop $continue|0 + local.get $2 + local.get $7 + i32.ne + if + local.get $2 + i32.load offset=4 + i32.const 1 + i32.and + i32.eqz + if + local.get $3 + local.get $2 + i32.load + i32.store + local.get $3 + local.get $2 + i32.load + call $~lib/util/hash/hashStr + local.get $1 + i32.and + i32.const 2 + i32.shl + local.get $5 + i32.add + local.tee $8 + i32.load + i32.store offset=4 + local.get $8 + local.get $3 + i32.store + local.get $3 + i32.const 8 + i32.add + local.set $3 + end + local.get $2 + i32.const 8 + i32.add + local.set $2 + br $continue|0 + end + end + local.get $5 + local.tee $2 + local.get $0 + i32.load + i32.ne + drop + local.get $0 + local.get $2 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $4 + local.tee $1 + local.get $0 + i32.load offset=8 + i32.ne + drop + local.get $0 + local.get $1 + i32.store offset=8 + local.get $0 + local.get $6 + i32.store offset=12 + local.get $0 + local.get $0 + i32.load offset=20 + i32.store offset=16 + ) + (func $~lib/set/Set<~lib/string/String>#add (; 32 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + local.get $1 + local.get $1 + call $~lib/util/hash/hashStr + local.tee $3 + call $~lib/set/Set<~lib/string/String>#find + i32.eqz + if + local.get $0 + i32.load offset=16 + local.get $0 + i32.load offset=12 + i32.eq + if + local.get $0 + local.get $0 + i32.load offset=20 + local.get $0 + i32.load offset=12 + i32.const 3 + i32.mul + i32.const 4 + i32.div_s + i32.lt_s + if (result i32) + local.get $0 + i32.load offset=4 + else + local.get $0 + i32.load offset=4 + i32.const 1 + i32.shl + i32.const 1 + i32.or + end + call $~lib/set/Set<~lib/string/String>#rehash + end + local.get $0 + i32.load offset=8 + local.set $2 + local.get $0 + local.get $0 + i32.load offset=16 + local.tee $4 + i32.const 1 + i32.add + i32.store offset=16 + local.get $4 + i32.const 3 + i32.shl + local.get $2 + i32.add + local.tee $2 + local.get $1 + i32.store + local.get $0 + local.get $0 + i32.load offset=20 + i32.const 1 + i32.add + i32.store offset=20 + local.get $2 + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + local.get $3 + i32.and + i32.const 2 + i32.shl + i32.add + local.tee $0 + i32.load + i32.store offset=4 + local.get $0 + local.get $2 + i32.store + end + ) + (func $~lib/array/Array<~lib/string/String>#__set (; 33 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + local.get $1 + i32.const 0 + i32.lt_s + if + i32.const 288 + i32.const 192 + i32.const 109 + i32.const 21 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + local.tee $3 + call $~lib/array/ensureSize + local.get $0 + local.get $3 + i32.store offset=12 + end + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.tee $0 + i32.load + local.get $2 + i32.ne + if + local.get $0 + local.get $2 + i32.store + end + ) + (func $~lib/array/Array<~lib/string/String>#set:length (; 34 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + local.get $0 + i32.load offset=12 + local.tee $2 + local.get $1 + i32.gt_s + if + local.get $0 + i32.load offset=4 + local.tee $4 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.set $3 + local.get $2 + i32.const 2 + i32.shl + local.get $4 + i32.add + local.set $2 + loop $continue|0 + local.get $3 + i32.load + drop + local.get $3 + i32.const 4 + i32.add + local.tee $3 + local.get $2 + i32.lt_u + br_if $continue|0 + end + else + local.get $0 + local.get $1 + call $~lib/array/ensureSize + end + local.get $0 + local.get $1 + i32.store offset=12 + ) + (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 35 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + i32.const 16 + i32.const 22 + call $~lib/rt/stub/__alloc + call $~lib/arraybuffer/ArrayBufferView#constructor + local.tee $1 + i32.const 0 + i32.store offset=12 + local.get $1 + i32.const 0 + i32.store offset=12 + block $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 16 + i32.sub + br_table $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator $switch$1$default + end + unreachable + end + local.get $0 + local.tee $3 + call $~lib/iterator/Iterator<~lib/string/String>#next + local.set $2 + i32.const 0 + local.set $0 + loop $continue|0 + local.get $2 + call $~lib/iterator/IteratorResult<~lib/string/String>#get:done + i32.eqz + if + local.get $0 + local.tee $4 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.get $4 + local.get $2 + call $~lib/iterator/IteratorResult<~lib/string/String>#get:value + call $~lib/array/Array<~lib/string/String>#__set + local.get $3 + call $~lib/iterator/Iterator<~lib/string/String>#next + local.set $2 + br $continue|0 + end + end + local.get $1 + local.get $0 + call $~lib/array/Array<~lib/string/String>#set:length + local.get $1 + ) + (func $~lib/array/Array<~lib/string/String>#__get (; 36 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + local.tee $0 + i32.eqz + if + i32.const 456 + i32.const 192 + i32.const 97 + i32.const 39 + call $~lib/builtins/abort + unreachable + end + local.get $0 + ) + (func $start:std/iterator (; 37 ;) (type $FUNCSIG$v) + (local $0 i32) + (local $1 i32) + (local $2 i32) + i32.const 560 + global.set $~lib/rt/stub/startOffset + i32.const 560 + global.set $~lib/rt/stub/offset + i32.const 16 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/array/Array#constructor + global.set $std/iterator/iterableArr + global.get $std/iterator/iterableArr + i32.const 11 + call $~lib/array/Array#push + global.get $std/iterator/iterableArr + i32.const 3 + call $~lib/array/Array#push + global.get $std/iterator/iterableArr + i32.const 5 + call $~lib/array/Array#push + global.get $std/iterator/iterableArr + call $std/iterator/ArrayIterator#constructor + global.set $std/iterator/iter + global.get $std/iterator/iter + call $~lib/iterator/Iterator#next + global.set $std/iterator/iterres + loop $continue|0 + global.get $std/iterator/iterres + call $~lib/iterator/IteratorResult#get:done + i32.eqz + if + global.get $std/iterator/iterres + call $~lib/iterator/IteratorResult#get:value + local.set $0 + global.get $std/iterator/arri + local.tee $1 + i32.const 1 + i32.add + global.set $std/iterator/arri + i32.const 56 + local.get $1 + call $~lib/array/Array#__get + local.get $0 + i32.ne + if + i32.const 0 + i32.const 344 + i32.const 38 + i32.const 2 + call $~lib/builtins/abort + unreachable + else + global.get $std/iterator/iter + call $~lib/iterator/Iterator#next + global.set $std/iterator/iterres br $continue|0 end unreachable end end global.get $std/iterator/iterableArr - call $std/iterator/ArrayIterator#constructor - call $~lib/array/Array.from + call $~lib/array/Array.from global.set $std/iterator/arr2 global.get $std/iterator/arr2 i32.load offset=12 @@ -1430,8 +1989,8 @@ i32.ne if i32.const 0 - i32.const 192 - i32.const 48 + i32.const 344 + i32.const 44 i32.const 0 call $~lib/builtins/abort unreachable @@ -1439,12 +1998,12 @@ global.get $std/iterator/arr2 i32.const 0 call $~lib/array/Array#__get - i32.const 1 + i32.const 11 i32.ne if i32.const 0 - i32.const 192 - i32.const 49 + i32.const 344 + i32.const 45 i32.const 0 call $~lib/builtins/abort unreachable @@ -1456,8 +2015,8 @@ i32.ne if i32.const 0 - i32.const 192 - i32.const 50 + i32.const 344 + i32.const 46 i32.const 0 call $~lib/builtins/abort unreachable @@ -1483,7 +2042,7 @@ i32.const 8 i32.sub i32.load - i32.const 9 + i32.const 10 i32.sub if unreachable @@ -1496,8 +2055,8 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 58 + i32.const 344 + i32.const 54 i32.const 0 call $~lib/builtins/abort unreachable @@ -1506,7 +2065,7 @@ call $~lib/map/Map<~lib/string/String,i32>#entries local.set $0 i32.const 4 - i32.const 12 + i32.const 16 call $~lib/rt/stub/__alloc local.tee $1 local.get $0 @@ -1514,39 +2073,17 @@ local.get $1 global.set $std/iterator/keyIter global.get $std/iterator/keyIter - local.tee $0 - i32.const 8 - i32.sub - i32.load - i32.const 12 - i32.sub - if - unreachable - end - local.get $0 - call $~lib/map/ValueIterator<~lib/string/String,i32>#next + call $~lib/iterator/Iterator<~lib/string/String>#next global.set $std/iterator/key global.get $std/iterator/key - local.tee $0 - i32.const 8 - i32.sub - i32.load - i32.const 12 - i32.sub - if - unreachable - end - local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - i32.load + call $~lib/iterator/IteratorResult<~lib/string/String>#get:value i32.const 392 call $~lib/string/String.__eq i32.eqz if i32.const 0 - i32.const 192 - i32.const 62 + i32.const 344 + i32.const 58 i32.const 0 call $~lib/builtins/abort unreachable @@ -1555,7 +2092,7 @@ call $~lib/map/Map<~lib/string/String,i32>#entries local.set $0 i32.const 4 - i32.const 14 + i32.const 19 call $~lib/rt/stub/__alloc local.tee $1 local.get $0 @@ -1571,35 +2108,110 @@ i32.ne if i32.const 0 - i32.const 192 - i32.const 66 + i32.const 344 + i32.const 62 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + call $~lib/set/Set<~lib/string/String>#constructor + global.set $std/iterator/strSet + global.get $std/iterator/strSet + i32.const 392 + call $~lib/set/Set<~lib/string/String>#add + global.get $std/iterator/strSet + i32.const 424 + call $~lib/set/Set<~lib/string/String>#add + global.get $std/iterator/strSet + i32.const 392 + i32.const 392 + call $~lib/util/hash/hashStr + call $~lib/set/Set<~lib/string/String>#find + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 67 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/strSet + local.tee $0 + i32.load offset=8 + local.set $1 + local.get $0 + i32.load offset=16 + local.set $2 + i32.const 12 + i32.const 23 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const -1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.get $2 + i32.store offset=8 + local.get $0 + call $~lib/array/Array.from<~lib/string/String,~lib/string/String> + global.set $std/iterator/mapArray + global.get $std/iterator/mapArray + i32.const 0 + call $~lib/array/Array<~lib/string/String>#__get + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 70 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/mapArray + i32.const 1 + call $~lib/array/Array<~lib/string/String>#__get + i32.const 424 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 71 i32.const 0 call $~lib/builtins/abort unreachable end ) - (func $start (; 28 ;) (type $FUNCSIG$v) + (func $start (; 38 ;) (type $FUNCSIG$v) call $start:std/iterator ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 29 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 39 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next drop local.get $0 ) - (func $~lib/iterator/Iterator#next (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator#next (; 40 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 6 - i32.sub - br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default - end + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + local.tee $1 + if + local.get $1 + i32.const 13 + i32.eq + br_if $switch$1$case$4 unreachable end local.get $0 @@ -1614,15 +2226,109 @@ local.get $0 call $~lib/map/ValueIterator<~lib/string/String,i32>#next ) - (func $std/iterator/ArrayIterator#get:done (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult#get:done (; 42 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + block $switch$1$case$4 + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + local.tee $1 + if + local.get $1 + i32.const 13 + i32.eq + br_if $switch$1$case$4 + unreachable + end + local.get $0 + i32.load + local.get $0 + i32.load offset=4 + i32.load offset=12 + i32.ge_s + return + end + local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult#get:value (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + block $switch$1$case$4 + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 6 + i32.sub + local.tee $1 + if + local.get $1 + i32.const 13 + i32.eq + br_if $switch$1$case$4 + unreachable + end + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get + return + end local.get $0 i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=4 + ) + (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=4 - i32.load offset=12 - i32.ge_s + local.get $0 + i32.load + i32.const 3 + i32.shl + i32.add + ) + (func $~lib/set/SetIterator<~lib/string/String>#next (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + loop $continue|0 + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + if (result i32) + i32.const 0 + else + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:entry + i32.load offset=4 + i32.const 1 + i32.and + end + if + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + br $continue|0 + end + end + local.get $0 ) - (func $~lib/iterator/IteratorResult#get:done (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -1630,21 +2336,20 @@ i32.const 8 i32.sub i32.load - i32.const 6 + i32.const 16 i32.sub - br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end local.get $0 - call $std/iterator/ArrayIterator#get:done + call $~lib/map/ValueIterator<~lib/string/String,i32>#next return end local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + call $~lib/set/SetIterator<~lib/string/String>#next ) - (func $~lib/iterator/IteratorResult#get:value (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -1652,36 +2357,44 @@ i32.const 8 i32.sub i32.load - i32.const 6 + i32.const 16 i32.sub - br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end - block $__inlined_func$std/iterator/ArrayIterator#get:value - local.get $0 - call $std/iterator/ArrayIterator#get:done - i32.eqz - if - local.get $0 - i32.load offset=4 + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load + return + end + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:entry + i32.load + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default local.get $0 + i32.const 8 + i32.sub i32.load - call $~lib/array/Array#__get - local.set $0 - br $__inlined_func$std/iterator/ArrayIterator#get:value + i32.const 16 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end local.get $0 + call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done return end local.get $0 - i32.load - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - i32.load offset=4 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $null (; 34 ;) (type $FUNCSIG$v) + (func $null (; 49 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/std/iterator.ts b/tests/compiler/std/iterator.ts index 4d6459ce48..84fb8e116c 100644 --- a/tests/compiler/std/iterator.ts +++ b/tests/compiler/std/iterator.ts @@ -1,67 +1,71 @@ class ArrayIterator implements Iterator { private _index: i32 = -1; - constructor(private _array: Array){} + constructor(private _array: Array) {} - get done(): bool{ + get done(): bool { return this._index >= this._array.length; } - + get value(): T { - if (!this.done){ - return this._array[this._index]; - } - unreachable(); - return changetype(this); + return this._array[this._index]; } + next(): IteratorResult { this._index++; return this; } - } class IterableArray extends Array implements Iterable { - private _index: i32; - get iterator(): Iterator { return new ArrayIterator(this); } } -let arri32: Array = [1,3,5]; -let iterableArr = > arri32; +const arri32: Array = [11,3,5]; +const iterableArr: IterableArray = new IterableArray(); +iterableArr.push(11); +iterableArr.push(3); +iterableArr.push(5); -let iter = iterableArr.iterator; -let iterres = iter.next(); -let arri: i32 = 0; -while (!iterres.done){ +const iter = iterableArr.iterator; +var iterres = iter.next(); + +var arri: i32 = 0; +while (!iterres.done) { assert(iterres.value == arri32[arri++]); - iterres = iter.next() + iterres = iter.next(); } - - -let arr2: Array = Array.from(iterableArr.iterator); +const arr2: Array = Array.from(iterableArr); // assert (arr2 != null); assert(arr2.length == 3); -assert(arr2[0]== 1) -assert(arr2[1]== 3) +assert(arr2[0] == 11); +assert(arr2[1] == 3); -let map = new Map(); +const map = new Map(); map.set("hello", 40); map.set("world", 1); -let entries = map.entries(); -let resEntry = entries.next(); +const entries = map.entries(); +const resEntry = entries.next(); assert(resEntry.value.key == "hello"); -let keyIter = map.keys(); -let key = keyIter.next(); +const keyIter = map.keys(); +const key = keyIter.next(); assert(key.value == "hello"); -let valIter = map.values(); -let val = valIter.next(); +const valIter = map.values(); +const val = valIter.next(); assert(val.value == 40); +const strSet = new Set(); +strSet.add("hello"); +strSet.add("world"); +assert(strSet.has("hello")); + +const mapArray = Array.from(strSet.values()); +assert(mapArray[0] == "hello"); +assert(mapArray[1] == "world"); diff --git a/tests/compiler/std/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat index fb18898ea1..7ab4cf8f0f 100644 --- a/tests/compiler/std/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -1,36 +1,37 @@ (module - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$vi (func (param i32))) - (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$viiii (func (param i32 i32 i32 i32))) + (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) (memory $0 1) - (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\01\00\00\00\03\00\00\00\05\00\00\00") + (data (i32.const 8) "\0c\00\00\00\01\00\00\00\00\00\00\00\0c\00\00\00\0b\00\00\00\03\00\00\00\05\00\00\00") (data (i32.const 40) "\10\00\00\00\01\00\00\00\03\00\00\00\10\00\00\00\18\00\00\00\18\00\00\00\0c\00\00\00\03\00\00\00") - (data (i32.const 72) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00") - (data (i32.const 128) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") - (data (i32.const 176) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s\00") - (data (i32.const 224) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h\00") - (data (i32.const 272) "&\00\00\00\01\00\00\00\01\00\00\00&\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 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") + (data (i32.const 72) "\1c\00\00\00\01\00\00\00\01\00\00\00\1c\00\00\00I\00n\00v\00a\00l\00i\00d\00 \00l\00e\00n\00g\00t\00h\00") + (data (i32.const 120) "&\00\00\00\01\00\00\00\01\00\00\00&\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 176) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00") + (data (i32.const 224) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00") + (data (i32.const 272) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00") + (data (i32.const 328) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00s\00t\00d\00/\00i\00t\00e\00r\00a\00t\00o\00r\00.\00t\00s\00") (data (i32.const 376) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00h\00e\00l\00l\00o\00") (data (i32.const 408) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00w\00o\00r\00l\00d\00") + (data (i32.const 440) "^\00\00\00\01\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y\00") (table $0 1 funcref) (elem (i32.const 0) $null) - (global $std/iterator/arri32 (mut i32) (i32.const 56)) - (global $std/iterator/iterableArr (mut i32) (i32.const 0)) + (global $std/iterator/arri32 i32 (i32.const 56)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $std/iterator/iterableArr (mut i32) (i32.const 0)) (global $std/iterator/iter (mut i32) (i32.const 0)) (global $std/iterator/iterres (mut i32) (i32.const 0)) (global $std/iterator/arri (mut i32) (i32.const 0)) - (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/argc (mut i32) (i32.const 0)) (global $std/iterator/arr2 (mut i32) (i32.const 0)) (global $std/iterator/map (mut i32) (i32.const 0)) (global $std/iterator/entries (mut i32) (i32.const 0)) @@ -39,13 +40,12 @@ (global $std/iterator/key (mut i32) (i32.const 0)) (global $std/iterator/valIter (mut i32) (i32.const 0)) (global $std/iterator/val (mut i32) (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 436)) + (global $std/iterator/strSet (mut i32) (i32.const 0)) + (global $std/iterator/mapArray (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 552)) (export "memory" (memory $0)) (start $start) - (func $~lib/rt/stub/__retain (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - local.get $0 - ) - (func $~lib/rt/stub/maybeGrowMemory (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -99,7 +99,7 @@ local.get $0 global.set $~lib/rt/stub/offset ) - (func $~lib/rt/stub/__alloc (; 3 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/stub/__alloc (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -152,68 +152,7 @@ i32.store offset=12 local.get $2 ) - (func $~lib/rt/stub/__release (; 4 ;) (type $FUNCSIG$vi) (param $0 i32) - nop - ) - (func $std/iterator/ArrayIterator#constructor (; 5 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $1 - call $~lib/rt/stub/__retain - local.set $1 - local.get $0 - i32.eqz - if - i32.const 8 - i32.const 6 - call $~lib/rt/stub/__alloc - call $~lib/rt/stub/__retain - local.set $0 - end - local.get $0 - i32.const -1 - i32.store - local.get $0 - local.get $1 - call $~lib/rt/stub/__retain - i32.store offset=4 - local.get $1 - call $~lib/rt/stub/__release - local.get $0 - ) - (func $std/iterator/IterableArray#get:iterator (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 0 - local.get $0 - call $std/iterator/ArrayIterator#constructor - ) - (func $~lib/array/Array#__unchecked_get (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - local.get $0 - i32.load offset=4 - local.get $1 - i32.const 2 - i32.shl - i32.add - i32.load - ) - (func $~lib/array/Array#__get (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - local.get $1 - local.get $0 - i32.load offset=12 - i32.ge_u - if - i32.const 88 - i32.const 144 - i32.const 93 - i32.const 41 - call $~lib/builtins/abort - unreachable - end - local.get $0 - local.get $1 - call $~lib/array/Array#__unchecked_get - local.set $2 - local.get $2 - ) - (func $~lib/memory/memory.fill (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.fill (; 3 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -477,7 +416,13 @@ end end ) - (func $~lib/arraybuffer/ArrayBufferView#constructor (; 10 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/rt/stub/__retain (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + ) + (func $~lib/rt/stub/__release (; 5 ;) (type $FUNCSIG$vi) (param $0 i32) + nop + ) + (func $~lib/arraybuffer/ArrayBufferView#constructor (; 6 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -488,8 +433,8 @@ i32.shr_u i32.gt_u if - i32.const 240 - i32.const 288 + i32.const 88 + i32.const 136 i32.const 23 i32.const 56 call $~lib/builtins/abort @@ -549,7 +494,7 @@ i32.store offset=8 local.get $0 ) - (func $~lib/array/Array#constructor (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#constructor (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 if (result i32) local.get $0 @@ -571,7 +516,23 @@ i32.store offset=12 local.get $0 ) - (func $~lib/util/memory/memcpy (; 12 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $std/iterator/IterableArray#constructor (; 8 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 16 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + call $~lib/array/Array#constructor + local.set $0 + local.get $0 + ) + (func $~lib/util/memory/memcpy (; 9 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1599,7 +1560,7 @@ i32.store8 end ) - (func $~lib/memory/memory.copy (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 10 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1824,7 +1785,7 @@ end end ) - (func $~lib/rt/stub/__realloc (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/rt/stub/__realloc (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1845,7 +1806,7 @@ i32.eqz if i32.const 0 - i32.const 344 + i32.const 240 i32.const 43 i32.const 2 call $~lib/builtins/abort @@ -1865,7 +1826,7 @@ i32.eqz if i32.const 0 - i32.const 344 + i32.const 240 i32.const 46 i32.const 13 call $~lib/builtins/abort @@ -1947,7 +1908,7 @@ i32.store offset=12 local.get $0 ) - (func $~lib/array/ensureSize (; 15 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/ensureSize (; 12 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1967,8 +1928,8 @@ i32.shr_u i32.gt_u if - i32.const 240 - i32.const 144 + i32.const 88 + i32.const 192 i32.const 14 i32.const 47 call $~lib/builtins/abort @@ -2010,7 +1971,7 @@ i32.store offset=8 end ) - (func $~lib/array/Array#push (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#push (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2037,7 +1998,109 @@ i32.store offset=12 local.get $3 ) - (func $~lib/array/Array#set:length (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $std/iterator/ArrayIterator#constructor (; 14 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.eqz + if + i32.const 8 + i32.const 6 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const -1 + i32.store + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store offset=4 + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $std/iterator/IterableArray#get:iterator (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 0 + local.get $0 + call $std/iterator/ArrayIterator#constructor + ) + (func $~lib/array/Array#__unchecked_get (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/array/Array#__get (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + call $~lib/array/Array#__unchecked_get + local.set $2 + local.get $2 + ) + (func $~lib/array/Array#__unchecked_set (; 18 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.get $2 + i32.store + ) + (func $~lib/array/Array#__set (; 19 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + local.get $1 + i32.const 0 + i32.lt_s + if + i32.const 288 + i32.const 192 + i32.const 109 + i32.const 21 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.store offset=12 + end + local.get $0 + local.get $1 + local.get $2 + call $~lib/array/Array#__unchecked_set + ) + (func $~lib/array/Array#set:length (; 20 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) local.get $0 i32.load offset=12 @@ -2050,73 +2113,103 @@ local.get $1 i32.store offset=12 ) - (func $~lib/array/Array.from (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) + (func $~lib/array/Array.from (; 21 ;) (type $FUNCSIG$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.get $0 call $~lib/rt/stub/__retain local.set $0 i32.const 0 i32.const 0 call $~lib/array/Array#constructor - local.set $1 + local.set $2 local.get $0 + call $~lib/iterator/Iterable#get:iterator + local.tee $3 + call $~lib/rt/stub/__retain + local.set $4 + local.get $4 call $~lib/iterator/Iterator#next - local.set $2 + local.set $5 i32.const 0 - local.set $3 + local.set $6 block $break|0 loop $continue|0 - local.get $2 + local.get $5 call $~lib/iterator/IteratorResult#get:done i32.eqz i32.eqz br_if $break|0 local.get $1 - local.get $2 - call $~lib/iterator/IteratorResult#get:value - call $~lib/array/Array#push - drop - local.get $0 + if + local.get $2 + local.get $6 + local.tee $7 + i32.const 1 + i32.add + local.set $6 + local.get $7 + i32.const 1 + global.set $~lib/argc + local.get $5 + call $~lib/iterator/IteratorResult#get:value + local.get $1 + call_indirect (type $FUNCSIG$ii) + call $~lib/array/Array#__set + else + local.get $2 + local.get $6 + local.tee $7 + i32.const 1 + i32.add + local.set $6 + local.get $7 + local.get $5 + call $~lib/iterator/IteratorResult#get:value + call $~lib/array/Array#__set + end + local.get $4 call $~lib/iterator/Iterator#next - local.set $4 - local.get $2 + local.set $7 + local.get $5 call $~lib/rt/stub/__release - local.get $4 - local.set $2 - local.get $3 - i32.const 1 - i32.add - local.set $3 + local.get $7 + local.set $5 br $continue|0 end unreachable end - local.get $1 - local.get $3 + local.get $2 + local.get $6 call $~lib/array/Array#set:length - local.get $1 - local.set $4 - local.get $0 - call $~lib/rt/stub/__release local.get $2 + local.set $7 + local.get $3 call $~lib/rt/stub/__release local.get $4 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + local.get $7 ) - (func $~lib/array/Array#get:length (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#get:length (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=12 ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 23 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $1 i32.const 1073741808 i32.gt_u if - i32.const 240 - i32.const 288 + i32.const 88 + i32.const 136 i32.const 54 i32.const 42 call $~lib/builtins/abort @@ -2133,7 +2226,7 @@ local.get $2 call $~lib/rt/stub/__retain ) - (func $~lib/map/Map<~lib/string/String,i32>#clear (; 21 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/map/Map<~lib/string/String,i32>#clear (; 24 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -2173,12 +2266,12 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.eqz if i32.const 24 - i32.const 8 + i32.const 9 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -2205,7 +2298,7 @@ call $~lib/map/Map<~lib/string/String,i32>#clear local.get $0 ) - (func $~lib/string/String#get:length (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#get:length (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub @@ -2213,7 +2306,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/hash/hashStr (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/util/hash/hashStr (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2264,7 +2357,7 @@ call $~lib/rt/stub/__release local.get $3 ) - (func $~lib/util/string/compareImpl (; 25 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (func $~lib/util/string/compareImpl (; 28 ;) (type $FUNCSIG$iiiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) (local $5 i32) (local $6 i32) (local $7 i32) @@ -2384,7 +2477,7 @@ call $~lib/rt/stub/__release local.get $8 ) - (func $~lib/string/String.__eq (; 26 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 29 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $0 @@ -2457,7 +2550,7 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/map/Map<~lib/string/String,i32>#find (; 27 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#find (; 30 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $1 @@ -2517,7 +2610,7 @@ call $~lib/rt/stub/__release local.get $4 ) - (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 28 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 31 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2679,7 +2772,7 @@ local.get $5 call $~lib/rt/stub/__release ) - (func $~lib/map/Map<~lib/string/String,i32>#set (; 29 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map<~lib/string/String,i32>#set (; 32 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2793,37 +2886,28 @@ local.get $1 call $~lib/rt/stub/__release ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 30 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) - local.get $1 - call $~lib/rt/stub/__retain - local.set $1 + (func $~lib/map/EntriesIter<~lib/string/String,i32>#constructor (; 33 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.eqz if - i32.const 16 - i32.const 9 + i32.const 12 + i32.const 10 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 end local.get $0 - i32.const 0 + i32.const -1 i32.store local.get $0 local.get $1 - call $~lib/rt/stub/__retain i32.store offset=4 local.get $0 local.get $2 i32.store offset=8 local.get $0 - local.get $3 - i32.store offset=12 - local.get $1 - call $~lib/rt/stub/__release - local.get $0 ) - (func $~lib/map/Map<~lib/string/String,i32>#entries (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#entries (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -2833,45 +2917,52 @@ i32.load offset=16 local.set $2 i32.const 0 - local.get $0 local.get $1 local.get $2 call $~lib/map/EntriesIter<~lib/string/String,i32>#constructor ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 35 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 - i32.load offset=12 + i32.load offset=8 i32.ge_u ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.load offset=8 + i32.load offset=4 local.get $0 i32.load i32.const 12 i32.mul i32.add ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 34 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store block $break|0 loop $continue|0 local.get $0 call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done i32.eqz + if (result i32) + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + i32.load offset=8 + i32.const 1 + i32.and + i32.eqz + i32.eqz + else + i32.const 0 + end i32.eqz br_if $break|0 local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry - i32.load offset=8 - i32.const 1 - i32.and - i32.eqz - if - br $break|0 - end - local.get $0 local.get $0 i32.load i32.const 1 @@ -2884,7 +2975,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#constructor (; 35 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#constructor (; 38 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 call $~lib/rt/stub/__retain local.set $1 @@ -2892,7 +2983,7 @@ i32.eqz if i32.const 4 - i32.const 12 + i32.const 16 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -2905,7 +2996,7 @@ call $~lib/rt/stub/__release local.get $0 ) - (func $~lib/map/Map<~lib/string/String,i32>#keys (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#keys (; 39 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) i32.const 0 @@ -2918,7 +3009,7 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#constructor (; 37 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#constructor (; 40 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 call $~lib/rt/stub/__retain local.set $1 @@ -2926,39 +3017,768 @@ i32.eqz if i32.const 4 - i32.const 14 + i32.const 19 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + call $~lib/rt/stub/__retain + i32.store + local.get $1 + call $~lib/rt/stub/__release + local.get $0 + ) + (func $~lib/map/Map<~lib/string/String,i32>#values (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + i32.const 0 + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#entries + local.tee $1 + call $~lib/map/ValueIterator<~lib/string/String,i32>#constructor + local.set $2 + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $~lib/set/Set<~lib/string/String>#clear (; 42 ;) (type $FUNCSIG$vi) (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + local.tee $1 + i32.const 0 + i32.const 16 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $2 + local.get $1 + i32.load + call $~lib/rt/stub/__release + local.get $2 + i32.store + local.get $0 + i32.const 4 + i32.const 1 + i32.sub + i32.store offset=4 + local.get $0 + local.tee $1 + i32.const 0 + i32.const 32 + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $2 + local.get $1 + i32.load offset=8 + call $~lib/rt/stub/__release + local.get $2 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + ) + (func $~lib/set/Set<~lib/string/String>#constructor (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 24 + i32.const 20 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 end local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i32.const 0 + i32.store offset=8 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 0 + i32.store offset=16 + local.get $0 + i32.const 0 + i32.store offset=20 + local.get $0 + call $~lib/set/Set<~lib/string/String>#clear + local.get $0 + ) + (func $~lib/set/Set<~lib/string/String>#find (; 44 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + i32.load + local.get $2 + local.get $0 + i32.load offset=4 + i32.and + i32.const 4 + i32.mul + i32.add + i32.load + local.set $3 + block $break|0 + loop $continue|0 + local.get $3 + i32.eqz + br_if $break|0 + local.get $3 + i32.load offset=4 + i32.const 1 + i32.and + i32.eqz + if (result i32) + local.get $3 + i32.load + local.get $1 + call $~lib/string/String.__eq + else + i32.const 0 + end + if + local.get $3 + local.set $4 + local.get $1 + call $~lib/rt/stub/__release + local.get $4 + return + end + local.get $3 + i32.load offset=4 + i32.const 1 + i32.const -1 + i32.xor + i32.and + local.set $3 + br $continue|0 + end + unreachable + end + i32.const 0 + local.set $4 + local.get $1 + call $~lib/rt/stub/__release + local.get $4 + ) + (func $~lib/set/Set<~lib/string/String>#rehash (; 45 ;) (type $FUNCSIG$vii) (param $0 i32) (param $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) + (local $10 i32) + (local $11 i32) + (local $12 i32) + local.get $1 + i32.const 1 + i32.add + local.set $2 + i32.const 0 + local.get $2 + i32.const 4 + i32.mul + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $3 + local.get $2 + i32.const 8 + i32.mul + i32.const 3 + i32.div_s + local.set $4 + i32.const 0 + local.get $4 + i32.const 8 + i32.mul + call $~lib/arraybuffer/ArrayBuffer#constructor + local.set $5 + local.get $0 + i32.load offset=8 + local.set $6 + local.get $6 + local.get $0 + i32.load offset=16 + i32.const 8 + i32.mul + i32.add + local.set $7 + local.get $5 + local.set $8 + block $break|0 + loop $continue|0 + local.get $6 + local.get $7 + i32.ne + i32.eqz + br_if $break|0 + local.get $6 + local.set $9 + local.get $9 + i32.load offset=4 + i32.const 1 + i32.and + i32.eqz + if + local.get $8 + local.set $10 + local.get $10 + local.get $9 + i32.load + i32.store + block $~lib/util/hash/HASH<~lib/string/String>|inlined.3 (result i32) + local.get $9 + i32.load + call $~lib/rt/stub/__retain + local.set $11 + local.get $11 + call $~lib/util/hash/hashStr + local.set $12 + local.get $11 + call $~lib/rt/stub/__release + local.get $12 + br $~lib/util/hash/HASH<~lib/string/String>|inlined.3 + end + local.get $1 + i32.and + local.set $11 + local.get $3 + local.get $11 + i32.const 4 + i32.mul + i32.add + local.set $12 + local.get $10 + local.get $12 + i32.load + i32.store offset=4 + local.get $12 + local.get $8 + i32.store + local.get $8 + i32.const 8 + i32.add + local.set $8 + end + local.get $6 + i32.const 8 + i32.add + local.set $6 + br $continue|0 + end + unreachable + end + local.get $0 + local.tee $9 + local.get $3 + local.tee $10 + local.get $9 + i32.load + local.tee $12 + i32.ne + if + local.get $10 + call $~lib/rt/stub/__retain + local.set $10 + local.get $12 + call $~lib/rt/stub/__release + end + local.get $10 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.tee $9 + local.get $5 + local.tee $11 + local.get $9 + i32.load offset=8 + local.tee $10 + i32.ne + if + local.get $11 + call $~lib/rt/stub/__retain + local.set $11 + local.get $10 + call $~lib/rt/stub/__release + end + local.get $11 + i32.store offset=8 + local.get $0 + local.get $4 + i32.store offset=12 + local.get $0 + local.get $0 + i32.load offset=20 + i32.store offset=16 + local.get $3 + call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + ) + (func $~lib/set/Set<~lib/string/String>#add (; 46 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + block $~lib/util/hash/HASH<~lib/string/String>|inlined.2 (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $2 + local.get $2 + call $~lib/util/hash/hashStr + local.set $3 + local.get $2 + call $~lib/rt/stub/__release + local.get $3 + br $~lib/util/hash/HASH<~lib/string/String>|inlined.2 + end + local.set $4 + local.get $0 + local.get $1 + local.get $4 + call $~lib/set/Set<~lib/string/String>#find + local.set $5 + local.get $5 + i32.eqz + if + local.get $0 + i32.load offset=16 + local.get $0 + i32.load offset=12 + i32.eq + if + local.get $0 + local.get $0 + i32.load offset=20 + local.get $0 + i32.load offset=12 + i32.const 3 + i32.mul + i32.const 4 + i32.div_s + i32.lt_s + if (result i32) + local.get $0 + i32.load offset=4 + else + local.get $0 + i32.load offset=4 + i32.const 1 + i32.shl + i32.const 1 + i32.or + end + call $~lib/set/Set<~lib/string/String>#rehash + end + local.get $0 + i32.load offset=8 + local.get $0 + local.get $0 + i32.load offset=16 + local.tee $2 + i32.const 1 + i32.add + i32.store offset=16 + local.get $2 + i32.const 8 + i32.mul + i32.add + local.set $5 + local.get $5 + local.get $1 + call $~lib/rt/stub/__retain + i32.store + local.get $0 + local.get $0 + i32.load offset=20 + i32.const 1 + i32.add + i32.store offset=20 + local.get $0 + i32.load + local.get $4 + local.get $0 + i32.load offset=4 + i32.and + i32.const 4 + i32.mul + i32.add + local.set $2 + local.get $5 + local.get $2 + i32.load + i32.store offset=4 + local.get $2 + local.get $5 + i32.store + end + local.get $1 + call $~lib/rt/stub/__release + ) + (func $~lib/set/Set<~lib/string/String>#has (; 47 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $1 + local.get $0 + local.get $1 + block $~lib/util/hash/HASH<~lib/string/String>|inlined.4 (result i32) + local.get $1 + call $~lib/rt/stub/__retain + local.set $2 + local.get $2 + call $~lib/util/hash/hashStr + local.set $3 + local.get $2 + call $~lib/rt/stub/__release + local.get $3 + br $~lib/util/hash/HASH<~lib/string/String>|inlined.4 + end + call $~lib/set/Set<~lib/string/String>#find + i32.const 0 + i32.ne + local.set $2 + local.get $1 + call $~lib/rt/stub/__release + local.get $2 + ) + (func $~lib/set/SetIterator<~lib/string/String>#constructor (; 48 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 12 + i32.const 23 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + i32.const -1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.get $2 + i32.store offset=8 + local.get $0 + ) + (func $~lib/set/Set<~lib/string/String>#values (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 0 + local.get $0 + i32.load offset=8 + local.get $0 + i32.load offset=16 + call $~lib/set/SetIterator<~lib/string/String>#constructor + ) + (func $~lib/array/Array<~lib/string/String>#constructor (; 50 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + if (result i32) + local.get $0 + else + i32.const 16 + i32.const 22 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + end + local.get $1 + i32.const 2 + call $~lib/arraybuffer/ArrayBufferView#constructor + local.set $0 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/array/Array<~lib/string/String>#__unchecked_set (; 51 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.set $3 + local.get $3 + i32.load + local.set $4 + local.get $2 + local.get $4 + i32.ne + if + local.get $3 + local.get $2 + call $~lib/rt/stub/__retain + i32.store + local.get $4 + call $~lib/rt/stub/__release + end + local.get $2 + call $~lib/rt/stub/__release + ) + (func $~lib/array/Array<~lib/string/String>#__set (; 52 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $2 + call $~lib/rt/stub/__retain + local.set $2 + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + local.get $1 + i32.const 0 + i32.lt_s + if + local.get $2 + call $~lib/rt/stub/__release + i32.const 288 + i32.const 192 + i32.const 109 + i32.const 21 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.store offset=12 + end + local.get $0 + local.get $1 + local.get $2 + call $~lib/array/Array<~lib/string/String>#__unchecked_set + local.get $2 + call $~lib/rt/stub/__release + ) + (func $~lib/array/Array<~lib/string/String>#set:length (; 53 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $0 + i32.load offset=12 + local.set $2 + local.get $2 + local.get $1 + i32.gt_s + if + local.get $0 + i32.load offset=4 + local.set $3 + local.get $3 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.set $4 + local.get $3 + local.get $2 + i32.const 2 + i32.shl + i32.add + local.set $5 + loop $continue|0 + local.get $4 + i32.load + call $~lib/rt/stub/__release + local.get $4 + i32.const 4 + i32.add + local.tee $4 + local.get $5 + i32.lt_u + br_if $continue|0 + end + else + local.get $0 + local.get $1 + i32.const 2 + call $~lib/array/ensureSize + end + local.get $0 + local.get $1 + i32.store offset=12 + ) + (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 54 ;) (type $FUNCSIG$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) + (local $9 i32) + local.get $0 + call $~lib/rt/stub/__retain + local.set $0 + i32.const 0 + i32.const 0 + call $~lib/array/Array<~lib/string/String>#constructor + local.set $2 + local.get $0 + call $~lib/iterator/Iterable<~lib/string/String>#get:iterator + local.tee $3 + call $~lib/rt/stub/__retain + local.set $4 + local.get $4 + call $~lib/iterator/Iterator<~lib/string/String>#next + local.set $5 + i32.const 0 + local.set $6 + block $break|0 + loop $continue|0 + local.get $5 + call $~lib/iterator/IteratorResult<~lib/string/String>#get:done + i32.eqz + i32.eqz + br_if $break|0 + local.get $1 + if + local.get $2 + local.get $6 + local.tee $9 + i32.const 1 + i32.add + local.set $6 + local.get $9 + i32.const 1 + global.set $~lib/argc + local.get $5 + call $~lib/iterator/IteratorResult<~lib/string/String>#get:value + local.tee $7 + local.get $1 + call_indirect (type $FUNCSIG$ii) + local.tee $8 + call $~lib/array/Array<~lib/string/String>#__set + local.get $7 + call $~lib/rt/stub/__release + local.get $8 + call $~lib/rt/stub/__release + else + local.get $2 + local.get $6 + local.tee $7 + i32.const 1 + i32.add + local.set $6 + local.get $7 + local.get $5 + call $~lib/iterator/IteratorResult<~lib/string/String>#get:value + local.tee $8 + call $~lib/array/Array<~lib/string/String>#__set + local.get $8 + call $~lib/rt/stub/__release + end + local.get $4 + call $~lib/iterator/Iterator<~lib/string/String>#next + local.set $9 + local.get $5 + call $~lib/rt/stub/__release + local.get $9 + local.set $5 + br $continue|0 + end + unreachable + end + local.get $2 + local.get $6 + call $~lib/array/Array<~lib/string/String>#set:length + local.get $2 + local.set $9 + local.get $3 + call $~lib/rt/stub/__release + local.get $4 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + local.get $9 + ) + (func $~lib/array/Array<~lib/string/String>#__unchecked_get (; 55 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + call $~lib/rt/stub/__retain + ) + (func $~lib/array/Array<~lib/string/String>#__get (; 56 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 local.get $1 - call $~lib/rt/stub/__retain - i32.store - local.get $1 - call $~lib/rt/stub/__release - local.get $0 - ) - (func $~lib/map/Map<~lib/string/String,i32>#values (; 38 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - (local $2 i32) - i32.const 0 - local.get $0 - call $~lib/map/Map<~lib/string/String,i32>#entries - local.tee $1 - call $~lib/map/ValueIterator<~lib/string/String,i32>#constructor + call $~lib/array/Array<~lib/string/String>#__unchecked_get local.set $2 - local.get $1 - call $~lib/rt/stub/__release + local.get $2 + i32.eqz + if + local.get $2 + call $~lib/rt/stub/__release + i32.const 456 + i32.const 192 + i32.const 97 + i32.const 39 + call $~lib/builtins/abort + unreachable + end local.get $2 ) - (func $start:std/iterator (; 39 ;) (type $FUNCSIG$v) + (func $start:std/iterator (; 57 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) (local $2 i32) - global.get $std/iterator/arri32 - call $~lib/rt/stub/__retain - global.set $std/iterator/iterableArr + (local $3 i32) + (local $4 i32) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -2969,6 +3789,22 @@ global.set $~lib/rt/stub/startOffset global.get $~lib/rt/stub/startOffset global.set $~lib/rt/stub/offset + i32.const 0 + i32.const 0 + call $std/iterator/IterableArray#constructor + global.set $std/iterator/iterableArr + global.get $std/iterator/iterableArr + i32.const 11 + call $~lib/array/Array#push + drop + global.get $std/iterator/iterableArr + i32.const 3 + call $~lib/array/Array#push + drop + global.get $std/iterator/iterableArr + i32.const 5 + call $~lib/array/Array#push + drop global.get $std/iterator/iterableArr call $std/iterator/IterableArray#get:iterator local.tee $1 @@ -2986,7 +3822,7 @@ br_if $break|0 global.get $std/iterator/iterres call $~lib/iterator/IteratorResult#get:value - global.get $std/iterator/arri32 + i32.const 56 global.get $std/iterator/arri local.tee $0 i32.const 1 @@ -2998,8 +3834,8 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 40 + i32.const 344 + i32.const 38 i32.const 2 call $~lib/builtins/abort unreachable @@ -3016,9 +3852,8 @@ unreachable end global.get $std/iterator/iterableArr - call $std/iterator/IterableArray#get:iterator - local.tee $0 - call $~lib/array/Array.from + i32.const 0 + call $~lib/array/Array.from global.set $std/iterator/arr2 global.get $std/iterator/arr2 call $~lib/array/Array#get:length @@ -3027,8 +3862,8 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 48 + i32.const 344 + i32.const 44 i32.const 0 call $~lib/builtins/abort unreachable @@ -3036,13 +3871,13 @@ global.get $std/iterator/arr2 i32.const 0 call $~lib/array/Array#__get - i32.const 1 + i32.const 11 i32.eq i32.eqz if i32.const 0 - i32.const 192 - i32.const 49 + i32.const 344 + i32.const 45 i32.const 0 call $~lib/builtins/abort unreachable @@ -3055,8 +3890,8 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 50 + i32.const 344 + i32.const 46 i32.const 0 call $~lib/builtins/abort unreachable @@ -3086,8 +3921,8 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 58 + i32.const 344 + i32.const 54 i32.const 0 call $~lib/builtins/abort unreachable @@ -3100,14 +3935,14 @@ global.set $std/iterator/key global.get $std/iterator/key call $~lib/iterator/IteratorResult<~lib/string/String>#get:value - local.tee $2 + local.tee $0 i32.const 392 call $~lib/string/String.__eq i32.eqz if i32.const 0 - i32.const 192 - i32.const 62 + i32.const 344 + i32.const 58 i32.const 0 call $~lib/builtins/abort unreachable @@ -3125,8 +3960,65 @@ i32.eqz if i32.const 0 - i32.const 192 - i32.const 66 + i32.const 344 + i32.const 62 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + call $~lib/set/Set<~lib/string/String>#constructor + global.set $std/iterator/strSet + global.get $std/iterator/strSet + i32.const 392 + call $~lib/set/Set<~lib/string/String>#add + global.get $std/iterator/strSet + i32.const 424 + call $~lib/set/Set<~lib/string/String>#add + global.get $std/iterator/strSet + i32.const 392 + call $~lib/set/Set<~lib/string/String>#has + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 67 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/strSet + call $~lib/set/Set<~lib/string/String>#values + local.tee $2 + i32.const 0 + call $~lib/array/Array.from<~lib/string/String,~lib/string/String> + global.set $std/iterator/mapArray + global.get $std/iterator/mapArray + i32.const 0 + call $~lib/array/Array<~lib/string/String>#__get + local.tee $3 + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 70 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/mapArray + i32.const 1 + call $~lib/array/Array<~lib/string/String>#__get + local.tee $4 + i32.const 424 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 71 i32.const 0 call $~lib/builtins/abort unreachable @@ -3137,11 +4029,15 @@ call $~lib/rt/stub/__release local.get $2 call $~lib/rt/stub/__release + local.get $3 + call $~lib/rt/stub/__release + local.get $4 + call $~lib/rt/stub/__release ) - (func $start (; 40 ;) (type $FUNCSIG$v) + (func $start (; 58 ;) (type $FUNCSIG$v) call $start:std/iterator ) - (func $std/iterator/ArrayIterator#next (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#next (; 59 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 local.get $0 i32.load @@ -3151,7 +4047,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 42 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 60 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next @@ -3159,7 +4055,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator#next (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator#next (; 61 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -3167,7 +4063,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -3179,7 +4075,7 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#next return ) - (func $std/iterator/ArrayIterator#get:done (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:done (; 62 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 @@ -3187,12 +4083,12 @@ call $~lib/array/Array#get:length i32.ge_s ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 63 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult#get:done (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:done (; 64 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -3200,7 +4096,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -3212,31 +4108,24 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done return ) - (func $std/iterator/ArrayIterator#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:value (; 65 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - call $std/iterator/ArrayIterator#get:done - i32.eqz - if - local.get $0 - i32.load offset=4 - local.get $0 - i32.load - call $~lib/array/Array#__get - return - end - unreachable + i32.load offset=4 + local.get $0 + i32.load + call $~lib/array/Array#__get ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 66 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 67 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value i32.load offset=4 ) - (func $~lib/iterator/IteratorResult#get:value (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:value (; 68 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -3244,7 +4133,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -3256,14 +4145,29 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value return ) - (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 51 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterable#get:iterator (; 69 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end + unreachable + end + local.get $0 + call $std/iterator/IterableArray#get:iterator + return + ) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 70 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$3 block $switch$1$default local.get $0 i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default end unreachable end @@ -3271,7 +4175,7 @@ call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 71 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next @@ -3279,44 +4183,167 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator<~lib/string/String>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$3 - block $switch$1$default + (func $~lib/set/SetIterator<~lib/string/String>#get:done (; 72 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + local.get $0 + i32.load offset=8 + i32.ge_u + ) + (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 73 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $0 + i32.load + i32.const 8 + i32.mul + i32.add + ) + (func $~lib/set/SetIterator<~lib/string/String>#next (; 74 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.add + i32.store + block $break|0 + loop $continue|0 + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:done + i32.eqz + if (result i32) + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:entry + i32.load offset=4 + i32.const 1 + i32.and + i32.eqz + i32.eqz + else + i32.const 0 + end + i32.eqz + br_if $break|0 + local.get $0 local.get $0 - i32.const 8 - i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + i32.const 1 + i32.add + i32.store + br $continue|0 end unreachable end local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#next + call $~lib/rt/stub/__retain + ) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 75 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#next + return + end + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#next return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 76 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value i32.load call $~lib/rt/stub/__retain ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + (func $~lib/set/SetIterator<~lib/string/String>#get:value (; 77 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:entry + i32.load + call $~lib/rt/stub/__retain + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 78 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable end - unreachable + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:value + return + end + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:value + return + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator (; 79 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/rt/stub/__retain + ) + (func $~lib/set/SetIterator<~lib/string/String>#get:iterator (; 80 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/rt/stub/__retain + ) + (func $~lib/iterator/Iterable<~lib/string/String>#get:iterator (; 81 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator + return + end + local.get $0 + call $~lib/set/SetIterator<~lib/string/String>#get:iterator + return + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:done (; 82 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 83 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:done + return end local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#get:value + call $~lib/set/SetIterator<~lib/string/String>#get:done return ) - (func $null (; 56 ;) (type $FUNCSIG$v) + (func $null (; 84 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 4d2f715de7..02ee6792f5 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -2383,7 +2383,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -3076,7 +3076,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -3819,7 +3819,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -4512,7 +4512,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -5257,7 +5257,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -6400,7 +6400,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -7463,7 +7463,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -8174,7 +8174,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index 336d8ee5fa..fca7599fd0 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -4003,7 +4003,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -4887,7 +4887,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -5785,7 +5785,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -6669,7 +6669,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -7571,7 +7571,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -8415,7 +8415,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -9349,7 +9349,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -10203,7 +10203,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -11061,7 +11061,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -11920,7 +11920,7 @@ if i32.const 416 i32.const 472 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index 0371950761..c4de426636 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -684,7 +684,7 @@ if i32.const 200 i32.const 256 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -1239,7 +1239,7 @@ if i32.const 200 i32.const 256 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index c83f33ce74..e340b693a4 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -997,7 +997,7 @@ call $~lib/rt/stub/__release i32.const 200 i32.const 256 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable @@ -1750,7 +1750,7 @@ if i32.const 200 i32.const 256 - i32.const 179 + i32.const 189 i32.const 16 call $~lib/builtins/abort unreachable From 104a57386aa476f5afc2313de99f588cba540b2b Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 13 Dec 2019 11:49:21 -0500 Subject: [PATCH 46/47] Make Map/Set Iterable --- std/assembly/index.d.ts | 2 + std/assembly/map.ts | 6 +- std/assembly/set.ts | 4 + tests/compiler/std/iterator.optimized.wat | 416 +++++++++++++----- tests/compiler/std/iterator.ts | 8 + tests/compiler/std/iterator.untouched.wat | 496 ++++++++++++++++++---- tests/compiler/std/map.optimized.wat | 42 +- tests/compiler/std/map.untouched.wat | 42 +- tests/compiler/std/set.optimized.wat | 42 +- tests/compiler/std/set.untouched.wat | 42 +- tests/compiler/std/symbol.optimized.wat | 2 +- tests/compiler/std/symbol.untouched.wat | 2 +- 12 files changed, 834 insertions(+), 270 deletions(-) diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index e36abf44eb..2e6b4259fc 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -1558,6 +1558,7 @@ declare class Map { keys(): IterableIterator; values(): IterableIterator; toString(): string; + readonly iterator: IterableIterator> } declare class Set { @@ -1568,6 +1569,7 @@ declare class Set { clear(): void; values(): IterableIterator; // preliminary toString(): string; + readonly iterator: IterableIterator } interface SymbolConstructor { diff --git a/std/assembly/map.ts b/std/assembly/map.ts index 527724d926..7ab22cf8aa 100644 --- a/std/assembly/map.ts +++ b/std/assembly/map.ts @@ -27,7 +27,7 @@ const FREE_FACTOR_N = 3; const FREE_FACTOR_D = 4; /** Structure of a map entry. */ -@unmanaged class MapEntry { +@unmanaged export class MapEntry { key: K; value: V; taggedNext: usize; // LSB=1 indicates EMPTY @@ -320,4 +320,8 @@ export class Map { } __visit(entries, cookie); } + + get iterator(): IterableIterator> { + return this.entries(); + } } diff --git a/std/assembly/set.ts b/std/assembly/set.ts index dbf206fb13..3dc8286052 100644 --- a/std/assembly/set.ts +++ b/std/assembly/set.ts @@ -236,4 +236,8 @@ export class Set { } __visit(entries, cookie); } + + get iterator(): IterableIterator { + return this.values(); + } } diff --git a/tests/compiler/std/iterator.optimized.wat b/tests/compiler/std/iterator.optimized.wat index 8824f11937..0279e18a8c 100644 --- a/tests/compiler/std/iterator.optimized.wat +++ b/tests/compiler/std/iterator.optimized.wat @@ -30,12 +30,14 @@ (global $std/iterator/map (mut i32) (i32.const 0)) (global $std/iterator/entries (mut i32) (i32.const 0)) (global $std/iterator/resEntry (mut i32) (i32.const 0)) + (global $std/iterator/entriesArr (mut i32) (i32.const 0)) (global $std/iterator/keyIter (mut i32) (i32.const 0)) (global $std/iterator/key (mut i32) (i32.const 0)) (global $std/iterator/valIter (mut i32) (i32.const 0)) (global $std/iterator/val (mut i32) (i32.const 0)) (global $std/iterator/strSet (mut i32) (i32.const 0)) (global $std/iterator/mapArray (mut i32) (i32.const 0)) + (global $std/iterator/setArray (mut i32) (i32.const 0)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/maybeGrowMemory (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) @@ -768,7 +770,16 @@ i32.store offset=4 local.get $1 ) - (func $~lib/array/Array#__get (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#__unchecked_get (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/array/Array#__get (; 12 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 local.get $0 i32.load offset=12 @@ -782,14 +793,10 @@ unreachable end local.get $0 - i32.load offset=4 local.get $1 - i32.const 2 - i32.shl - i32.add - i32.load + call $~lib/array/Array#__unchecked_get ) - (func $~lib/array/Array#__set (; 12 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 13 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) local.get $1 local.get $0 @@ -826,7 +833,18 @@ local.get $2 i32.store ) - (func $~lib/array/Array.from (; 13 ;) (param $0 i32) (result i32) + (func $~lib/array/Array#set:length (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + local.get $0 + i32.load offset=12 + drop + local.get $0 + local.get $1 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.store offset=12 + ) + (func $~lib/array/Array.from (; 15 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -874,17 +892,11 @@ end end local.get $1 - i32.load offset=12 - drop - local.get $1 local.get $0 - call $~lib/array/ensureSize - local.get $1 - local.get $0 - i32.store offset=12 + call $~lib/array/Array#set:length local.get $1 ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 14 ;) (param $0 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 16 ;) (param $0 i32) (result i32) (local $1 i32) local.get $0 i32.const 1073741808 @@ -905,7 +917,7 @@ call $~lib/memory/memory.fill local.get $1 ) - (func $~lib/map/Map<~lib/string/String,i32>#clear (; 15 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/map/Map<~lib/string/String,i32>#clear (; 17 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) i32.const 16 call $~lib/arraybuffer/ArrayBuffer#constructor @@ -938,7 +950,7 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 16 ;) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#constructor (; 18 ;) (result i32) (local $0 i32) i32.const 24 i32.const 9 @@ -965,7 +977,7 @@ call $~lib/map/Map<~lib/string/String,i32>#clear local.get $0 ) - (func $~lib/string/String#get:length (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#get:length (; 19 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 16 i32.sub @@ -973,7 +985,7 @@ i32.const 1 i32.shr_u ) - (func $~lib/util/hash/hashStr (; 18 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/util/hash/hashStr (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -1015,7 +1027,7 @@ end local.get $1 ) - (func $~lib/util/string/compareImpl (; 19 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/util/string/compareImpl (; 21 ;) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $0 @@ -1095,7 +1107,7 @@ end i32.const 0 ) - (func $~lib/string/String.__eq (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $0 local.get $1 @@ -1127,7 +1139,7 @@ end i32.const 0 ) - (func $~lib/map/Map<~lib/string/String,i32>#find (; 21 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#find (; 23 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.load local.get $0 @@ -1170,7 +1182,7 @@ end i32.const 0 ) - (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 22 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map<~lib/string/String,i32>#rehash (; 24 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1283,7 +1295,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map<~lib/string/String,i32>#set (; 23 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map<~lib/string/String,i32>#set (; 25 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1373,7 +1385,7 @@ i32.store end ) - (func $~lib/map/Map<~lib/string/String,i32>#entries (; 24 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#entries (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) local.get $0 @@ -1383,7 +1395,7 @@ i32.load offset=16 local.set $2 i32.const 12 - i32.const 10 + i32.const 12 call $~lib/rt/stub/__alloc local.tee $0 i32.const -1 @@ -1396,14 +1408,14 @@ i32.store offset=8 local.get $0 ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 25 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:done (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 i32.load offset=8 i32.ge_u ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry (; 28 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -1412,7 +1424,7 @@ i32.mul i32.add ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#next (; 29 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 local.get $0 i32.load @@ -1443,7 +1455,103 @@ end local.get $0 ) - (func $~lib/set/Set<~lib/string/String>#clear (; 28 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array.from<~lib/map/MapEntry<~lib/string/String,i32>,~lib/map/MapEntry<~lib/string/String,i32>> (; 30 ;) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + i32.const 16 + i32.const 15 + call $~lib/rt/stub/__alloc + call $~lib/arraybuffer/ArrayBufferView#constructor + local.tee $1 + i32.const 0 + i32.store offset=12 + local.get $1 + i32.const 0 + i32.store offset=12 + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 9 + i32.sub + if + unreachable + end + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#entries + local.tee $0 + local.set $3 + local.get $0 + call $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next + local.set $2 + i32.const 0 + local.set $0 + loop $continue|0 + local.get $2 + i32.const 8 + i32.sub + i32.load + i32.const 12 + i32.sub + if + unreachable + end + local.get $2 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + i32.eqz + if + local.get $0 + local.tee $4 + i32.const 1 + i32.add + local.set $0 + local.get $1 + local.get $4 + local.get $2 + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value + call $~lib/array/Array#__set + local.get $3 + call $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next + local.set $2 + br $continue|0 + end + end + local.get $1 + local.get $0 + call $~lib/array/Array#set:length + local.get $1 + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__get (; 31 ;) (param $0 i32) (result i32) + i32.const 0 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 0 + call $~lib/array/Array#__unchecked_get + local.tee $0 + i32.eqz + if + i32.const 456 + i32.const 192 + i32.const 97 + i32.const 39 + call $~lib/builtins/abort + unreachable + end + local.get $0 + ) + (func $~lib/set/Set<~lib/string/String>#clear (; 32 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) i32.const 16 call $~lib/arraybuffer/ArrayBuffer#constructor @@ -1476,10 +1584,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set<~lib/string/String>#constructor (; 29 ;) (result i32) + (func $~lib/set/Set<~lib/string/String>#constructor (; 33 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 20 + i32.const 22 call $~lib/rt/stub/__alloc local.tee $0 i32.const 0 @@ -1503,7 +1611,7 @@ call $~lib/set/Set<~lib/string/String>#clear local.get $0 ) - (func $~lib/set/Set<~lib/string/String>#find (; 30 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/Set<~lib/string/String>#find (; 34 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.load local.get $0 @@ -1546,7 +1654,7 @@ end i32.const 0 ) - (func $~lib/set/Set<~lib/string/String>#rehash (; 31 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set<~lib/string/String>#rehash (; 35 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1655,7 +1763,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set<~lib/string/String>#add (; 32 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set<~lib/string/String>#add (; 36 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1738,7 +1846,30 @@ i32.store end ) - (func $~lib/array/Array<~lib/string/String>#__set (; 33 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/set/Set<~lib/string/String>#values (; 37 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=8 + local.set $1 + local.get $0 + i32.load offset=16 + local.set $2 + i32.const 12 + i32.const 25 + call $~lib/rt/stub/__alloc + local.tee $0 + i32.const -1 + i32.store + local.get $0 + local.get $1 + i32.store offset=4 + local.get $0 + local.get $2 + i32.store offset=8 + local.get $0 + ) + (func $~lib/array/Array<~lib/string/String>#__set (; 38 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) local.get $1 local.get $0 @@ -1782,7 +1913,7 @@ i32.store end ) - (func $~lib/array/Array<~lib/string/String>#set:length (; 34 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/Array<~lib/string/String>#set:length (; 39 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1827,13 +1958,13 @@ local.get $1 i32.store offset=12 ) - (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 35 ;) (param $0 i32) (result i32) + (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 40 ;) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) i32.const 16 - i32.const 22 + i32.const 24 call $~lib/rt/stub/__alloc call $~lib/arraybuffer/ArrayBufferView#constructor local.tee $1 @@ -1842,19 +1973,8 @@ local.get $1 i32.const 0 i32.store offset=12 - block $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - i32.const 16 - i32.sub - br_table $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $__inlined_func$~lib/iterator/Iterable<~lib/string/String>#get:iterator $switch$1$default - end - unreachable - end local.get $0 + call $~lib/iterator/Iterable<~lib/string/String>#get:iterator local.tee $3 call $~lib/iterator/Iterator<~lib/string/String>#next local.set $2 @@ -1886,7 +2006,7 @@ call $~lib/array/Array<~lib/string/String>#set:length local.get $1 ) - (func $~lib/array/Array<~lib/string/String>#__get (; 36 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array<~lib/string/String>#__get (; 41 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 local.get $0 i32.load offset=12 @@ -1918,10 +2038,9 @@ end local.get $0 ) - (func $start:std/iterator (; 37 ;) (type $FUNCSIG$v) + (func $start:std/iterator (; 42 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) - (local $2 i32) i32.const 560 global.set $~lib/rt/stub/startOffset i32.const 560 @@ -2038,17 +2157,37 @@ call $~lib/map/EntriesIter<~lib/string/String,i32>#next global.set $std/iterator/resEntry global.get $std/iterator/resEntry - local.tee $0 - i32.const 8 - i32.sub + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value i32.load - i32.const 10 - i32.sub + i32.const 392 + call $~lib/string/String.__eq + i32.eqz if + i32.const 0 + i32.const 344 + i32.const 54 + i32.const 0 + call $~lib/builtins/abort unreachable end - local.get $0 - call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + global.get $std/iterator/map + call $~lib/array/Array.from<~lib/map/MapEntry<~lib/string/String,i32>,~lib/map/MapEntry<~lib/string/String,i32>> + global.set $std/iterator/entriesArr + global.get $std/iterator/entriesArr + i32.load offset=12 + global.get $std/iterator/map + i32.load offset=20 + i32.ne + if + i32.const 0 + i32.const 344 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/entriesArr + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__get i32.load i32.const 392 call $~lib/string/String.__eq @@ -2056,7 +2195,7 @@ if i32.const 0 i32.const 344 - i32.const 54 + i32.const 58 i32.const 0 call $~lib/builtins/abort unreachable @@ -2065,7 +2204,7 @@ call $~lib/map/Map<~lib/string/String,i32>#entries local.set $0 i32.const 4 - i32.const 16 + i32.const 18 call $~lib/rt/stub/__alloc local.tee $1 local.get $0 @@ -2083,7 +2222,7 @@ if i32.const 0 i32.const 344 - i32.const 58 + i32.const 62 i32.const 0 call $~lib/builtins/abort unreachable @@ -2092,7 +2231,7 @@ call $~lib/map/Map<~lib/string/String,i32>#entries local.set $0 i32.const 4 - i32.const 19 + i32.const 21 call $~lib/rt/stub/__alloc local.tee $1 local.get $0 @@ -2109,7 +2248,7 @@ if i32.const 0 i32.const 344 - i32.const 62 + i32.const 66 i32.const 0 call $~lib/builtins/abort unreachable @@ -2131,31 +2270,13 @@ if i32.const 0 i32.const 344 - i32.const 67 + i32.const 71 i32.const 0 call $~lib/builtins/abort unreachable end global.get $std/iterator/strSet - local.tee $0 - i32.load offset=8 - local.set $1 - local.get $0 - i32.load offset=16 - local.set $2 - i32.const 12 - i32.const 23 - call $~lib/rt/stub/__alloc - local.tee $0 - i32.const -1 - i32.store - local.get $0 - local.get $1 - i32.store offset=4 - local.get $0 - local.get $2 - i32.store offset=8 - local.get $0 + call $~lib/set/Set<~lib/string/String>#values call $~lib/array/Array.from<~lib/string/String,~lib/string/String> global.set $std/iterator/mapArray global.get $std/iterator/mapArray @@ -2167,7 +2288,7 @@ if i32.const 0 i32.const 344 - i32.const 70 + i32.const 74 i32.const 0 call $~lib/builtins/abort unreachable @@ -2181,23 +2302,54 @@ if i32.const 0 i32.const 344 - i32.const 71 + i32.const 75 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/strSet + call $~lib/array/Array.from<~lib/string/String,~lib/string/String> + global.set $std/iterator/setArray + global.get $std/iterator/setArray + i32.const 0 + call $~lib/array/Array<~lib/string/String>#__get + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 78 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/setArray + i32.const 1 + call $~lib/array/Array<~lib/string/String>#__get + i32.const 424 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 79 i32.const 0 call $~lib/builtins/abort unreachable end ) - (func $start (; 38 ;) (type $FUNCSIG$v) + (func $start (; 43 ;) (type $FUNCSIG$v) call $start:std/iterator ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 39 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next drop local.get $0 ) - (func $~lib/iterator/Iterator#next (; 40 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator#next (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) block $switch$1$case$4 local.get $0 @@ -2209,7 +2361,7 @@ local.tee $1 if local.get $1 - i32.const 13 + i32.const 15 i32.eq br_if $switch$1$case$4 unreachable @@ -2226,12 +2378,12 @@ local.get $0 call $~lib/map/ValueIterator<~lib/string/String,i32>#next ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult#get:done (; 42 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:done (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) block $switch$1$case$4 local.get $0 @@ -2243,7 +2395,7 @@ local.tee $1 if local.get $1 - i32.const 13 + i32.const 15 i32.eq br_if $switch$1$case$4 unreachable @@ -2259,7 +2411,7 @@ local.get $0 call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult#get:value (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:value (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) block $switch$1$case$4 local.get $0 @@ -2271,7 +2423,7 @@ local.tee $1 if local.get $1 - i32.const 13 + i32.const 15 i32.eq br_if $switch$1$case$4 unreachable @@ -2288,7 +2440,33 @@ call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry i32.load offset=4 ) - (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 12 + i32.sub + if + unreachable + end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry + ) + (func $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 12 + i32.sub + if + unreachable + end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + ) + (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 51 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -2297,7 +2475,7 @@ i32.shl i32.add ) - (func $~lib/set/SetIterator<~lib/string/String>#next (; 45 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#next (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 local.get $0 i32.load @@ -2328,7 +2506,7 @@ end local.get $0 ) - (func $~lib/iterator/Iterator<~lib/string/String>#next (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 53 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -2336,7 +2514,7 @@ i32.const 8 i32.sub i32.load - i32.const 16 + i32.const 18 i32.sub br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end @@ -2349,7 +2527,7 @@ local.get $0 call $~lib/set/SetIterator<~lib/string/String>#next ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 54 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -2357,7 +2535,7 @@ i32.const 8 i32.sub i32.load - i32.const 16 + i32.const 18 i32.sub br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end @@ -2373,7 +2551,31 @@ call $~lib/set/SetIterator<~lib/string/String>#get:entry i32.load ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterable<~lib/string/String>#get:iterator (; 55 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + i32.const 18 + i32.sub + br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$case$5 $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable + end + local.get $0 + return + end + local.get $0 + return + end + local.get $0 + call $~lib/set/Set<~lib/string/String>#values + ) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 56 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -2381,7 +2583,7 @@ i32.const 8 i32.sub i32.load - i32.const 16 + i32.const 18 i32.sub br_table $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end @@ -2394,7 +2596,7 @@ local.get $0 call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $null (; 49 ;) (type $FUNCSIG$v) + (func $null (; 57 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/std/iterator.ts b/tests/compiler/std/iterator.ts index 84fb8e116c..ea2f85a408 100644 --- a/tests/compiler/std/iterator.ts +++ b/tests/compiler/std/iterator.ts @@ -53,6 +53,10 @@ const entries = map.entries(); const resEntry = entries.next(); assert(resEntry.value.key == "hello"); +const entriesArr = Array.from>(map); +assert(entriesArr.length == map.size); +assert(entriesArr[0].key == "hello"); + const keyIter = map.keys(); const key = keyIter.next(); assert(key.value == "hello"); @@ -69,3 +73,7 @@ assert(strSet.has("hello")); const mapArray = Array.from(strSet.values()); assert(mapArray[0] == "hello"); assert(mapArray[1] == "world"); + +const setArray = Array.from(strSet); +assert(setArray[0] == "hello"); +assert(setArray[1] == "world"); diff --git a/tests/compiler/std/iterator.untouched.wat b/tests/compiler/std/iterator.untouched.wat index 7ab4cf8f0f..b0e4618c77 100644 --- a/tests/compiler/std/iterator.untouched.wat +++ b/tests/compiler/std/iterator.untouched.wat @@ -36,12 +36,14 @@ (global $std/iterator/map (mut i32) (i32.const 0)) (global $std/iterator/entries (mut i32) (i32.const 0)) (global $std/iterator/resEntry (mut i32) (i32.const 0)) + (global $std/iterator/entriesArr (mut i32) (i32.const 0)) (global $std/iterator/keyIter (mut i32) (i32.const 0)) (global $std/iterator/key (mut i32) (i32.const 0)) (global $std/iterator/valIter (mut i32) (i32.const 0)) (global $std/iterator/val (mut i32) (i32.const 0)) (global $std/iterator/strSet (mut i32) (i32.const 0)) (global $std/iterator/mapArray (mut i32) (i32.const 0)) + (global $std/iterator/setArray (mut i32) (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 552)) (export "memory" (memory $0)) (start $start) @@ -2891,7 +2893,7 @@ i32.eqz if i32.const 12 - i32.const 10 + i32.const 12 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -2975,7 +2977,218 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#constructor (; 38 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#constructor (; 38 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + if (result i32) + local.get $0 + else + i32.const 16 + i32.const 15 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + end + local.get $1 + i32.const 2 + call $~lib/arraybuffer/ArrayBufferView#constructor + local.set $0 + local.get $0 + i32.const 0 + i32.store offset=12 + local.get $0 + local.get $1 + i32.store offset=12 + local.get $0 + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__unchecked_set (; 39 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + local.get $2 + i32.store + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__set (; 40 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + local.get $1 + i32.const 0 + i32.lt_s + if + i32.const 288 + i32.const 192 + i32.const 109 + i32.const 21 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.store offset=12 + end + local.get $0 + local.get $1 + local.get $2 + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__unchecked_set + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#set:length (; 41 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=12 + local.set $2 + local.get $0 + local.get $1 + i32.const 2 + call $~lib/array/ensureSize + local.get $0 + local.get $1 + i32.store offset=12 + ) + (func $~lib/array/Array.from<~lib/map/MapEntry<~lib/string/String,i32>,~lib/map/MapEntry<~lib/string/String,i32>> (; 42 ;) (type $FUNCSIG$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.get $0 + call $~lib/rt/stub/__retain + local.set $0 + i32.const 0 + i32.const 0 + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#constructor + local.set $2 + local.get $0 + call $~lib/iterator/Iterable<~lib/map/MapEntry<~lib/string/String,i32>>#get:iterator + local.tee $3 + call $~lib/rt/stub/__retain + local.set $4 + local.get $4 + call $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next + local.set $5 + i32.const 0 + local.set $6 + block $break|0 + loop $continue|0 + local.get $5 + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:done + i32.eqz + i32.eqz + br_if $break|0 + local.get $1 + if + local.get $2 + local.get $6 + local.tee $7 + i32.const 1 + i32.add + local.set $6 + local.get $7 + i32.const 1 + global.set $~lib/argc + local.get $5 + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value + local.get $1 + call_indirect (type $FUNCSIG$ii) + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__set + else + local.get $2 + local.get $6 + local.tee $7 + i32.const 1 + i32.add + local.set $6 + local.get $7 + local.get $5 + call $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__set + end + local.get $4 + call $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next + local.set $7 + local.get $5 + call $~lib/rt/stub/__release + local.get $7 + local.set $5 + br $continue|0 + end + unreachable + end + local.get $2 + local.get $6 + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#set:length + local.get $2 + local.set $7 + local.get $3 + call $~lib/rt/stub/__release + local.get $4 + call $~lib/rt/stub/__release + local.get $0 + call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + local.get $7 + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#get:length (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=12 + ) + (func $~lib/map/Map<~lib/string/String,i32>#get:size (; 44 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.load offset=20 + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__unchecked_get (; 45 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.load offset=4 + local.get $1 + i32.const 2 + i32.shl + i32.add + i32.load + ) + (func $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__get (; 46 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + local.get $0 + i32.load offset=12 + i32.ge_u + if + i32.const 288 + i32.const 192 + i32.const 93 + i32.const 41 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__unchecked_get + local.set $2 + local.get $2 + i32.eqz + if + i32.const 456 + i32.const 192 + i32.const 97 + i32.const 39 + call $~lib/builtins/abort + unreachable + end + local.get $2 + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#constructor (; 47 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 call $~lib/rt/stub/__retain local.set $1 @@ -2983,7 +3196,7 @@ i32.eqz if i32.const 4 - i32.const 16 + i32.const 18 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -2996,7 +3209,7 @@ call $~lib/rt/stub/__release local.get $0 ) - (func $~lib/map/Map<~lib/string/String,i32>#keys (; 39 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#keys (; 48 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) i32.const 0 @@ -3009,7 +3222,7 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#constructor (; 40 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#constructor (; 49 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $1 call $~lib/rt/stub/__retain local.set $1 @@ -3017,7 +3230,7 @@ i32.eqz if i32.const 4 - i32.const 19 + i32.const 21 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -3030,7 +3243,7 @@ call $~lib/rt/stub/__release local.get $0 ) - (func $~lib/map/Map<~lib/string/String,i32>#values (; 41 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#values (; 50 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) i32.const 0 @@ -3043,7 +3256,7 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/set/Set<~lib/string/String>#clear (; 42 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/set/Set<~lib/string/String>#clear (; 51 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) local.get $0 @@ -3083,12 +3296,12 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set<~lib/string/String>#constructor (; 43 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/Set<~lib/string/String>#constructor (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.eqz if i32.const 24 - i32.const 20 + i32.const 22 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -3115,7 +3328,7 @@ call $~lib/set/Set<~lib/string/String>#clear local.get $0 ) - (func $~lib/set/Set<~lib/string/String>#find (; 44 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/Set<~lib/string/String>#find (; 53 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) local.get $1 @@ -3175,7 +3388,7 @@ call $~lib/rt/stub/__release local.get $4 ) - (func $~lib/set/Set<~lib/string/String>#rehash (; 45 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set<~lib/string/String>#rehash (; 54 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3333,7 +3546,7 @@ local.get $5 call $~lib/rt/stub/__release ) - (func $~lib/set/Set<~lib/string/String>#add (; 46 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/set/Set<~lib/string/String>#add (; 55 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3436,7 +3649,7 @@ local.get $1 call $~lib/rt/stub/__release ) - (func $~lib/set/Set<~lib/string/String>#has (; 47 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set<~lib/string/String>#has (; 56 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) local.get $1 @@ -3464,12 +3677,12 @@ call $~lib/rt/stub/__release local.get $2 ) - (func $~lib/set/SetIterator<~lib/string/String>#constructor (; 48 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#constructor (; 57 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.eqz if i32.const 12 - i32.const 23 + i32.const 25 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 @@ -3485,7 +3698,7 @@ i32.store offset=8 local.get $0 ) - (func $~lib/set/Set<~lib/string/String>#values (; 49 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/Set<~lib/string/String>#values (; 58 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) i32.const 0 local.get $0 i32.load offset=8 @@ -3493,13 +3706,13 @@ i32.load offset=16 call $~lib/set/SetIterator<~lib/string/String>#constructor ) - (func $~lib/array/Array<~lib/string/String>#constructor (; 50 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array<~lib/string/String>#constructor (; 59 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 if (result i32) local.get $0 else i32.const 16 - i32.const 22 + i32.const 24 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain end @@ -3515,7 +3728,7 @@ i32.store offset=12 local.get $0 ) - (func $~lib/array/Array<~lib/string/String>#__unchecked_set (; 51 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array<~lib/string/String>#__unchecked_set (; 60 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) local.get $2 @@ -3545,7 +3758,7 @@ local.get $2 call $~lib/rt/stub/__release ) - (func $~lib/array/Array<~lib/string/String>#__set (; 52 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array<~lib/string/String>#__set (; 61 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) local.get $2 call $~lib/rt/stub/__retain local.set $2 @@ -3586,7 +3799,7 @@ local.get $2 call $~lib/rt/stub/__release ) - (func $~lib/array/Array<~lib/string/String>#set:length (; 53 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/array/Array<~lib/string/String>#set:length (; 62 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3635,7 +3848,7 @@ local.get $1 i32.store offset=12 ) - (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 54 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array.from<~lib/string/String,~lib/string/String> (; 63 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3731,7 +3944,7 @@ call $~lib/rt/stub/__release local.get $9 ) - (func $~lib/array/Array<~lib/string/String>#__unchecked_get (; 55 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array<~lib/string/String>#__unchecked_get (; 64 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 i32.load offset=4 local.get $1 @@ -3741,7 +3954,7 @@ i32.load call $~lib/rt/stub/__retain ) - (func $~lib/array/Array<~lib/string/String>#__get (; 56 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array<~lib/string/String>#__get (; 65 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) local.get $1 local.get $0 @@ -3773,12 +3986,14 @@ end local.get $2 ) - (func $start:std/iterator (; 57 ;) (type $FUNCSIG$v) + (func $start:std/iterator (; 66 ;) (type $FUNCSIG$v) (local $0 i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) + (local $5 i32) + (local $6 i32) global.get $~lib/heap/__heap_base i32.const 15 i32.add @@ -3928,6 +4143,39 @@ unreachable end global.get $std/iterator/map + i32.const 0 + call $~lib/array/Array.from<~lib/map/MapEntry<~lib/string/String,i32>,~lib/map/MapEntry<~lib/string/String,i32>> + global.set $std/iterator/entriesArr + global.get $std/iterator/entriesArr + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#get:length + global.get $std/iterator/map + call $~lib/map/Map<~lib/string/String,i32>#get:size + i32.eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 57 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/entriesArr + i32.const 0 + call $~lib/array/Array<~lib/map/MapEntry<~lib/string/String,i32>>#__get + i32.load + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 58 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/map call $~lib/map/Map<~lib/string/String,i32>#keys global.set $std/iterator/keyIter global.get $std/iterator/keyIter @@ -3942,7 +4190,7 @@ if i32.const 0 i32.const 344 - i32.const 58 + i32.const 62 i32.const 0 call $~lib/builtins/abort unreachable @@ -3961,7 +4209,7 @@ if i32.const 0 i32.const 344 - i32.const 62 + i32.const 66 i32.const 0 call $~lib/builtins/abort unreachable @@ -3982,7 +4230,7 @@ if i32.const 0 i32.const 344 - i32.const 67 + i32.const 71 i32.const 0 call $~lib/builtins/abort unreachable @@ -4003,7 +4251,7 @@ if i32.const 0 i32.const 344 - i32.const 70 + i32.const 74 i32.const 0 call $~lib/builtins/abort unreachable @@ -4018,7 +4266,41 @@ if i32.const 0 i32.const 344 - i32.const 71 + i32.const 75 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/strSet + i32.const 0 + call $~lib/array/Array.from<~lib/string/String,~lib/string/String> + global.set $std/iterator/setArray + global.get $std/iterator/setArray + i32.const 0 + call $~lib/array/Array<~lib/string/String>#__get + local.tee $5 + i32.const 392 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 78 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + global.get $std/iterator/setArray + i32.const 1 + call $~lib/array/Array<~lib/string/String>#__get + local.tee $6 + i32.const 424 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 344 + i32.const 79 i32.const 0 call $~lib/builtins/abort unreachable @@ -4033,11 +4315,15 @@ call $~lib/rt/stub/__release local.get $4 call $~lib/rt/stub/__release + local.get $5 + call $~lib/rt/stub/__release + local.get $6 + call $~lib/rt/stub/__release ) - (func $start (; 58 ;) (type $FUNCSIG$v) + (func $start (; 67 ;) (type $FUNCSIG$v) call $start:std/iterator ) - (func $std/iterator/ArrayIterator#next (; 59 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#next (; 68 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 local.get $0 i32.load @@ -4047,7 +4333,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 60 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#next (; 69 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next @@ -4055,7 +4341,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator#next (; 61 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator#next (; 70 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4063,7 +4349,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4075,7 +4361,7 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#next return ) - (func $std/iterator/ArrayIterator#get:done (; 62 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:done (; 71 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 @@ -4083,12 +4369,12 @@ call $~lib/array/Array#get:length i32.ge_s ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 63 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:done (; 72 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult#get:done (; 64 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:done (; 73 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4096,7 +4382,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4108,24 +4394,24 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#get:done return ) - (func $std/iterator/ArrayIterator#get:value (; 65 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/iterator/ArrayIterator#get:value (; 74 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 i32.load call $~lib/array/Array#__get ) - (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 66 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/EntriesIter<~lib/string/String,i32>#get:value (; 75 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/map/EntriesIter<~lib/string/String,i32>#get:entry ) - (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 67 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/ValueIterator<~lib/string/String,i32>#get:value (; 76 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value i32.load offset=4 ) - (func $~lib/iterator/IteratorResult#get:value (; 68 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult#get:value (; 77 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4133,7 +4419,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4145,7 +4431,7 @@ call $~lib/map/ValueIterator<~lib/string/String,i32>#get:value return ) - (func $~lib/iterator/Iterable#get:iterator (; 69 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterable#get:iterator (; 78 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$3 block $switch$1$default local.get $0 @@ -4160,14 +4446,14 @@ call $std/iterator/IterableArray#get:iterator return ) - (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 70 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:value (; 79 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$3 block $switch$1$default local.get $0 i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default end unreachable end @@ -4175,7 +4461,56 @@ call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 71 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/Map<~lib/string/String,i32>#get:iterator (; 80 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#entries + ) + (func $~lib/iterator/Iterable<~lib/map/MapEntry<~lib/string/String,i32>>#get:iterator (; 81 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/Map<~lib/string/String,i32>#get:iterator + return + ) + (func $~lib/iterator/Iterator<~lib/map/MapEntry<~lib/string/String,i32>>#next (; 82 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#next + return + ) + (func $~lib/iterator/IteratorResult<~lib/map/MapEntry<~lib/string/String,i32>>#get:done (; 83 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default + end + unreachable + end + local.get $0 + call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done + return + ) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#next (; 84 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#next @@ -4183,14 +4518,14 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/set/SetIterator<~lib/string/String>#get:done (; 72 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#get:done (; 85 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load local.get $0 i32.load offset=8 i32.ge_u ) - (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 73 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#get:entry (; 86 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load offset=4 local.get $0 @@ -4199,7 +4534,7 @@ i32.mul i32.add ) - (func $~lib/set/SetIterator<~lib/string/String>#next (; 74 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#next (; 87 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 local.get $0 i32.load @@ -4237,7 +4572,7 @@ local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterator<~lib/string/String>#next (; 75 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/Iterator<~lib/string/String>#next (; 88 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4245,7 +4580,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4257,20 +4592,20 @@ call $~lib/set/SetIterator<~lib/string/String>#next return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 76 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:value (; 89 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:value i32.load call $~lib/rt/stub/__retain ) - (func $~lib/set/SetIterator<~lib/string/String>#get:value (; 77 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#get:value (; 90 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/set/SetIterator<~lib/string/String>#get:entry i32.load call $~lib/rt/stub/__retain ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 78 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:value (; 91 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4278,7 +4613,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4290,40 +4625,49 @@ call $~lib/set/SetIterator<~lib/string/String>#get:value return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator (; 79 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator (; 92 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/set/SetIterator<~lib/string/String>#get:iterator (; 80 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/set/SetIterator<~lib/string/String>#get:iterator (; 93 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 call $~lib/rt/stub/__retain ) - (func $~lib/iterator/Iterable<~lib/string/String>#get:iterator (; 81 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - block $switch$1$case$4 - block $switch$1$case$3 - block $switch$1$default - local.get $0 - i32.const 8 - i32.sub - i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + (func $~lib/set/Set<~lib/string/String>#get:iterator (; 94 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + call $~lib/set/Set<~lib/string/String>#values + ) + (func $~lib/iterator/Iterable<~lib/string/String>#get:iterator (; 95 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + block $switch$1$case$5 + block $switch$1$case$4 + block $switch$1$case$3 + block $switch$1$default + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$case$5 $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + end + unreachable end - unreachable + local.get $0 + call $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator + return end local.get $0 - call $~lib/map/KeyIterator<~lib/string/String,i32>#get:iterator + call $~lib/set/SetIterator<~lib/string/String>#get:iterator return end local.get $0 - call $~lib/set/SetIterator<~lib/string/String>#get:iterator + call $~lib/set/Set<~lib/string/String>#get:iterator return ) - (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:done (; 82 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/map/KeyIterator<~lib/string/String,i32>#get:done (; 96 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.load call $~lib/map/EntriesIter<~lib/string/String,i32>#get:done ) - (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 83 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/iterator/IteratorResult<~lib/string/String>#get:done (; 97 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) block $switch$1$case$4 block $switch$1$case$3 block $switch$1$default @@ -4331,7 +4675,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default + br_table $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$3 $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$default $switch$1$case$4 $switch$1$default end unreachable end @@ -4343,7 +4687,7 @@ call $~lib/set/SetIterator<~lib/string/String>#get:done return ) - (func $null (; 84 ;) (type $FUNCSIG$v) + (func $null (; 98 ;) (type $FUNCSIG$v) unreachable ) ) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 02ee6792f5..28d74e0039 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -33,7 +33,7 @@ (data (i32.const 360) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00s\00t\00d\00/\00m\00a\00p\00.\00t\00s") (data (i32.const 400) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00K\00e\00y\00 \00d\00o\00e\00s\00 \00n\00o\00t\00 \00e\00x\00i\00s\00t") (data (i32.const 456) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00~\00l\00i\00b\00/\00m\00a\00p\00.\00t\00s") - (data (i32.const 496) "\0d\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\98D\08\00\00\00\00\00\98D\00\00\00\00\00\00\98\84\08\00\00\00\00\00\98\84\00\00\00\00\00\00\98\04\t\00\00\00\00\00\98\04\01\00\00\00\00\00\98\04\n\00\00\00\00\00\98\04\02\00\00\00\00\00\98\04\19\00\00\00\00\00\98\04\1a") + (data (i32.const 496) "!\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\98D\08\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\04\00\00\00\98D\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\07\00\00\00\98\84\08\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\n\00\00\00\98\84\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\0d\00\00\00\98\04\t\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\10\00\00\00\98\04\01\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\13\00\00\00\98\04\n\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\16\00\00\00\98\04\02\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\19\00\00\00\98\04\19\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1c\00\00\00\98\04\1a\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1f") (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) (global $~lib/rt/tlsf/collectLock (mut i32) (i32.const 0)) (global $~lib/rt/pure/ROOTS (mut i32) (i32.const 0)) @@ -626,10 +626,10 @@ if unreachable end - i32.const 608 + i32.const 768 i32.const 0 i32.store - i32.const 2176 + i32.const 2336 i32.const 0 i32.store i32.const 0 @@ -643,7 +643,7 @@ local.get $0 i32.const 2 i32.shl - i32.const 608 + i32.const 768 i32.add i32.const 0 i32.store offset=4 @@ -662,7 +662,7 @@ i32.add i32.const 2 i32.shl - i32.const 608 + i32.const 768 i32.add i32.const 0 i32.store offset=96 @@ -680,13 +680,13 @@ br $loop|0 end end - i32.const 608 - i32.const 2192 + i32.const 768 + i32.const 2352 memory.size i32.const 16 i32.shl call $~lib/rt/tlsf/addMemory - i32.const 608 + i32.const 768 global.set $~lib/rt/tlsf/ROOT ) (func $~lib/rt/tlsf/prepareSize (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -1378,7 +1378,7 @@ ) (func $~lib/rt/pure/__retain (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.const 604 + i32.const 764 i32.gt_u if local.get $0 @@ -2007,7 +2007,7 @@ ) (func $~lib/rt/pure/__release (; 31 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - i32.const 604 + i32.const 764 i32.gt_u if local.get $0 @@ -2803,7 +2803,7 @@ (func $~lib/map/Map#constructor (; 42 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -3480,7 +3480,7 @@ (func $~lib/map/Map#constructor (; 49 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 5 + i32.const 9 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -4239,7 +4239,7 @@ (func $~lib/map/Map#constructor (; 58 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 6 + i32.const 12 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -4916,7 +4916,7 @@ (func $~lib/map/Map#constructor (; 65 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 7 + i32.const 15 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -5645,7 +5645,7 @@ (func $~lib/map/Map#constructor (; 74 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 8 + i32.const 18 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -6024,7 +6024,7 @@ (func $~lib/map/Map#constructor (; 77 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 9 + i32.const 21 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -6796,7 +6796,7 @@ (func $~lib/map/Map#constructor (; 86 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 10 + i32.const 24 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -7149,7 +7149,7 @@ (func $~lib/map/Map#constructor (; 88 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 11 + i32.const 27 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -7860,7 +7860,7 @@ (func $~lib/map/Map#constructor (; 96 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 12 + i32.const 30 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -8582,7 +8582,7 @@ ) (func $~lib/rt/pure/__visit (; 105 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 - i32.const 604 + i32.const 764 i32.lt_u if return @@ -8699,7 +8699,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $switch$1$default end return end diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index fca7599fd0..d46b04c0ca 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -33,7 +33,7 @@ (data (i32.const 360) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00s\00t\00d\00/\00m\00a\00p\00.\00t\00s\00") (data (i32.const 400) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00K\00e\00y\00 \00d\00o\00e\00s\00 \00n\00o\00t\00 \00e\00x\00i\00s\00t\00") (data (i32.const 456) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00~\00l\00i\00b\00/\00m\00a\00p\00.\00t\00s\00") - (data (i32.const 496) "\0d\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\98D\08\00\00\00\00\00\98D\00\00\00\00\00\00\98\84\08\00\00\00\00\00\98\84\00\00\00\00\00\00\98\04\t\00\00\00\00\00\98\04\01\00\00\00\00\00\98\04\n\00\00\00\00\00\98\04\02\00\00\00\00\00\98\04\19\00\00\00\00\00\98\04\1a\00\00\00\00\00") + (data (i32.const 496) "!\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\98D\08\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\04\00\00\00\98D\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\07\00\00\00\98\84\08\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\n\00\00\00\98\84\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\0d\00\00\00\98\04\t\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\10\00\00\00\98\04\01\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\13\00\00\00\98\04\n\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\16\00\00\00\98\04\02\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\19\00\00\00\98\04\19\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1c\00\00\00\98\04\1a\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1f\00\00\00") (table $0 1 funcref) (elem (i32.const 0) $null) (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) @@ -44,7 +44,7 @@ (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) (global $~lib/rt/__rtti_base i32 (i32.const 496)) - (global $~lib/heap/__heap_base i32 (i32.const 604)) + (global $~lib/heap/__heap_base i32 (i32.const 764)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/tlsf/removeBlock (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) @@ -4510,7 +4510,7 @@ i32.eqz if i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -5378,7 +5378,7 @@ i32.eqz if i32.const 24 - i32.const 5 + i32.const 9 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -6292,7 +6292,7 @@ i32.eqz if i32.const 24 - i32.const 6 + i32.const 12 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -7160,7 +7160,7 @@ i32.eqz if i32.const 24 - i32.const 7 + i32.const 15 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -8046,7 +8046,7 @@ i32.eqz if i32.const 24 - i32.const 8 + i32.const 18 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -8890,7 +8890,7 @@ i32.eqz if i32.const 24 - i32.const 9 + i32.const 21 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -9832,7 +9832,7 @@ i32.eqz if i32.const 24 - i32.const 10 + i32.const 24 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -10686,7 +10686,7 @@ i32.eqz if i32.const 24 - i32.const 11 + i32.const 27 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -11545,7 +11545,7 @@ i32.eqz if i32.const 24 - i32.const 12 + i32.const 30 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -12637,15 +12637,15 @@ (func $~lib/rt/__visit_members (; 150 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) block $switch$1$default - block $switch$1$case$14 - block $switch$1$case$13 - block $switch$1$case$12 - block $switch$1$case$11 - block $switch$1$case$10 - block $switch$1$case$9 - block $switch$1$case$8 - block $switch$1$case$7 - block $switch$1$case$6 + block $switch$1$case$32 + block $switch$1$case$29 + block $switch$1$case$26 + block $switch$1$case$23 + block $switch$1$case$20 + block $switch$1$case$17 + block $switch$1$case$14 + block $switch$1$case$11 + block $switch$1$case$8 block $switch$1$case$5 block $switch$1$case$4 block $switch$1$case$2 @@ -12653,7 +12653,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$5 $switch$1$case$6 $switch$1$case$7 $switch$1$case$8 $switch$1$case$9 $switch$1$case$10 $switch$1$case$11 $switch$1$case$12 $switch$1$case$13 $switch$1$case$14 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$5 $switch$1$case$2 $switch$1$case$2 $switch$1$case$8 $switch$1$case$2 $switch$1$case$2 $switch$1$case$11 $switch$1$case$2 $switch$1$case$2 $switch$1$case$14 $switch$1$case$2 $switch$1$case$2 $switch$1$case$17 $switch$1$case$2 $switch$1$case$2 $switch$1$case$20 $switch$1$case$2 $switch$1$case$2 $switch$1$case$23 $switch$1$case$2 $switch$1$case$2 $switch$1$case$26 $switch$1$case$2 $switch$1$case$2 $switch$1$case$29 $switch$1$case$2 $switch$1$case$2 $switch$1$case$32 $switch$1$case$2 $switch$1$case$2 $switch$1$default end return end diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index 219f454d0a..3cee22d365 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -31,7 +31,7 @@ (data (i32.const 264) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e") (data (i32.const 320) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00~\00l\00i\00b\00/\00r\00t\00.\00t\00s") (data (i32.const 360) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00s\00t\00d\00/\00s\00e\00t\00.\00t\00s") - (data (i32.const 400) "\0d\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\004\04\00\00\00\00\00\004\00\00\00\00\00\00\00T\04\00\00\00\00\00\00T\00\00\00\00\00\00\00\94\04\00\00\00\00\00\00\94\00\00\00\00\00\00\00\14\05\00\00\00\00\00\00\14\01\00\00\00\00\00\00\94\0c\00\00\00\00\00\00\14\0d") + (data (i32.const 400) "!\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\004\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\04\00\00\004\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\07\00\00\00T\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\n\00\00\00T\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\0d\00\00\00\94\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\10\00\00\00\94\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\13\00\00\00\14\05\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\16\00\00\00\14\01\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\19\00\00\00\94\0c\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1c\00\00\00\14\0d\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1f") (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) (global $~lib/rt/tlsf/collectLock (mut i32) (i32.const 0)) (global $~lib/rt/pure/ROOTS (mut i32) (i32.const 0)) @@ -624,10 +624,10 @@ if unreachable end - i32.const 512 + i32.const 672 i32.const 0 i32.store - i32.const 2080 + i32.const 2240 i32.const 0 i32.store i32.const 0 @@ -641,7 +641,7 @@ local.get $0 i32.const 2 i32.shl - i32.const 512 + i32.const 672 i32.add i32.const 0 i32.store offset=4 @@ -660,7 +660,7 @@ i32.add i32.const 2 i32.shl - i32.const 512 + i32.const 672 i32.add i32.const 0 i32.store offset=96 @@ -678,13 +678,13 @@ br $loop|0 end end - i32.const 512 - i32.const 2096 + i32.const 672 + i32.const 2256 memory.size i32.const 16 i32.shl call $~lib/rt/tlsf/addMemory - i32.const 512 + i32.const 672 global.set $~lib/rt/tlsf/ROOT ) (func $~lib/rt/tlsf/prepareSize (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -1376,7 +1376,7 @@ ) (func $~lib/rt/pure/__retain (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.const 508 + i32.const 668 i32.gt_u if local.get $0 @@ -2005,7 +2005,7 @@ ) (func $~lib/rt/pure/__release (; 31 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - i32.const 508 + i32.const 668 i32.gt_u if local.get $0 @@ -2668,7 +2668,7 @@ (func $~lib/set/Set#constructor (; 41 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -3228,7 +3228,7 @@ (func $~lib/set/Set#constructor (; 47 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 5 + i32.const 9 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -3854,7 +3854,7 @@ (func $~lib/set/Set#constructor (; 55 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 6 + i32.const 12 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -4414,7 +4414,7 @@ (func $~lib/set/Set#constructor (; 61 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 7 + i32.const 15 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -5042,7 +5042,7 @@ (func $~lib/set/Set#constructor (; 69 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 8 + i32.const 18 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -5350,7 +5350,7 @@ (func $~lib/set/Set#constructor (; 72 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 9 + i32.const 21 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -6014,7 +6014,7 @@ (func $~lib/set/Set#constructor (; 80 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 10 + i32.const 24 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -6289,7 +6289,7 @@ (func $~lib/set/Set#constructor (; 82 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 11 + i32.const 27 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -6891,7 +6891,7 @@ (func $~lib/set/Set#constructor (; 89 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 12 + i32.const 30 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.tee $0 @@ -7504,7 +7504,7 @@ ) (func $~lib/rt/pure/__visit (; 97 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 - i32.const 508 + i32.const 668 i32.lt_u if return @@ -7621,7 +7621,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $folding-inner0 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $folding-inner0 $switch$1$case$2 $switch$1$case$2 $switch$1$default end return end diff --git a/tests/compiler/std/set.untouched.wat b/tests/compiler/std/set.untouched.wat index 9713655ac1..28c6d1794b 100644 --- a/tests/compiler/std/set.untouched.wat +++ b/tests/compiler/std/set.untouched.wat @@ -31,7 +31,7 @@ (data (i32.const 264) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00") (data (i32.const 320) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00~\00l\00i\00b\00/\00r\00t\00.\00t\00s\00") (data (i32.const 360) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00s\00t\00d\00/\00s\00e\00t\00.\00t\00s\00") - (data (i32.const 400) "\0d\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\004\04\00\00\00\00\00\004\00\00\00\00\00\00\00T\04\00\00\00\00\00\00T\00\00\00\00\00\00\00\94\04\00\00\00\00\00\00\94\00\00\00\00\00\00\00\14\05\00\00\00\00\00\00\14\01\00\00\00\00\00\00\94\0c\00\00\00\00\00\00\14\0d\00\00\00\00\00\00") + (data (i32.const 400) "!\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\00\00\00\004\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\04\00\00\004\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\07\00\00\00T\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\n\00\00\00T\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\0d\00\00\00\94\04\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\10\00\00\00\94\00\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\13\00\00\00\14\05\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\16\00\00\00\14\01\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\19\00\00\00\94\0c\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1c\00\00\00\14\0d\00\00\00\00\00\00\10\00\00\00\00\00\00\00\10\00\00\00\1f\00\00\00") (table $0 1 funcref) (elem (i32.const 0) $null) (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) @@ -42,7 +42,7 @@ (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) (global $~lib/rt/__rtti_base i32 (i32.const 400)) - (global $~lib/heap/__heap_base i32 (i32.const 508)) + (global $~lib/heap/__heap_base i32 (i32.const 668)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/tlsf/removeBlock (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) @@ -4360,7 +4360,7 @@ i32.eqz if i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -5096,7 +5096,7 @@ i32.eqz if i32.const 24 - i32.const 5 + i32.const 9 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -5862,7 +5862,7 @@ i32.eqz if i32.const 24 - i32.const 6 + i32.const 12 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -6598,7 +6598,7 @@ i32.eqz if i32.const 24 - i32.const 7 + i32.const 15 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -7368,7 +7368,7 @@ i32.eqz if i32.const 24 - i32.const 8 + i32.const 18 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -8096,7 +8096,7 @@ i32.eqz if i32.const 24 - i32.const 9 + i32.const 21 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -8915,7 +8915,7 @@ i32.eqz if i32.const 24 - i32.const 10 + i32.const 24 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -9646,7 +9646,7 @@ i32.eqz if i32.const 24 - i32.const 11 + i32.const 27 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -10381,7 +10381,7 @@ i32.eqz if i32.const 24 - i32.const 12 + i32.const 30 call $~lib/rt/tlsf/__alloc call $~lib/rt/pure/__retain local.set $0 @@ -11349,15 +11349,15 @@ (func $~lib/rt/__visit_members (; 140 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) block $switch$1$default - block $switch$1$case$14 - block $switch$1$case$13 - block $switch$1$case$12 - block $switch$1$case$11 - block $switch$1$case$10 - block $switch$1$case$9 - block $switch$1$case$8 - block $switch$1$case$7 - block $switch$1$case$6 + block $switch$1$case$32 + block $switch$1$case$29 + block $switch$1$case$26 + block $switch$1$case$23 + block $switch$1$case$20 + block $switch$1$case$17 + block $switch$1$case$14 + block $switch$1$case$11 + block $switch$1$case$8 block $switch$1$case$5 block $switch$1$case$4 block $switch$1$case$2 @@ -11365,7 +11365,7 @@ i32.const 8 i32.sub i32.load - br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$5 $switch$1$case$6 $switch$1$case$7 $switch$1$case$8 $switch$1$case$9 $switch$1$case$10 $switch$1$case$11 $switch$1$case$12 $switch$1$case$13 $switch$1$case$14 $switch$1$default + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$5 $switch$1$case$2 $switch$1$case$2 $switch$1$case$8 $switch$1$case$2 $switch$1$case$2 $switch$1$case$11 $switch$1$case$2 $switch$1$case$2 $switch$1$case$14 $switch$1$case$2 $switch$1$case$2 $switch$1$case$17 $switch$1$case$2 $switch$1$case$2 $switch$1$case$20 $switch$1$case$2 $switch$1$case$2 $switch$1$case$23 $switch$1$case$2 $switch$1$case$2 $switch$1$case$26 $switch$1$case$2 $switch$1$case$2 $switch$1$case$29 $switch$1$case$2 $switch$1$case$2 $switch$1$case$32 $switch$1$case$2 $switch$1$case$2 $switch$1$default end return end diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index c4de426636..b4b8f9787d 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -444,7 +444,7 @@ (func $~lib/map/Map#constructor (; 8 ;) (result i32) (local $0 i32) i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/stub/__alloc local.tee $0 i32.const 0 diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index e340b693a4..7f71af4c91 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -600,7 +600,7 @@ i32.eqz if i32.const 24 - i32.const 4 + i32.const 6 call $~lib/rt/stub/__alloc call $~lib/rt/stub/__retain local.set $0 From 2f5836367844abf374cfc938ce4164d28623fe78 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 17 Dec 2019 19:02:52 -0500 Subject: [PATCH 47/47] addresses nitpicks --- NOTICE | 2 +- package-lock.json | 30 +-------- src/compiler.ts | 91 ++++++++++---------------- src/program.ts | 51 ++++++--------- src/util/collections.ts | 21 ------ tests/compiler/interface-fail.json | 2 +- tests/compiler/interface-fail.ts | 4 +- tests/compiler/interface.optimized.wat | 6 +- tests/compiler/interface.ts | 7 +- tests/compiler/interface.untouched.wat | 8 +-- 10 files changed, 71 insertions(+), 151 deletions(-) diff --git a/NOTICE b/NOTICE index 92a78f1255..69d8e52273 100644 --- a/NOTICE +++ b/NOTICE @@ -13,7 +13,7 @@ under the licensing terms detailed in LICENSE: * Joshua Tenner * Nidin Vinayakan <01@01alchemist.com> * Aaron Turner -* Willem Wyndham or +* Willem Wyndham * Bowen Wang * Emil Laine * Stephen Paul Weber diff --git a/package-lock.json b/package-lock.json index 11b1485164..5d2e0cedf5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1074,14 +1074,6 @@ "semver": "^5.5.0", "shebang-command": "^1.2.0", "which": "^1.2.9" - }, - "dependencies": { - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - } } }, "crypto-browserify": { @@ -2775,14 +2767,6 @@ "requires": { "pify": "^4.0.1", "semver": "^5.6.0" - }, - "dependencies": { - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - } } }, "make-error": { @@ -3711,9 +3695,9 @@ } }, "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true }, "serialize-javascript": { @@ -4236,14 +4220,6 @@ "semver": "^5.3.0", "tslib": "^1.8.0", "tsutils": "^2.29.0" - }, - "dependencies": { - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - } } }, "tsutils": { diff --git a/src/compiler.ts b/src/compiler.ts index e1bd099b89..9f3727a847 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -1516,11 +1516,7 @@ export class Compiler extends DiagnosticEmitter { contextualTypeArguments: Map | null = null, alternativeReportNode: Node | null = null ): void { - // TODO Compile functions to use - // this.error( - // DiagnosticCode.Operation_not_supported, - // declaration.range - // ); + // TODO: Allow multiple interfaces with the same name to merge } // === Memory =================================================================================== @@ -3061,7 +3057,7 @@ export class Compiler extends DiagnosticEmitter { fromType.toString(), toType.toString()); } else { - //Also checks abstract methods + // Also checks abstract methods if (this.checkInterfaceImplementation(toType, fromType, reportNode)) { toType.classReference!.addImplementer(fromType.classReference); } else { @@ -9283,13 +9279,14 @@ export class Compiler extends DiagnosticEmitter { checkInterfaceImplementation(toType: Type, fromType: Type, reportNode: Node): bool { const _interface = (toType.classReference!); const _class = fromType.classReference!; - var imems: Map; - var mems: Map | null; + assert(_interface != null); + assert(_class != null); if (_interface.members == null) { return true; } - imems = _interface.members; - mems = _class.members; + + var imems: Map = _interface.members; + var mems: Map | null = _class.members; var error = false; var incorrectMember = false; @@ -9329,31 +9326,28 @@ export class Compiler extends DiagnosticEmitter { let from: Type = Type.void, to: Type = Type.void; switch (mem.kind) { case ElementKind.FIELD: { - mem = (mem).prototype; - imem = (imem).prototype; - } - case ElementKind.FIELD_PROTOTYPE: { - from = this.resolver.resolveType((mem).typeNode!, _class)!; - to = this.resolver.resolveType((imem).getterPrototype!.functionTypeNode, imem, _interface.contextualTypeArguments, ReportMode.REPORT)!.signatureReference!.returnType; + from = (mem).type!; + to = (imem).getterInstance!.signature!.returnType; break; } - case ElementKind.FUNCTION: { - mem = (mem).prototype; - imem = (mem).prototype; - } case ElementKind.FUNCTION_PROTOTYPE: { let func = (mem); from = this.resolver.resolveType(func.functionTypeNode, func, _class.contextualTypeArguments)!; to = this.resolver.resolveType((imem).functionTypeNode, imem, _interface.contextualTypeArguments)!; break; } + case ElementKind.FUNCTION: { + from = (mem).signature.type; + to = (imem).signature.type; + break; + } case ElementKind.PROPERTY: { mem = (mem).prototype; imem = (imem).prototype; } case ElementKind.PROPERTY_PROTOTYPE: { - const property = mem; - const iproperty = imem; + const property = mem; + const iproperty = imem; if (!iproperty.isAny(CommonFlags.READONLY | CommonFlags.ABSTRACT)) { if (property.setterPrototype == null) { this.error( @@ -9400,14 +9394,14 @@ export class Compiler extends DiagnosticEmitter { } incorrectMember = false; } - error = error || incorrectMember;// case where contiune skips the last check. + error = error || incorrectMember; // case where continue skips the last check. if (error) { this.error( DiagnosticCode.Class_0_incorrectly_implements_interface_1, _class.identifierNode.range, - fromType.toString(), - toType.toString() - ); + fromType.toString(), + toType.toString() + ); } return !error; } @@ -9463,7 +9457,6 @@ export class Compiler extends DiagnosticEmitter { const isVoid = returnType.toNativeType() == NativeType.None; const first = relooper.addBlockWithSwitch(module.nop(), this.loadClassID()); - const defaultVal = defaultTypeValue(returnType.toNativeType(), module); const last = relooper.addBlock(module.unreachable()); // default branch relooper.addBranch(first, last); @@ -9481,7 +9474,7 @@ export class Compiler extends DiagnosticEmitter { // finish relooper and prepare body of function let switchExpression = relooper.renderAndDispose(first, 0); - let block = isVoid ? [switchExpression] : [switchExpression, defaultVal]; + let block = isVoid ? [switchExpression] : [switchExpression, this.makeZero(returnType)]; let body = module.block(null, block, returnType.toNativeType()); // Remove the nop standin @@ -9502,7 +9495,7 @@ export class Compiler extends DiagnosticEmitter { var method: Function; switch (prop.kind){ case ElementKind.FUNCTION_PROTOTYPE: { - let p = prop; + let p = prop; let newFunc = this.resolver.resolveFunction(p, null, (func.parent).contextualTypeArguments); if (newFunc == null) { throw new Error(`Couldn't resolve ${p.name}`); @@ -9510,20 +9503,20 @@ export class Compiler extends DiagnosticEmitter { prop = newFunc; } case ElementKind.FUNCTION: { - method = prop; + method = prop; break; } case ElementKind.FIELD: { - let field = prop; + let field = prop; return field; } case ElementKind.PROPERTY: { - let p = prop; + let p = prop; if (func.is(CommonFlags.SET)) { method = p.setterInstance!; - }else if (func.is(CommonFlags.GET)) { + } else if (func.is(CommonFlags.GET)) { method = p.getterInstance!; - }else { + } else { throw Error("Interface method " + func.name + " should be a property"); } break; @@ -9543,7 +9536,7 @@ export class Compiler extends DiagnosticEmitter { var method: Function; switch (prop.kind){ case ElementKind.FUNCTION_PROTOTYPE: { - let p = prop; + let p = prop; let newFunc = this.resolver.resolveFunction(p, null, (ifunc.parent).contextualTypeArguments); if (newFunc == null) { throw new Error(`Couldn't resolve ${p.name}`); @@ -9551,11 +9544,11 @@ export class Compiler extends DiagnosticEmitter { prop = newFunc; } case ElementKind.FUNCTION: { - method = prop; + method = prop; break; } case ElementKind.FIELD: { - let field = prop; + let field = prop; let type = field.type; let nativeType = type.toNativeType(); const thisExpr = module.local_get(0, this.nativeUsizeType); @@ -9587,12 +9580,12 @@ export class Compiler extends DiagnosticEmitter { } } case ElementKind.PROPERTY: { - let p = prop; + let p = prop; if (ifunc.is(CommonFlags.SET)) { method = p.setterInstance!; - }else if (ifunc.is(CommonFlags.GET)) { + } else if (ifunc.is(CommonFlags.GET)) { method = p.getterInstance!; - }else { + } else { throw Error("Interface method " + ifunc.name + " should be a property"); } break; @@ -9650,24 +9643,6 @@ export class Compiler extends DiagnosticEmitter { const v128_zero = new Uint8Array(16); -/* Useful for adding to the end of a block that needs a type even if there is an unreachable(); */ -export function defaultTypeValue(nativeType: NativeType, module: Module): ExpressionRef { - switch (nativeType) { - case NativeType.I64: return module.i64(0); - case NativeType.F32: return module.f32(0); - case NativeType.F64: return module.f64(0); - case NativeType.V128: return module.v128(v128_zero); - case NativeType.Unreachable: return module.unreachable(); - case NativeType.None: return module.nop(); - case NativeType.I32: - case NativeType.Anyref: - case NativeType.Exnref: - default: { - return module.i32(0); - } - } -} - function mangleImportName( element: Element, declaration: DeclarationStatement diff --git a/src/program.ts b/src/program.ts index 696aab2721..6b3aed60ec 100644 --- a/src/program.ts +++ b/src/program.ts @@ -917,9 +917,13 @@ export class Program extends DiagnosticEmitter { if (!baseElement) continue; if (baseElement.kind == ElementKind.CLASS_PROTOTYPE || baseElement.kind == ElementKind.INTERFACE_PROTOTYPE) { let basePrototype = baseElement; - if (thisPrototype.kind == ElementKind.INTERFACE_PROTOTYPE) { + if (thisPrototype.kind == ElementKind.INTERFACE_PROTOTYPE && baseElement.kind == ElementKind.CLASS_PROTOTYPE) { // TODO: Interface extends class // basePrototype = InterfacePrototype.fromClassPrototype(basePrototype); + this.error( + DiagnosticCode.Not_implemented, + Range.join(thisPrototype.identifierNode.range, extendsNode.range) + ); } else { if (basePrototype.hasDecorator(DecoratorFlags.SEALED)) { this.error( @@ -1837,37 +1841,26 @@ export class Program extends DiagnosticEmitter { if (!parent.add(name, element)) return null; var memberDeclarations = declaration.members; if (declaration.extendsType) queuedExtends.push(element); - var instanceDeclarations = new Array(); - /** - * Must convert field declarations to property declarations - */ for (let i = 0, k = memberDeclarations.length; i < k; ++i) { let memberDeclaration = memberDeclarations[i]; - if (memberDeclaration.kind == NodeKind.FIELDDECLARATION) { - let fieldDecl = memberDeclaration; - if (!fieldDecl.is(CommonFlags.READONLY)) { - const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range); - const signature = Node.createFunctionType([param], Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); - instanceDeclarations.push(Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.SET, fieldDecl.range)); - } - const signature = Node.createFunctionType([], fieldDecl.type || Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); - memberDeclaration = Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range); - }else if (memberDeclaration.kind == NodeKind.METHODDECLARATION && - (memberDeclaration.is(CommonFlags.GET) || memberDeclaration.is(CommonFlags.SET))) { - //TODO check that you can't have a property in an interface - } - instanceDeclarations.push(memberDeclaration); - } - for (let i = 0, k = instanceDeclarations.length; i < k; ++i) { - let memberDeclaration = instanceDeclarations[i]; switch (memberDeclaration.kind) { case NodeKind.FIELDDECLARATION: { - this.initializeField(memberDeclaration, element); + let fieldDecl = memberDeclaration; + if (!fieldDecl.is(CommonFlags.READONLY)) { + const param = Node.createParameter(fieldDecl.name, fieldDecl.type!, null, ParameterKind.DEFAULT, fieldDecl.range); + const signature = Node.createFunctionType([param], Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); + const setter = Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.SET, fieldDecl.range); + this.initializeProperty(setter, element); + } + const signature = Node.createFunctionType([], fieldDecl.type || Node.createOmittedType(fieldDecl.range), null, false, fieldDecl.range); + memberDeclaration = Node.createMethodDeclaration(memberDeclaration.name, null, signature, null, fieldDecl.decorators, fieldDecl.flags | CommonFlags.GET, fieldDecl.range); + this.initializeProperty(memberDeclaration, element); break; } case NodeKind.METHODDECLARATION: { if (memberDeclaration.isAny(CommonFlags.GET | CommonFlags.SET)) { - this.initializeProperty(memberDeclaration, element); + // Throw error + //this.initializeProperty(memberDeclaration, element); } else { this.initializeMethod(memberDeclaration, element); } @@ -3438,9 +3431,6 @@ export class Class extends TypedElement { /** 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; - if (target.kind == ElementKind.INTERFACE) { - return true; - } do if (current == target) return true; while (current = current.base); return false; @@ -3688,12 +3678,13 @@ export class InterfacePrototype extends ClassPrototype { } /** Convert a class to an interface when an interface extends a class */ static fromClassPrototype(cP: ClassPrototype): InterfacePrototype { - const cDecl = cP.declaration; + const cDecl = cP.declaration; const iDecl = new InterfaceDeclaration(); iDecl.typeParameters = cDecl.typeParameters; iDecl.extendsType = cDecl.extendsType; iDecl.implementsTypes = cDecl.implementsTypes; iDecl.members = cDecl.members; + iDecl.range = cDecl.range; return new InterfacePrototype(cP.name, cP.parent, iDecl, cP.decoratorFlags); } } @@ -3705,7 +3696,7 @@ export class Interface extends Class { // FIXME nameInclTypeParameters: string, prototype: InterfacePrototype, typeArguments: Type[] | null = [], - base: Interface | Class | null = null // interface can extend classes in typescript + base: Class | null = null // interface can extend classes in typescript ) { super( nameInclTypeParameters, @@ -3715,7 +3706,7 @@ export class Interface extends Class { // FIXME true ); } - // Overrides class.addImplementer for casses when implementer is also interfaces + // Overrides class.addImplementer for cases when implementer is also interfaces addImplementer(_class: Class): void { if (_class.kind == ElementKind.INTERFACE) { _class.implementers.forEach((_class: Class) => { diff --git a/src/util/collections.ts b/src/util/collections.ts index 0267e18010..db47579cf5 100644 --- a/src/util/collections.ts +++ b/src/util/collections.ts @@ -27,24 +27,3 @@ export function makeMap(original: Map | null = null, overrides: Map(iter: Iterable, func: (t: T) => bool): T[] { - const res: T[] = []; - for (let i of iter) { - if (func(i)) { - res.push(i); - } - } - return res; -} -export function map(iter: Iterable, func: (t: T) => R): R[] { - const res: R[] = []; - for (let i of iter) { - res.push(func(i)); - } - return res; -} - -export function notNull(t: T): bool { - return t != null; -} diff --git a/tests/compiler/interface-fail.json b/tests/compiler/interface-fail.json index 0c23e3fea4..e9199268cf 100644 --- a/tests/compiler/interface-fail.json +++ b/tests/compiler/interface-fail.json @@ -37,7 +37,7 @@ "class BadProps implements Properties {", "TS2322: Type 'interface-fail/BadProps' is not assignable to type 'interface-fail/Properties'.", - "const badProp = new BadProps();" + "const badProp = new BadProps();" ] diff --git a/tests/compiler/interface-fail.ts b/tests/compiler/interface-fail.ts index e09a1f5e32..06561299ca 100644 --- a/tests/compiler/interface-fail.ts +++ b/tests/compiler/interface-fail.ts @@ -45,11 +45,11 @@ class BadProps implements Properties { } } -const badProp = new BadProps(); +const badProp = new BadProps(); const badVal = badProp.val; function badFunc(prop: Properties): void { const val = prop.val; } -badFunc(badProp); \ No newline at end of file +badFunc(badProp); diff --git a/tests/compiler/interface.optimized.wat b/tests/compiler/interface.optimized.wat index 48bae9508a..6ffe3cee09 100644 --- a/tests/compiler/interface.optimized.wat +++ b/tests/compiler/interface.optimized.wat @@ -92,7 +92,7 @@ if i32.const 0 i32.const 24 - i32.const 42 + i32.const 41 i32.const 2 call $~lib/builtins/abort unreachable @@ -137,7 +137,7 @@ if i32.const 0 i32.const 24 - i32.const 51 + i32.const 50 i32.const 2 call $~lib/builtins/abort unreachable @@ -190,7 +190,7 @@ if i32.const 0 i32.const 24 - i32.const 59 + i32.const 58 i32.const 0 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/interface.ts b/tests/compiler/interface.ts index c337ded1e1..57fb8db213 100644 --- a/tests/compiler/interface.ts +++ b/tests/compiler/interface.ts @@ -24,7 +24,7 @@ class AFoo implements IFoo { class StructurallyImplementsIFoo { i: i32 = 41; x: bool = false; - + foo(i: i32): i32 { return this.i + i; } @@ -37,12 +37,11 @@ class StructurallyImplementsIFoo { const aFoo = new AFoo(); const sFoo = new StructurallyImplementsIFoo(); - function passAnInterface(foo: IFoo): void { assert(foo.foo(1) == 42); assert(foo.faa(1,3) == 4); } - +// const num = aFoo.foo(1); passAnInterface(aFoo); passAnInterface(sFoo); @@ -54,6 +53,6 @@ function expectX(foo: IFoo, x: bool): void { expectX(aFoo, false); expectX(sFoo, true); -const iFoo = aFoo; +const iFoo = aFoo; const ibool = iFoo.x; assert(!ibool); diff --git a/tests/compiler/interface.untouched.wat b/tests/compiler/interface.untouched.wat index 689130b33a..c397b4c196 100644 --- a/tests/compiler/interface.untouched.wat +++ b/tests/compiler/interface.untouched.wat @@ -182,7 +182,7 @@ if i32.const 0 i32.const 24 - i32.const 42 + i32.const 41 i32.const 2 call $~lib/builtins/abort unreachable @@ -197,7 +197,7 @@ if i32.const 0 i32.const 24 - i32.const 43 + i32.const 42 i32.const 2 call $~lib/builtins/abort unreachable @@ -224,7 +224,7 @@ if i32.const 0 i32.const 24 - i32.const 51 + i32.const 50 i32.const 2 call $~lib/builtins/abort unreachable @@ -273,7 +273,7 @@ if i32.const 0 i32.const 24 - i32.const 59 + i32.const 58 i32.const 0 call $~lib/builtins/abort unreachable