From 8571df939f2167e6f94ad2552bcc154aac8feedd Mon Sep 17 00:00:00 2001 From: dcode Date: Sat, 15 Jun 2019 22:44:48 +0200 Subject: [PATCH 1/2] Add built-in valueof type --- src/common.ts | 1 + src/program.ts | 6 + src/resolver.ts | 150 ++++++++++++++++++------ std/assembly/index.d.ts | 2 + std/assembly/typedarray.ts | 2 +- std/portable/index.d.ts | 3 + tests/compiler/valueof.json | 5 + tests/compiler/valueof.optimized.wat | 9 ++ tests/compiler/valueof.ts | 26 +++++ tests/compiler/valueof.untouched.wat | 168 +++++++++++++++++++++++++++ 10 files changed, 333 insertions(+), 39 deletions(-) create mode 100644 tests/compiler/valueof.json create mode 100644 tests/compiler/valueof.optimized.wat create mode 100644 tests/compiler/valueof.ts create mode 100644 tests/compiler/valueof.untouched.wat diff --git a/src/common.ts b/src/common.ts index 3191265603..5ddef23649 100644 --- a/src/common.ts +++ b/src/common.ts @@ -134,6 +134,7 @@ export namespace CommonSymbols { export const boolean = "boolean"; export const string = "string"; export const native = "native"; + export const valueof = "valueof"; // aliases export const null_ = "null"; export const true_ = "true"; diff --git a/src/program.ts b/src/program.ts index 683fd2f60a..f354e34766 100644 --- a/src/program.ts +++ b/src/program.ts @@ -567,6 +567,12 @@ export class Program extends DiagnosticEmitter { this.makeNativeTypeDeclaration(CommonSymbols.native, CommonFlags.EXPORT | CommonFlags.GENERIC), DecoratorFlags.BUILTIN )); + this.nativeFile.add(CommonSymbols.valueof, new TypeDefinition( + CommonSymbols.valueof, + this.nativeFile, + this.makeNativeTypeDeclaration(CommonSymbols.valueof, CommonFlags.EXPORT | CommonFlags.GENERIC), + DecoratorFlags.BUILTIN + )); if (options.hasFeature(Feature.SIMD)) this.registerNativeType(CommonSymbols.v128, Type.v128); // register compiler hints diff --git a/src/resolver.ts b/src/resolver.ts index cdc7857e92..9ccb32cbc4 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -212,10 +212,10 @@ export class Resolver extends DiagnosticEmitter { var typeNode = node; var typeName = typeNode.name; var typeArgumentNodes = typeNode.typeArguments; - var possiblyPlaceholder = !typeName.next; + var isSimpleType = !typeName.next; - // look up in contextual type arguments if possibly a placeholder - if (possiblyPlaceholder) { + // look up in contextual type arguments if a simple type + if (isSimpleType) { if (contextualTypeArguments && contextualTypeArguments.has(typeName.identifier.text)) { let type = contextualTypeArguments.get(typeName.identifier.text)!; if (typeArgumentNodes !== null && typeArgumentNodes.length) { @@ -314,41 +314,11 @@ export class Resolver extends DiagnosticEmitter { return type; } - // handle special native type - if (possiblyPlaceholder && typeName.identifier.text == CommonSymbols.native) { - if (!(typeArgumentNodes && typeArgumentNodes.length == 1)) { - if (reportMode == ReportMode.REPORT) { - this.error( - DiagnosticCode.Expected_0_type_arguments_but_got_1, - typeNode.range, "1", (typeArgumentNodes ? typeArgumentNodes.length : 1).toString(10) - ); - } - return null; - } - let typeArgument = this.resolveType( - typeArgumentNodes[0], - context, - contextualTypeArguments, - reportMode - ); - if (!typeArgument) return null; - switch (typeArgument.kind) { - case TypeKind.I8: - case TypeKind.I16: - case TypeKind.I32: return Type.i32; - case TypeKind.ISIZE: if (!this.program.options.isWasm64) return Type.i32; - case TypeKind.I64: return Type.i64; - case TypeKind.U8: - case TypeKind.U16: - case TypeKind.U32: - case TypeKind.BOOL: return Type.u32; - case TypeKind.USIZE: if (!this.program.options.isWasm64) return Type.u32; - case TypeKind.U64: return Type.u64; - case TypeKind.F32: return Type.f32; - case TypeKind.F64: return Type.f64; - case TypeKind.V128: return Type.v128; - case TypeKind.VOID: return Type.void; - default: assert(false); + // handle built-in types + if (isSimpleType) { + switch (typeName.identifier.symbol) { + case CommonSymbols.native: return this.resolveBuiltinNativeType(typeNode, context, contextualTypeArguments, reportMode); + case CommonSymbols.valueof: return this.resolveBuiltinValueofType(typeNode, context, contextualTypeArguments, reportMode) } } @@ -402,6 +372,110 @@ export class Resolver extends DiagnosticEmitter { return null; } + private resolveBuiltinNativeType( + /** The type to resolve. */ + typeNode: TypeNode, + /** Relative context. */ + context: Element, + /** Type arguments inherited through context, i.e. `T`. */ + contextualTypeArguments: Map | null = null, + /** How to proceed with eventualy diagnostics. */ + reportMode: ReportMode = ReportMode.REPORT + ): Type | null { + var typeArgumentNodes = typeNode.typeArguments; + if (!(typeArgumentNodes && typeArgumentNodes.length == 1)) { + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Expected_0_type_arguments_but_got_1, + typeNode.range, "1", (typeArgumentNodes ? typeArgumentNodes.length : 1).toString(10) + ); + } + return null; + } + var typeArgument = this.resolveType(typeArgumentNodes[0], context, contextualTypeArguments, reportMode); + if (!typeArgument) return null; + switch (typeArgument.kind) { + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.I32: return Type.i32; + case TypeKind.ISIZE: if (!this.program.options.isWasm64) return Type.i32; + case TypeKind.I64: return Type.i64; + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.U32: + case TypeKind.BOOL: return Type.u32; + case TypeKind.USIZE: if (!this.program.options.isWasm64) return Type.u32; + case TypeKind.U64: return Type.u64; + case TypeKind.F32: return Type.f32; + case TypeKind.F64: return Type.f64; + case TypeKind.V128: return Type.v128; + case TypeKind.VOID: return Type.void; + default: assert(false); + } + return null; + } + + private resolveBuiltinValueofType( + /** The type to resolve. */ + typeNode: TypeNode, + /** Relative context. */ + context: Element, + /** Type arguments inherited through context, i.e. `T`. */ + contextualTypeArguments: Map | null = null, + /** How to proceed with eventualy diagnostics. */ + reportMode: ReportMode = ReportMode.REPORT + ): Type | null { + var typeArgumentNodes = typeNode.typeArguments; + if (!(typeArgumentNodes && typeArgumentNodes.length == 1)) { + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Expected_0_type_arguments_but_got_1, + typeNode.range, "1", (typeArgumentNodes ? typeArgumentNodes.length : 1).toString(10) + ); + } + return null; + } + var typeArgument = this.resolveType(typeArgumentNodes[0], context, contextualTypeArguments, reportMode); + if (!typeArgument) return null; + var classReference = typeArgument.classReference; + if (!classReference) { + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + typeArgumentNodes[0].range, typeArgument.toString() + ); + } + return null; + } + var program = this.program; + var mapPrototype = program.mapPrototype; + var setPrototype = program.setPrototype; + var arrayPrototype = program.arrayPrototype; + if (classReference.extends(arrayPrototype)) { + let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); + assert(actualTypeArguments.length == 1); + return actualTypeArguments[0]; + } else if (classReference.extends(mapPrototype)) { + let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); + assert(actualTypeArguments.length == 2); + return actualTypeArguments[1]; + } else if (classReference.extends(setPrototype)) { + let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); + assert(actualTypeArguments.length == 1); + return actualTypeArguments[0]; + } else { + let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + if (overload) return overload.signature.returnType; + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + typeArgumentNodes[0].range, typeArgument.toString() + ); + } + return null; + } + } + /** Resolves a type name to the program element it refers to. */ resolveTypeName( /** The type name to resolve. */ diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 02b7ccdebf..71c57a2a96 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -882,6 +882,8 @@ declare namespace v8x16 { } /** Macro type evaluating to the underlying native WebAssembly type. */ declare type native = T; +/** Special type evaluating the value type of a collection. */ +declare type valueof = T[0]; /** Pseudo-class representing the backing class of integer types. */ declare class _Integer { diff --git a/std/assembly/typedarray.ts b/std/assembly/typedarray.ts index 3965de7199..493dc6d25e 100644 --- a/std/assembly/typedarray.ts +++ b/std/assembly/typedarray.ts @@ -1068,7 +1068,7 @@ function FOREACH( // @ts-ignore: decorator @inline -export function REVERSE(array: TArray): TArray { +function REVERSE(array: TArray): TArray { var dataStart = array.dataStart; for (let front = 0, back = array.length - 1; front < back; ++front, --back) { let frontPtr = dataStart + (front << alignof()); diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index ab049ee37e..67552f8df9 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -28,6 +28,9 @@ declare type usize = number; declare type f32 = number; declare type f64 = number; +/** Special type evaluating the value type of a collection. */ +declare type valueof = T[0]; + // Compiler hints /** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */ diff --git a/tests/compiler/valueof.json b/tests/compiler/valueof.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/valueof.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/valueof.optimized.wat b/tests/compiler/valueof.optimized.wat new file mode 100644 index 0000000000..e396f28a3c --- /dev/null +++ b/tests/compiler/valueof.optimized.wat @@ -0,0 +1,9 @@ +(module + (type $FUNCSIG$v (func)) + (memory $0 1) + (data (i32.const 8) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s") + (export "memory" (memory $0)) + (func $start (; 0 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/valueof.ts b/tests/compiler/valueof.ts new file mode 100644 index 0000000000..ee200c22a7 --- /dev/null +++ b/tests/compiler/valueof.ts @@ -0,0 +1,26 @@ +// simple +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 1); + +// alias +type u32Array = u32[]; +assert(isInteger>()); +assert(!isSigned>()); +assert(sizeof>() == 4); + +// float +assert(isFloat>()); +assert(sizeof>() == 4); + +// string +assert(isString>()); +assert(isManaged>()); + +// array +assert(isArray>()); + +// typed array +assert(isInteger>()); +assert(!isSigned>()); +assert(sizeof>() == 1); diff --git a/tests/compiler/valueof.untouched.wat b/tests/compiler/valueof.untouched.wat new file mode 100644 index 0000000000..43cb6cdc94 --- /dev/null +++ b/tests/compiler/valueof.untouched.wat @@ -0,0 +1,168 @@ +(module + (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) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s\00") + (table $0 1 funcref) + (elem (i32.const 0) $null) + (export "memory" (memory $0)) + (start $start) + (func $start:valueof (; 1 ;) (type $FUNCSIG$v) + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 2 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 3 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 4 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 8 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 9 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 10 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 13 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 14 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 17 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 18 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 21 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 24 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 25 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 26 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 2 ;) (type $FUNCSIG$v) + call $start:valueof + ) + (func $null (; 3 ;) (type $FUNCSIG$v) + ) +) From f8f2565f60c63f0b5f33b4808c9a15a907953fda Mon Sep 17 00:00:00 2001 From: dcode Date: Mon, 17 Jun 2019 16:17:27 +0200 Subject: [PATCH 2/2] refactor, indexof, map/set overloads --- src/ast.ts | 148 +++---- src/common.ts | 1 + src/compiler.ts | 24 +- src/extra/ast.ts | 85 ++-- src/parser.ts | 104 ++--- src/program.ts | 30 +- src/resolver.ts | 115 ++++-- std/assembly/index.d.ts | 4 +- std/assembly/map.ts | 6 +- std/assembly/set.ts | 7 + std/assembly/util/error.ts | 4 + std/portable/index.d.ts | 4 +- .../{valueof.json => indexof-valueof.json} | 0 tests/compiler/indexof-valueof.optimized.wat | 9 + tests/compiler/indexof-valueof.ts | 61 +++ tests/compiler/indexof-valueof.untouched.wat | 384 ++++++++++++++++++ tests/compiler/std/map.optimized.wat | 132 ++++-- tests/compiler/std/map.untouched.wat | 138 +++++-- tests/compiler/std/symbol.optimized.wat | 160 ++++---- tests/compiler/std/symbol.untouched.wat | 115 +++--- tests/compiler/valueof.optimized.wat | 9 - tests/compiler/valueof.ts | 26 -- tests/compiler/valueof.untouched.wat | 168 -------- 23 files changed, 1090 insertions(+), 644 deletions(-) rename tests/compiler/{valueof.json => indexof-valueof.json} (100%) create mode 100644 tests/compiler/indexof-valueof.optimized.wat create mode 100644 tests/compiler/indexof-valueof.ts create mode 100644 tests/compiler/indexof-valueof.untouched.wat delete mode 100644 tests/compiler/valueof.optimized.wat delete mode 100644 tests/compiler/valueof.ts delete mode 100644 tests/compiler/valueof.untouched.wat diff --git a/src/ast.ts b/src/ast.ts index e833ca4400..68a373d3f9 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -30,11 +30,11 @@ export enum NodeKind { SOURCE, // types - TYPE, + NAMEDTYPE, + FUNCTIONTYPE, TYPENAME, TYPEPARAMETER, PARAMETER, - SIGNATURE, // expressions IDENTIFIER, @@ -164,13 +164,13 @@ export abstract class Node { return Node.createTypeName(Node.createIdentifierExpression(name, range), range); } - static createType( + static createNamedType( name: TypeName, - typeArguments: CommonTypeNode[] | null, + typeArguments: TypeNode[] | null, isNullable: bool, range: Range - ): TypeNode { - var type = new TypeNode(); + ): NamedTypeNode { + var type = new NamedTypeNode(); type.range = range; type.name = name; type.typeArguments = typeArguments; @@ -178,10 +178,26 @@ export abstract class Node { return type; } + static createFunctionType( + parameters: ParameterNode[], + returnType: TypeNode, + explicitThisType: NamedTypeNode | null, + isNullable: bool, + range: Range + ): FunctionTypeNode { + var type = new FunctionTypeNode(); + type.range = range; + type.parameters = parameters; + type.returnType = returnType; + type.explicitThisType = explicitThisType; + type.isNullable = isNullable; + return type; + } + static createOmittedType( range: Range - ): TypeNode { - return Node.createType( + ): NamedTypeNode { + return Node.createNamedType( Node.createSimpleTypeName("", range), null, false, @@ -191,8 +207,8 @@ export abstract class Node { static createTypeParameter( name: IdentifierExpression, - extendsType: TypeNode | null, - defaultType: TypeNode | null, + extendsType: NamedTypeNode | null, + defaultType: NamedTypeNode | null, range: Range ): TypeParameterNode { var elem = new TypeParameterNode(); @@ -205,7 +221,7 @@ export abstract class Node { static createParameter( name: IdentifierExpression, - type: CommonTypeNode, + type: TypeNode, initializer: Expression | null, kind: ParameterKind, range: Range @@ -219,22 +235,6 @@ export abstract class Node { return elem; } - static createSignature( - parameters: ParameterNode[], - returnType: CommonTypeNode, - explicitThisType: TypeNode | null, - isNullable: bool, - range: Range - ): SignatureNode { - var sig = new SignatureNode(); - sig.range = range; - sig.parameters = parameters; - sig.returnType = returnType; - sig.explicitThisType = explicitThisType; - sig.isNullable = isNullable; - return sig; - } - // special static createDecorator( @@ -299,7 +299,7 @@ export abstract class Node { static createAssertionExpression( assertionKind: AssertionKind, expression: Expression, - toType: CommonTypeNode | null, + toType: TypeNode | null, range: Range ): AssertionExpression { var expr = new AssertionExpression(); @@ -326,7 +326,7 @@ export abstract class Node { static createCallExpression( expression: Expression, - typeArgs: CommonTypeNode[] | null, + typeArgs: TypeNode[] | null, args: Expression[], range: Range ): CallExpression { @@ -406,7 +406,7 @@ export abstract class Node { static createInstanceOfExpression( expression: Expression, - isType: CommonTypeNode, + isType: TypeNode, range: Range ): InstanceOfExpression { var expr = new InstanceOfExpression(); @@ -428,7 +428,7 @@ export abstract class Node { static createNewExpression( expression: Expression, - typeArgs: CommonTypeNode[] | null, + typeArgs: TypeNode[] | null, args: Expression[], range: Range ): NewExpression { @@ -591,8 +591,8 @@ export abstract class Node { static createClassDeclaration( identifier: IdentifierExpression, typeParameters: TypeParameterNode[] | null, - extendsType: TypeNode | null, // can't be a function - implementsTypes: TypeNode[] | null, // can't be functions + extendsType: NamedTypeNode | null, // can't be a function + implementsTypes: NamedTypeNode[] | null, // can't be functions members: DeclarationStatement[], decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -828,7 +828,7 @@ export abstract class Node { static createInterfaceDeclaration( name: IdentifierExpression, typeParameters: TypeParameterNode[] | null, - extendsType: TypeNode | null, // can't be a function + extendsType: NamedTypeNode | null, // can't be a function members: DeclarationStatement[], decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -847,7 +847,7 @@ export abstract class Node { static createFieldDeclaration( name: IdentifierExpression, - type: CommonTypeNode | null, + type: TypeNode | null, initializer: Expression | null, decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -882,7 +882,7 @@ export abstract class Node { static createFunctionDeclaration( name: IdentifierExpression, typeParameters: TypeParameterNode[] | null, - signature: SignatureNode, + signature: FunctionTypeNode, body: Statement | null, decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -902,8 +902,8 @@ export abstract class Node { } static createIndexSignatureDeclaration( - keyType: TypeNode, - valueType: CommonTypeNode, + keyType: NamedTypeNode, + valueType: TypeNode, range: Range ): IndexSignatureDeclaration { var elem = new IndexSignatureDeclaration(); @@ -916,7 +916,7 @@ export abstract class Node { static createMethodDeclaration( name: IdentifierExpression, typeParameters: TypeParameterNode[] | null, - signature: SignatureNode, + signature: FunctionTypeNode, body: Statement | null, decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -1012,7 +1012,7 @@ export abstract class Node { static createTypeDeclaration( name: IdentifierExpression, typeParameters: TypeParameterNode[] | null, - alias: CommonTypeNode, + alias: TypeNode, decorators: DecoratorNode[] | null, flags: CommonFlags, range: Range @@ -1041,7 +1041,7 @@ export abstract class Node { static createVariableDeclaration( name: IdentifierExpression, - type: CommonTypeNode | null, + type: TypeNode | null, initializer: Expression | null, decorators: DecoratorNode[] | null, flags: CommonFlags, @@ -1082,7 +1082,7 @@ export abstract class Node { // types -export abstract class CommonTypeNode extends Node { +export abstract class TypeNode extends Node { // kind varies /** Whether nullable or not. */ @@ -1099,14 +1099,26 @@ export class TypeName extends Node { next: TypeName | null; } -/** Represents a type annotation. */ -export class TypeNode extends CommonTypeNode { - kind = NodeKind.TYPE; +/** Represents a named type. */ +export class NamedTypeNode extends TypeNode { + kind = NodeKind.NAMEDTYPE; /** Type name. */ name: TypeName; /** Type argument references. */ - typeArguments: CommonTypeNode[] | null; + typeArguments: TypeNode[] | null; +} + +/** Represents a function type. */ +export class FunctionTypeNode extends TypeNode { + kind = NodeKind.FUNCTIONTYPE; + + /** Accepted parameters. */ + parameters: ParameterNode[]; + /** Return type. */ + returnType: TypeNode; + /** Explicitly provided this type, if any. */ + explicitThisType: NamedTypeNode | null; // can't be a function } /** Represents a type parameter. */ @@ -1116,9 +1128,9 @@ export class TypeParameterNode extends Node { /** Identifier reference. */ name: IdentifierExpression; /** Extended type reference, if any. */ - extendsType: TypeNode | null; // can't be a function + extendsType: NamedTypeNode | null; // can't be a function /** Default type if omitted, if any. */ - defaultType: TypeNode | null; // can't be a function + defaultType: NamedTypeNode | null; // can't be a function } /** Represents the kind of a parameter. */ @@ -1140,7 +1152,7 @@ export class ParameterNode extends Node { /** Parameter name. */ name: IdentifierExpression; /** Parameter type. */ - type: CommonTypeNode; + type: TypeNode; /** Initializer expression, if present. */ initializer: Expression | null; /** Implicit field declaration, if applicable. */ @@ -1156,18 +1168,6 @@ export class ParameterNode extends Node { set(flag: CommonFlags): void { this.flags |= flag; } } -/** Represents a function signature. */ -export class SignatureNode extends CommonTypeNode { - kind = NodeKind.SIGNATURE; - - /** Accepted parameters. */ - parameters: ParameterNode[]; - /** Return type. */ - returnType: CommonTypeNode; - /** Explicitly provided this type, if any. */ - explicitThisType: TypeNode | null; // can't be a function -} - // special /** Built-in decorator kinds. */ @@ -1347,7 +1347,7 @@ export class AssertionExpression extends Expression { /** Expression being asserted. */ expression: Expression; /** Target type. */ - toType: CommonTypeNode | null; + toType: TypeNode | null; } /** Represents a binary expression. */ @@ -1369,7 +1369,7 @@ export class CallExpression extends Expression { /** Called expression. Usually an identifier or property access expression. */ expression: Expression; /** Provided type arguments. */ - typeArguments: CommonTypeNode[] | null; + typeArguments: TypeNode[] | null; /** Provided arguments. */ arguments: Expression[]; @@ -1450,7 +1450,7 @@ export class InstanceOfExpression extends Expression { /** Expression being asserted. */ expression: Expression; /** Type to test for. */ - isType: CommonTypeNode; + isType: TypeNode; } /** Represents an integer literal expression. */ @@ -1659,16 +1659,16 @@ export class IndexSignatureDeclaration extends DeclarationStatement { kind = NodeKind.INDEXSIGNATUREDECLARATION; /** Key type. */ - keyType: TypeNode; + keyType: NamedTypeNode; /** Value type. */ - valueType: CommonTypeNode; + valueType: TypeNode; } /** Base class of all variable-like declaration statements. */ export abstract class VariableLikeDeclarationStatement extends DeclarationStatement { /** Variable type. */ - type: CommonTypeNode | null; + type: TypeNode | null; /** Variable initializer. */ initializer: Expression | null; } @@ -1696,9 +1696,9 @@ export class ClassDeclaration extends DeclarationStatement { /** Accepted type parameters. */ typeParameters: TypeParameterNode[] | null; /** Base class type being extended, if any. */ - extendsType: TypeNode | null; // can't be a function + extendsType: NamedTypeNode | null; // can't be a function /** Interface types being implemented, if any. */ - implementsTypes: TypeNode[] | null; // can't be functions + implementsTypes: NamedTypeNode[] | null; // can't be functions /** Class member declarations. */ members: DeclarationStatement[]; @@ -1842,7 +1842,7 @@ export class FunctionDeclaration extends DeclarationStatement { /** Type parameters, if any. */ typeParameters: TypeParameterNode[] | null; /** Function signature. */ - signature: SignatureNode; + signature: FunctionTypeNode; /** Body statement. Usually a block. */ body: Statement | null; /** Arrow function kind, if applicable. */ @@ -1979,7 +1979,7 @@ export class TypeDeclaration extends DeclarationStatement { /** Type parameters, if any. */ typeParameters: TypeParameterNode[] | null; /** Type being aliased. */ - type: CommonTypeNode; + type: TypeNode; } /** Represents a variable declaration part of a {@link VariableStatement}. */ @@ -2033,9 +2033,9 @@ export function mangleInternalPath(path: string): string { } /** Tests if the specified type node represents an omitted type. */ -export function isTypeOmitted(type: CommonTypeNode): bool { - if (type.kind == NodeKind.TYPE) { - let name = (type).name; +export function isTypeOmitted(type: TypeNode): bool { + if (type.kind == NodeKind.NAMEDTYPE) { + let name = (type).name; return !(name.next || name.identifier.text.length); } return false; diff --git a/src/common.ts b/src/common.ts index 5ddef23649..e5d51a8e07 100644 --- a/src/common.ts +++ b/src/common.ts @@ -134,6 +134,7 @@ export namespace CommonSymbols { export const boolean = "boolean"; export const string = "string"; export const native = "native"; + export const indexof = "indexof"; export const valueof = "valueof"; // aliases export const null_ = "null"; diff --git a/src/compiler.ts b/src/compiler.ts index 5f833c9a41..b0f9306f48 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -100,7 +100,7 @@ import { import { Node, NodeKind, - TypeNode, + NamedTypeNode, Range, DecoratorKind, AssertionKind, @@ -1064,7 +1064,7 @@ export class Compiler extends DiagnosticEmitter { /** Resolves the specified type arguments prior to compiling the resulting function instance. */ compileFunctionUsingTypeArguments( prototype: FunctionPrototype, - typeArguments: TypeNode[], + typeArguments: NamedTypeNode[], contextualTypeArguments: Map = makeMap(), alternativeReportNode: Node | null = null ): Function | null { @@ -1209,7 +1209,7 @@ export class Compiler extends DiagnosticEmitter { } else if (returnType != Type.void && !flow.is(FlowFlags.TERMINATES)) { this.error( DiagnosticCode.A_function_whose_declared_type_is_not_void_must_return_a_value, - instance.prototype.signatureNode.returnType.range + instance.prototype.functionTypeNode.returnType.range ); } @@ -1325,7 +1325,7 @@ export class Compiler extends DiagnosticEmitter { compileClassUsingTypeArguments( prototype: ClassPrototype, - typeArguments: TypeNode[], + typeArguments: NamedTypeNode[], contextualTypeArguments: Map = makeMap(), alternativeReportNode: Node | null = null ): void { @@ -1429,7 +1429,7 @@ export class Compiler extends DiagnosticEmitter { compileInterfaceDeclaration( declaration: InterfaceDeclaration, - typeArguments: TypeNode[], + typeArguments: NamedTypeNode[], contextualTypeArguments: Map | null = null, alternativeReportNode: Node | null = null ): void { @@ -5810,15 +5810,15 @@ export class Compiler extends DiagnosticEmitter { inferredTypes.set(typeParameterNodes[i].name.text, null); } // let numInferred = 0; - let parameterNodes = prototype.signatureNode.parameters; + let parameterNodes = prototype.functionTypeNode.parameters; let numParameters = parameterNodes.length; let argumentNodes = expression.arguments; let numArguments = argumentNodes.length; let argumentExprs = new Array(numArguments); for (let i = 0; i < numParameters; ++i) { let typeNode = parameterNodes[i].type; - let templateName = typeNode.kind == NodeKind.TYPE && !(typeNode).name.next - ? (typeNode).name.identifier.text + let templateName = typeNode.kind == NodeKind.NAMEDTYPE && !(typeNode).name.next + ? (typeNode).name.identifier.text : null; let argumentExpression = i < numArguments ? argumentNodes[i] @@ -6254,7 +6254,7 @@ export class Compiler extends DiagnosticEmitter { for (let i = numArguments; i < numParameters; ++i) { let initType = parameterTypes[i]; let initExpr = this.compileExpression( - assert(instance.prototype.signatureNode.parameters[i].initializer), + assert(instance.prototype.functionTypeNode.parameters[i].initializer), initType, Constraints.CONV_IMPLICIT ); @@ -6314,7 +6314,7 @@ export class Compiler extends DiagnosticEmitter { var originalSignature = original.signature; var originalName = original.internalName; var originalParameterTypes = originalSignature.parameterTypes; - var originalParameterDeclarations = original.prototype.signatureNode.parameters; + var originalParameterDeclarations = original.prototype.functionTypeNode.parameters; var returnType = originalSignature.returnType; var thisType = originalSignature.thisType; var isInstance = original.is(CommonFlags.INSTANCE); @@ -6705,7 +6705,7 @@ export class Compiler extends DiagnosticEmitter { operands.length = 0; } let parameterTypes = instance.signature.parameterTypes; - let parameterNodes = instance.prototype.signatureNode.parameters; + let parameterNodes = instance.prototype.functionTypeNode.parameters; assert(parameterNodes.length == parameterTypes.length); let allOptionalsAreConstant = true; for (let i = numArguments; i < maxArguments; ++i) { @@ -6954,7 +6954,7 @@ export class Compiler extends DiagnosticEmitter { // compile according to context. this differs from a normal function in that omitted parameter // and return types can be inferred and omitted arguments can be replaced with dummies. if (contextualSignature) { - let signatureNode = prototype.signatureNode; + let signatureNode = prototype.functionTypeNode; let parameterNodes = signatureNode.parameters; let numPresentParameters = parameterNodes.length; diff --git a/src/extra/ast.ts b/src/extra/ast.ts index 0f843af63e..384473196f 100644 --- a/src/extra/ast.ts +++ b/src/extra/ast.ts @@ -12,11 +12,11 @@ import { Source, ArrowKind, - CommonTypeNode, TypeNode, + NamedTypeNode, + FunctionTypeNode, TypeName, TypeParameterNode, - SignatureNode, Expression, IdentifierExpression, @@ -123,8 +123,12 @@ export class ASTBuilder { // types - case NodeKind.TYPE: { - this.visitTypeNode(node); + case NodeKind.NAMEDTYPE: { + this.visitNamedTypeNode(node); + break; + } + case NodeKind.FUNCTIONTYPE: { + this.visitFunctionTypeNode(node); break; } case NodeKind.TYPEPARAMETER: { @@ -362,27 +366,17 @@ export class ASTBuilder { // types - visitTypeNode(node: CommonTypeNode): void { - if (node.kind == NodeKind.SIGNATURE) { - this.visitSignatureNode(node); - return; - } - var typeNode = node; - this.visitTypeName((node).name); - var typeArguments = typeNode.typeArguments; - if (typeArguments) { - let numTypeArguments = typeArguments.length; - let sb = this.sb; - if (numTypeArguments) { - sb.push("<"); - this.visitTypeNode(typeArguments[0]); - for (let i = 1; i < numTypeArguments; ++i) { - sb.push(", "); - this.visitTypeNode(typeArguments[i]); - } - sb.push(">"); + visitTypeNode(node: TypeNode): void { + switch (node.kind) { + case NodeKind.NAMEDTYPE: { + this.visitNamedTypeNode(node); + break; } - if (node.isNullable) sb.push(" | null"); + case NodeKind.FUNCTIONTYPE: { + this.visitFunctionTypeNode(node); + break; + } + default: assert(false); } } @@ -397,21 +391,26 @@ export class ASTBuilder { } } - visitTypeParameter(node: TypeParameterNode): void { - this.visitIdentifierExpression(node.name); - var extendsType = node.extendsType; - if (extendsType) { - this.sb.push(" extends "); - this.visitTypeNode(extendsType); - } - var defaultType = node.defaultType; - if (defaultType) { - this.sb.push("="); - this.visitTypeNode(defaultType); + visitNamedTypeNode(node: NamedTypeNode): void { + this.visitTypeName(node.name); + var typeArguments = node.typeArguments; + if (typeArguments) { + let numTypeArguments = typeArguments.length; + let sb = this.sb; + if (numTypeArguments) { + sb.push("<"); + this.visitTypeNode(typeArguments[0]); + for (let i = 1; i < numTypeArguments; ++i) { + sb.push(", "); + this.visitTypeNode(typeArguments[i]); + } + sb.push(">"); + } + if (node.isNullable) sb.push(" | null"); } } - visitSignatureNode(node: SignatureNode): void { + visitFunctionTypeNode(node: FunctionTypeNode): void { var isNullable = node.isNullable; var sb = this.sb; sb.push(isNullable ? "((" : "("); @@ -440,6 +439,20 @@ export class ASTBuilder { if (isNullable) sb.push(") | null"); } + visitTypeParameter(node: TypeParameterNode): void { + this.visitIdentifierExpression(node.name); + var extendsType = node.extendsType; + if (extendsType) { + this.sb.push(" extends "); + this.visitTypeNode(extendsType); + } + var defaultType = node.defaultType; + if (defaultType) { + this.sb.push("="); + this.visitTypeNode(defaultType); + } + } + // expressions visitIdentifierExpression(node: IdentifierExpression): void { diff --git a/src/parser.ts b/src/parser.ts index 47d5aab983..4e94c9a181 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -36,9 +36,9 @@ import { NodeKind, Source, SourceKind, - CommonTypeNode, TypeNode, - SignatureNode, + NamedTypeNode, + FunctionTypeNode, ArrowKind, Expression, @@ -387,13 +387,13 @@ export class Parser extends DiagnosticEmitter { tn: Tokenizer, acceptParenthesized: bool = true, suppressErrors: bool = false - ): CommonTypeNode | null { + ): TypeNode | null { // NOTE: this parses our limited subset var token = tn.next(); var startPos = tn.tokenPos; - var type: CommonTypeNode; + var type: TypeNode; // '(' ... if (token == Token.OPENPAREN) { @@ -401,7 +401,7 @@ export class Parser extends DiagnosticEmitter { // '(' FunctionSignature ')' '|' 'null'? let isNullableSignature = tn.skip(Token.OPENPAREN); // FunctionSignature? - let signature = this.tryParseSignature(tn); + let signature = this.tryParseFunctionType(tn); if (signature) { if (isNullableSignature) { if (!tn.skip(Token.CLOSEPAREN)) { @@ -461,26 +461,26 @@ export class Parser extends DiagnosticEmitter { // 'void' } else if (token == Token.VOID) { - type = Node.createType( + type = Node.createNamedType( Node.createSimpleTypeName("void", tn.range()), [], false, tn.range(startPos, tn.pos) ); // 'this' } else if (token == Token.THIS) { - type = Node.createType( + type = Node.createNamedType( Node.createSimpleTypeName("this", tn.range()), [], false, tn.range(startPos, tn.pos) ); // 'true' } else if (token == Token.TRUE || token == Token.FALSE) { - type = Node.createType( + type = Node.createNamedType( Node.createSimpleTypeName("bool", tn.range()), [], false, tn.range(startPos, tn.pos) ); // StringLiteral } else if (token == Token.STRINGLITERAL) { tn.readString(); - type = Node.createType( + type = Node.createNamedType( Node.createSimpleTypeName("string", tn.range()), [], false, tn.range(startPos, tn.pos) ); @@ -488,7 +488,7 @@ export class Parser extends DiagnosticEmitter { } else if (token == Token.IDENTIFIER) { let first = Node.createSimpleTypeName(tn.readIdentifier(), tn.range()); let current = first; - let parameters: TypeNode[] | null = null; + let parameters: NamedTypeNode[] | null = null; let nullable = false; // Identifier ('.' Identifier)+ @@ -511,8 +511,8 @@ export class Parser extends DiagnosticEmitter { do { let parameter = this.parseType(tn, true, suppressErrors); if (!parameter) return null; - if (!parameters) parameters = [parameter]; - else parameters.push(parameter); + if (!parameters) parameters = [parameter]; + else parameters.push(parameter); } while (tn.skip(Token.COMMA)); if (!tn.skip(Token.GREATERTHAN)) { if (!suppressErrors) { @@ -538,7 +538,7 @@ export class Parser extends DiagnosticEmitter { return null; } } - type = Node.createType(first, parameters || [], nullable, tn.range(startPos, tn.pos)); + type = Node.createNamedType(first, parameters || [], nullable, tn.range(startPos, tn.pos)); } else { if (!suppressErrors) { this.error( @@ -577,7 +577,7 @@ export class Parser extends DiagnosticEmitter { return null; } } - type = Node.createType( + type = Node.createNamedType( Node.createSimpleTypeName("Array", bracketRange), [ type ], nullable, @@ -592,17 +592,17 @@ export class Parser extends DiagnosticEmitter { // Indicates whether tryParseSignature determined that it is handling a Signature private tryParseSignatureIsSignature: bool = false; - /** Parses a function signature, as used in type declarations. */ - tryParseSignature( + /** Parses a function type, as used in type declarations. */ + tryParseFunctionType( tn: Tokenizer - ): SignatureNode | null { + ): FunctionTypeNode | null { // at '(': ('...'? Identifier '?'? ':' Type (',' '...'? Identifier '?'? ':' Type)* )? ')' '=>' Type var state = tn.mark(); var startPos = tn.tokenPos; var parameters: ParameterNode[] | null = null; - var thisType: TypeNode | null = null; + var thisType: NamedTypeNode | null = null; var isSignature: bool = false; if (tn.skip(Token.CLOSEPAREN)) { @@ -625,7 +625,7 @@ export class Parser extends DiagnosticEmitter { tn.discard(state); let t = this.parseType(tn, false); if (!t) return null; - if (t.kind != NodeKind.TYPE) { + if (t.kind != NodeKind.NAMEDTYPE) { this.error( DiagnosticCode.Operation_not_supported, t.range @@ -633,7 +633,7 @@ export class Parser extends DiagnosticEmitter { this.tryParseSignatureIsSignature = true; return null; } - thisType = t; + thisType = t; } else { tn.reset(state); this.tryParseSignatureIsSignature = false; @@ -702,7 +702,7 @@ export class Parser extends DiagnosticEmitter { } } - var returnType: CommonTypeNode | null; + var returnType: TypeNode | null; if (tn.skip(Token.EQUALS_GREATERTHAN)) { isSignature = true; tn.discard(state); @@ -724,7 +724,7 @@ export class Parser extends DiagnosticEmitter { return null; } this.tryParseSignatureIsSignature = true; - return Node.createSignature( + return Node.createFunctionType( parameters || [], returnType, thisType, @@ -827,7 +827,7 @@ export class Parser extends DiagnosticEmitter { flags |= CommonFlags.DEFINITE_ASSIGNMENT; } - var type: CommonTypeNode | null = null; + var type: TypeNode | null = null; if (tn.skip(Token.COLON)) { type = this.parseType(tn); } @@ -1027,31 +1027,31 @@ export class Parser extends DiagnosticEmitter { tn.readIdentifier(), tn.range() ); - let extendsType: TypeNode | null = null; + let extendsType: NamedTypeNode | null = null; if (tn.skip(Token.EXTENDS)) { let t = this.parseType(tn); if (!t) return null; - if (t.kind != NodeKind.TYPE) { + if (t.kind != NodeKind.NAMEDTYPE) { this.error( DiagnosticCode.Operation_not_supported, t.range ); return null; } - extendsType = t; + extendsType = t; } - let defaultType: TypeNode | null = null; + let defaultType: NamedTypeNode | null = null; if (tn.skip(Token.EQUALS)) { let t = this.parseType(tn); if (!t) return null; - if (t.kind != NodeKind.TYPE) { + if (t.kind != NodeKind.NAMEDTYPE) { this.error( DiagnosticCode.Operation_not_supported, t.range ); return null; } - defaultType = t; + defaultType = t; } return Node.createTypeParameter( identifier, @@ -1068,7 +1068,7 @@ export class Parser extends DiagnosticEmitter { return null; } - private parseParametersThis: TypeNode | null = null; + private parseParametersThis: NamedTypeNode | null = null; parseParameters( tn: Tokenizer, @@ -1081,7 +1081,7 @@ export class Parser extends DiagnosticEmitter { var seenRest: ParameterNode | null = null; var seenOptional = false; var reportedRest = false; - var thisType: CommonTypeNode | null = null; + var thisType: TypeNode | null = null; // check if there is a leading `this` parameter this.parseParametersThis = null; @@ -1089,8 +1089,8 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { thisType = this.parseType(tn); // reports if (!thisType) return null; - if (thisType.kind == NodeKind.TYPE) { - this.parseParametersThis = thisType; + if (thisType.kind == NodeKind.NAMEDTYPE) { + this.parseParametersThis = thisType; } else { this.error( DiagnosticCode.Operation_not_supported, @@ -1210,7 +1210,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skipIdentifier()) { if (!isRest) startRange = tn.range(); let identifier = Node.createIdentifierExpression(tn.readIdentifier(), tn.range()); - let type: CommonTypeNode | null = null; + let type: TypeNode | null = null; if (isOptional = tn.skip(Token.QUESTION)) { if (isRest) { this.error( @@ -1340,7 +1340,7 @@ export class Parser extends DiagnosticEmitter { } } - var returnType: CommonTypeNode | null = null; + var returnType: TypeNode | null = null; if (tn.skip(Token.COLON)) { returnType = this.parseType(tn, true, isSetter); if (!returnType) return null; @@ -1358,7 +1358,7 @@ export class Parser extends DiagnosticEmitter { } } - var signature = Node.createSignature( + var signature = Node.createFunctionType( parameters, returnType, thisType, @@ -1452,7 +1452,7 @@ export class Parser extends DiagnosticEmitter { if (startPos < 0) startPos = name.range.start; if (signatureStart < 0) signatureStart = startPos; - var returnType: CommonTypeNode | null = null; + var returnType: TypeNode | null = null; if (arrowKind != ArrowKind.ARROW_SINGLE && tn.skip(Token.COLON)) { returnType = this.parseType(tn); if (!returnType) return null; @@ -1470,7 +1470,7 @@ export class Parser extends DiagnosticEmitter { } } - var signature = Node.createSignature( + var signature = Node.createFunctionType( parameters, returnType, null, // TODO? @@ -1547,21 +1547,21 @@ export class Parser extends DiagnosticEmitter { flags |= CommonFlags.GENERIC; } - var extendsType: TypeNode | null = null; + var extendsType: NamedTypeNode | null = null; if (tn.skip(Token.EXTENDS)) { let t = this.parseType(tn); if (!t) return null; - if (t.kind != NodeKind.TYPE) { + if (t.kind != NodeKind.NAMEDTYPE) { this.error( DiagnosticCode.Operation_not_supported, t.range ); return null; } - extendsType = t; + extendsType = t; } - var implementsTypes: TypeNode[] | null = null; + var implementsTypes: NamedTypeNode[] | null = null; if (tn.skip(Token.IMPLEMENTS)) { if (isInterface) { this.error( @@ -1573,8 +1573,8 @@ export class Parser extends DiagnosticEmitter { let type = this.parseType(tn); if (!type) return null; if (!isInterface) { - if (!implementsTypes) implementsTypes = [type]; - else implementsTypes.push(type); + if (!implementsTypes) implementsTypes = [type]; + else implementsTypes.push(type); } } while (tn.skip(Token.COMMA)); } @@ -1988,7 +1988,7 @@ export class Parser extends DiagnosticEmitter { } } - let returnType: CommonTypeNode | null = null; + let returnType: TypeNode | null = null; if (tn.skip(Token.COLON)) { if (name.kind == NodeKind.CONSTRUCTOR) { this.error( @@ -2013,7 +2013,7 @@ export class Parser extends DiagnosticEmitter { } } - let signature = Node.createSignature( + let signature = Node.createFunctionType( parameters, returnType, thisType, @@ -2090,7 +2090,7 @@ export class Parser extends DiagnosticEmitter { ); // recoverable } - let type: CommonTypeNode | null = null; + let type: TypeNode | null = null; if (tn.skip(Token.QUESTION)) { this.error( DiagnosticCode.Optional_properties_are_not_supported, @@ -2153,7 +2153,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { let keyType = this.parseType(tn); if (!keyType) return null; - if (keyType.kind != NodeKind.TYPE) { + if (keyType.kind != NodeKind.NAMEDTYPE) { this.error( DiagnosticCode.Type_expected, tn.range() @@ -2164,7 +2164,7 @@ export class Parser extends DiagnosticEmitter { if (tn.skip(Token.COLON)) { let valueType = this.parseType(tn); if (!valueType) return null; - return Node.createIndexSignatureDeclaration(keyType, valueType, tn.range(start, tn.pos)); + return Node.createIndexSignatureDeclaration(keyType, valueType, tn.range(start, tn.pos)); } else { this.error( DiagnosticCode._0_expected, @@ -3528,13 +3528,13 @@ export class Parser extends DiagnosticEmitter { tryParseTypeArgumentsBeforeArguments( tn: Tokenizer - ): CommonTypeNode[] | null { + ): TypeNode[] | null { // at '<': Type (',' Type)* '>' '(' var state = tn.mark(); if (!tn.skip(Token.LESSTHAN)) return null; - var typeArguments: CommonTypeNode[] | null = null; + var typeArguments: TypeNode[] | null = null; do { if (tn.peek() === Token.GREATERTHAN) { break; @@ -3792,7 +3792,7 @@ export class Parser extends DiagnosticEmitter { expr: Expression ): Expression { if (nodeIsCallable(expr.kind)) { - let typeArguments: CommonTypeNode[] | null = null; + let typeArguments: TypeNode[] | null = null; while ( tn.skip(Token.OPENPAREN) || diff --git a/src/program.ts b/src/program.ts index f354e34766..ff05531d55 100644 --- a/src/program.ts +++ b/src/program.ts @@ -43,10 +43,10 @@ import { Range, DecoratorNode, DecoratorKind, - SignatureNode, TypeParameterNode, - CommonTypeNode, TypeNode, + NamedTypeNode, + FunctionTypeNode, ArrowKind, Expression, @@ -470,7 +470,7 @@ export class Program extends DiagnosticEmitter { } // a dummy signature for programmatically generated native functions - private nativeDummySignature: SignatureNode | null = null; + private nativeDummySignature: FunctionTypeNode | null = null; /** Creates a native function declaration. */ makeNativeFunctionDeclaration( @@ -483,8 +483,8 @@ export class Program extends DiagnosticEmitter { return Node.createFunctionDeclaration( Node.createIdentifierExpression(name, range), null, - this.nativeDummySignature || (this.nativeDummySignature = Node.createSignature([], - Node.createType( // ^ AST signature doesn't really matter, is overridden anyway + this.nativeDummySignature || (this.nativeDummySignature = Node.createFunctionType([], + Node.createNamedType( // ^ AST signature doesn't really matter, is overridden anyway Node.createSimpleTypeName(CommonSymbols.void_, range), null, false, range ), @@ -567,6 +567,12 @@ export class Program extends DiagnosticEmitter { this.makeNativeTypeDeclaration(CommonSymbols.native, CommonFlags.EXPORT | CommonFlags.GENERIC), DecoratorFlags.BUILTIN )); + this.nativeFile.add(CommonSymbols.indexof, new TypeDefinition( + CommonSymbols.indexof, + this.nativeFile, + this.makeNativeTypeDeclaration(CommonSymbols.indexof, CommonFlags.EXPORT | CommonFlags.GENERIC), + DecoratorFlags.BUILTIN + )); this.nativeFile.add(CommonSymbols.valueof, new TypeDefinition( CommonSymbols.valueof, this.nativeFile, @@ -2248,7 +2254,7 @@ export class TypeDefinition extends TypedElement { } /** Gets the associated type node. */ - get typeNode(): CommonTypeNode { + get typeNode(): TypeNode { return (this.declaration).type; } @@ -2366,7 +2372,7 @@ export abstract class VariableLikeElement extends TypedElement { } /** Gets the associated type node.s */ - get typeNode(): CommonTypeNode | null { + get typeNode(): TypeNode | null { return (this.declaration).type; } @@ -2540,8 +2546,8 @@ export class FunctionPrototype extends DeclaredElement { return (this.declaration).typeParameters; } - /** Gets the associated signature node. */ - get signatureNode(): SignatureNode { + /** Gets the associated function type node. */ + get functionTypeNode(): FunctionTypeNode { return (this.declaration).signature; } @@ -2818,7 +2824,7 @@ export class FieldPrototype extends DeclaredElement { } /** Gets the associated type node. */ - get typeNode(): CommonTypeNode | null { + get typeNode(): TypeNode | null { return (this.declaration).type; } @@ -2982,11 +2988,11 @@ export class ClassPrototype extends DeclaredElement { return (this.declaration).typeParameters; } /** Gets the associated extends node. */ - get extendsNode(): TypeNode | null { + get extendsNode(): NamedTypeNode | null { return (this.declaration).extendsType; } /** Gets the associated implements nodes. */ - get implementsNodes(): TypeNode[] | null { + get implementsNodes(): NamedTypeNode[] | null { return (this.declaration).implementsTypes; } diff --git a/src/resolver.ts b/src/resolver.ts index 9ccb32cbc4..7a7c97ea12 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -32,11 +32,11 @@ import { } from "./flow"; import { - SignatureNode, + FunctionTypeNode, ParameterKind, - CommonTypeNode, - NodeKind, TypeNode, + NodeKind, + NamedTypeNode, TypeName, TypeParameterNode, Node, @@ -117,7 +117,7 @@ export class Resolver extends DiagnosticEmitter { /** Resolves a {@link CommonTypeNode} to a concrete {@link Type}. */ resolveType( /** The type to resolve. */ - node: CommonTypeNode, + node: TypeNode, /** Relative context. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ @@ -127,8 +127,8 @@ export class Resolver extends DiagnosticEmitter { ): Type | null { // handle signature - if (node.kind == NodeKind.SIGNATURE) { - let explicitThisType = (node).explicitThisType; + if (node.kind == NodeKind.FUNCTIONTYPE) { + let explicitThisType = (node).explicitThisType; let thisType: Type | null = null; if (explicitThisType) { thisType = this.resolveType( @@ -139,7 +139,7 @@ export class Resolver extends DiagnosticEmitter { ); if (!thisType) return null; } - let parameterNodes = (node).parameters; + let parameterNodes = (node).parameters; let numParameters = parameterNodes.length; let parameterTypes = new Array(numParameters); let parameterNames = new Array(numParameters); @@ -178,7 +178,7 @@ export class Resolver extends DiagnosticEmitter { parameterTypes[i] = parameterType; parameterNames[i] = parameterNode.name.text; } - let returnTypeNode = (node).returnType; + let returnTypeNode = (node).returnType; if (isTypeOmitted(returnTypeNode)) { if (reportMode == ReportMode.REPORT) { this.error( @@ -208,8 +208,8 @@ export class Resolver extends DiagnosticEmitter { } // now dealing with TypeNode - assert(node.kind == NodeKind.TYPE); - var typeNode = node; + assert(node.kind == NodeKind.NAMEDTYPE); + var typeNode = node; var typeName = typeNode.name; var typeArgumentNodes = typeNode.typeArguments; var isSimpleType = !typeName.next; @@ -318,7 +318,8 @@ export class Resolver extends DiagnosticEmitter { if (isSimpleType) { switch (typeName.identifier.symbol) { case CommonSymbols.native: return this.resolveBuiltinNativeType(typeNode, context, contextualTypeArguments, reportMode); - case CommonSymbols.valueof: return this.resolveBuiltinValueofType(typeNode, context, contextualTypeArguments, reportMode) + case CommonSymbols.indexof: return this.resolveBuiltinIndexofType(typeNode, context, contextualTypeArguments, reportMode); + case CommonSymbols.valueof: return this.resolveBuiltinValueofType(typeNode, context, contextualTypeArguments, reportMode); } } @@ -374,7 +375,7 @@ export class Resolver extends DiagnosticEmitter { private resolveBuiltinNativeType( /** The type to resolve. */ - typeNode: TypeNode, + typeNode: NamedTypeNode, /** Relative context. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ @@ -415,9 +416,9 @@ export class Resolver extends DiagnosticEmitter { return null; } - private resolveBuiltinValueofType( + private resolveBuiltinIndexofType( /** The type to resolve. */ - typeNode: TypeNode, + typeNode: NamedTypeNode, /** Relative context. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ @@ -447,25 +448,49 @@ export class Resolver extends DiagnosticEmitter { } return null; } - var program = this.program; - var mapPrototype = program.mapPrototype; - var setPrototype = program.setPrototype; - var arrayPrototype = program.arrayPrototype; - if (classReference.extends(arrayPrototype)) { - let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); - assert(actualTypeArguments.length == 1); - return actualTypeArguments[0]; - } else if (classReference.extends(mapPrototype)) { - let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); - assert(actualTypeArguments.length == 2); - return actualTypeArguments[1]; - } else if (classReference.extends(setPrototype)) { - let actualTypeArguments = assert(classReference.getTypeArgumentsTo(arrayPrototype)); - assert(actualTypeArguments.length == 1); - return actualTypeArguments[0]; - } else { - let overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); - if (overload) return overload.signature.returnType; + var overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + if (overload) { + if (overload.is(CommonFlags.STATIC)) { + assert(overload.signature.parameterTypes.length == 2); + return overload.signature.parameterTypes[1]; + } else { + assert(overload.signature.parameterTypes.length == 1); + return overload.signature.parameterTypes[0]; + } + } + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + typeArgumentNodes[0].range, typeArgument.toString() + ); + } + return null; + } + + private resolveBuiltinValueofType( + /** The type to resolve. */ + typeNode: NamedTypeNode, + /** Relative context. */ + context: Element, + /** Type arguments inherited through context, i.e. `T`. */ + contextualTypeArguments: Map | null = null, + /** How to proceed with eventualy diagnostics. */ + reportMode: ReportMode = ReportMode.REPORT + ): Type | null { + var typeArgumentNodes = typeNode.typeArguments; + if (!(typeArgumentNodes && typeArgumentNodes.length == 1)) { + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Expected_0_type_arguments_but_got_1, + typeNode.range, "1", (typeArgumentNodes ? typeArgumentNodes.length : 1).toString(10) + ); + } + return null; + } + var typeArgument = this.resolveType(typeArgumentNodes[0], context, contextualTypeArguments, reportMode); + if (!typeArgument) return null; + var classReference = typeArgument.classReference; + if (!classReference) { if (reportMode == ReportMode.REPORT) { this.error( DiagnosticCode.Index_signature_is_missing_in_type_0, @@ -474,6 +499,16 @@ export class Resolver extends DiagnosticEmitter { } return null; } + + var overload = classReference.lookupOverload(OperatorKind.INDEXED_GET); + if (overload) return overload.signature.returnType; + if (reportMode == ReportMode.REPORT) { + this.error( + DiagnosticCode.Index_signature_is_missing_in_type_0, + typeArgumentNodes[0].range, typeArgument.toString() + ); + } + return null; } /** Resolves a type name to the program element it refers to. */ @@ -518,7 +553,7 @@ export class Resolver extends DiagnosticEmitter { /** Actual type parameter nodes. */ typeParameters: TypeParameterNode[], /** Type arguments provided. */ - typeArgumentNodes: CommonTypeNode[] | null, + typeArgumentNodes: TypeNode[] | null, /** Relative context. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ @@ -540,8 +575,8 @@ export class Resolver extends DiagnosticEmitter { DiagnosticCode.Expected_0_type_arguments_but_got_1, argumentCount ? Range.join( - (typeArgumentNodes)[0].range, - (typeArgumentNodes)[argumentCount - 1].range + (typeArgumentNodes)[0].range, + (typeArgumentNodes)[argumentCount - 1].range ) : assert(alternativeReportNode).range, (argumentCount < minParameterCount ? minParameterCount : maxParameterCount).toString(10), @@ -553,7 +588,7 @@ export class Resolver extends DiagnosticEmitter { for (let i = 0; i < maxParameterCount; ++i) { let type = i < argumentCount ? this.resolveType( // reports - (typeArgumentNodes)[i], + (typeArgumentNodes)[i], context, contextualTypeArguments, reportMode @@ -1398,7 +1433,7 @@ export class Resolver extends DiagnosticEmitter { } // override whatever is contextual with actual function type arguments - var signatureNode = prototype.signatureNode; + var signatureNode = prototype.functionTypeNode; var typeParameterNodes = prototype.typeParameterNodes; var numFunctionTypeArguments: i32; if (typeArguments && (numFunctionTypeArguments = typeArguments.length)) { @@ -1506,7 +1541,7 @@ export class Resolver extends DiagnosticEmitter { /** The prototype of the function. */ prototype: FunctionPrototype, /** Type arguments provided. */ - typeArgumentNodes: CommonTypeNode[] | null, + typeArgumentNodes: TypeNode[] | null, /** Relative context. Type arguments are resolved from here. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ @@ -1795,7 +1830,7 @@ export class Resolver extends DiagnosticEmitter { /** The prototype of the class. */ prototype: ClassPrototype, /** Type argument nodes provided. */ - typeArgumentNodes: CommonTypeNode[] | null, + typeArgumentNodes: TypeNode[] | null, /** Relative context. Type arguments are resolved from here. */ context: Element, /** Type arguments inherited through context, i.e. `T`. */ diff --git a/std/assembly/index.d.ts b/std/assembly/index.d.ts index 71c57a2a96..eae1cce951 100644 --- a/std/assembly/index.d.ts +++ b/std/assembly/index.d.ts @@ -882,7 +882,9 @@ declare namespace v8x16 { } /** Macro type evaluating to the underlying native WebAssembly type. */ declare type native = T; -/** Special type evaluating the value type of a collection. */ +/** Special type evaluating the indexed access index type. */ +declare type indexof = keyof T; +/** Special type evaluating the indexed access value type. */ declare type valueof = T[0]; /** Pseudo-class representing the backing class of integer types. */ diff --git a/std/assembly/map.ts b/std/assembly/map.ts index 9430ad6fef..a0defe12f9 100644 --- a/std/assembly/map.ts +++ b/std/assembly/map.ts @@ -1,6 +1,7 @@ /// import { HASH } from "./util/hash"; +import { E_KEYNOTFOUND } from "util/error"; // A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht @@ -96,11 +97,14 @@ export class Map { return this.find(key, HASH(key)) !== null; } + @operator("[]") get(key: K): V { var entry = this.find(key, HASH(key)); - return entry ? entry.value : unreachable(); + if (!entry) throw new Error(E_KEYNOTFOUND); // cannot represent `undefined` + return entry.value; } + @operator("[]=") set(key: K, value: V): void { var hashCode = HASH(key); var entry = this.find(key, hashCode); // unmanaged! diff --git a/std/assembly/set.ts b/std/assembly/set.ts index a235410545..d361b5619b 100644 --- a/std/assembly/set.ts +++ b/std/assembly/set.ts @@ -88,6 +88,7 @@ export class Set { return null; } + @operator("[]") has(key: T): bool { return this.find(key, HASH(key)) !== null; } @@ -117,6 +118,12 @@ export class Set { } } + @operator("[]=") + private __set(key: T, value: bool): void { + if (value) this.add(key); + else this.delete(key); + } + delete(key: T): bool { var entry = this.find(key, HASH(key)); // unmanaged! if (!entry) return false; diff --git a/std/assembly/util/error.ts b/std/assembly/util/error.ts index cbee8cbffa..20ce7f6d78 100644 --- a/std/assembly/util/error.ts +++ b/std/assembly/util/error.ts @@ -20,3 +20,7 @@ export const E_HOLEYARRAY: string = "Element type must be nullable if array is h // @ts-ignore: decorator @lazy @inline export const E_NOTIMPLEMENTED: string = "Not implemented"; + +// @ts-ignore: decorator +@lazy @inline +export const E_KEYNOTFOUND: string = "Key does not exist"; diff --git a/std/portable/index.d.ts b/std/portable/index.d.ts index 67552f8df9..75a565a6dc 100644 --- a/std/portable/index.d.ts +++ b/std/portable/index.d.ts @@ -28,7 +28,9 @@ declare type usize = number; declare type f32 = number; declare type f64 = number; -/** Special type evaluating the value type of a collection. */ +/** Special type evaluating the indexed access index type. */ +declare type indexof = keyof T; +/** Special type evaluating the indexed access value type. */ declare type valueof = T[0]; // Compiler hints diff --git a/tests/compiler/valueof.json b/tests/compiler/indexof-valueof.json similarity index 100% rename from tests/compiler/valueof.json rename to tests/compiler/indexof-valueof.json diff --git a/tests/compiler/indexof-valueof.optimized.wat b/tests/compiler/indexof-valueof.optimized.wat new file mode 100644 index 0000000000..3adc5f22a3 --- /dev/null +++ b/tests/compiler/indexof-valueof.optimized.wat @@ -0,0 +1,9 @@ +(module + (type $FUNCSIG$v (func)) + (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\00o\00f\00-\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s") + (export "memory" (memory $0)) + (func $start (; 0 ;) (type $FUNCSIG$v) + nop + ) +) diff --git a/tests/compiler/indexof-valueof.ts b/tests/compiler/indexof-valueof.ts new file mode 100644 index 0000000000..9e271e2c0b --- /dev/null +++ b/tests/compiler/indexof-valueof.ts @@ -0,0 +1,61 @@ +// simple indexes +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 4); // i32 + +// simple values +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 1); + +// using an alias +type u32Array = u32[]; +assert(isInteger>()); +assert(!isSigned>()); +assert(sizeof>() == 4); + +// float values +assert(isFloat>()); +assert(sizeof>() == 4); + +// string values +assert(isString>()); +assert(isManaged>()); + +// array indexes +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 4); // i32 + +// array values +assert(isArray>()); + +// typed array indexes +assert(isInteger>()); +assert(isSigned>()); +assert(sizeof>() == 4); // i32 + +// typed array values +assert(isInteger>()); +assert(!isSigned>()); +assert(sizeof>() == 1); + +// map indexes +assert(isInteger>>()); +assert(isFloat>>()); +assert(isString>>()); + +// map values +assert(isInteger>>()); +assert(isFloat>>()); +assert(isString>>()); + +// set indexes +assert(isInteger>>()); +assert(isFloat>>()); +assert(isString>>()); + +// set values (always bool) +assert(isBoolean>>()); +assert(isBoolean>>()); +assert(isBoolean>>()); diff --git a/tests/compiler/indexof-valueof.untouched.wat b/tests/compiler/indexof-valueof.untouched.wat new file mode 100644 index 0000000000..57aaf3ead2 --- /dev/null +++ b/tests/compiler/indexof-valueof.untouched.wat @@ -0,0 +1,384 @@ +(module + (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\00d\00e\00x\00o\00f\00-\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s\00") + (table $0 1 funcref) + (elem (i32.const 0) $null) + (export "memory" (memory $0)) + (start $start) + (func $start:indexof-valueof (; 1 ;) (type $FUNCSIG$v) + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 2 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 3 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 4 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 7 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 8 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 9 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 13 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 14 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 15 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 18 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 19 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 22 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 23 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 26 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 27 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 28 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 31 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 34 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 35 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 4 + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 36 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 39 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 40 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 41 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 44 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 45 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 46 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 49 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 50 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 51 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 54 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 55 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 56 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 59 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 60 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + i32.const 1 + i32.eqz + if + i32.const 0 + i32.const 24 + i32.const 61 + i32.const 0 + call $~lib/builtins/abort + unreachable + end + ) + (func $start (; 2 ;) (type $FUNCSIG$v) + call $start:indexof-valueof + ) + (func $null (; 3 ;) (type $FUNCSIG$v) + ) +) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 0bd1913cf6..dcc8c8ce6d 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -35,7 +35,9 @@ (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/\00m\00a\00p\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\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 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") (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) (global $~lib/rt/pure/CUR (mut i32) (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) @@ -627,10 +629,10 @@ if unreachable end - i32.const 512 + i32.const 608 i32.const 0 i32.store - i32.const 2080 + i32.const 2176 i32.const 0 i32.store i32.const 0 @@ -644,7 +646,7 @@ local.get $0 i32.const 2 i32.shl - i32.const 512 + i32.const 608 i32.add i32.const 0 i32.store offset=4 @@ -663,7 +665,7 @@ i32.add i32.const 2 i32.shl - i32.const 512 + i32.const 608 i32.add i32.const 0 i32.store offset=96 @@ -681,13 +683,13 @@ br $loop|0 end end - i32.const 512 - i32.const 2096 + i32.const 608 + i32.const 2192 memory.size i32.const 16 i32.shl call $~lib/rt/tlsf/addMemory - i32.const 512 + i32.const 608 global.set $~lib/rt/tlsf/ROOT ) (func $~lib/rt/tlsf/prepareSize (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -1079,7 +1081,7 @@ ) (func $~lib/rt/pure/__retain (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.const 508 + i32.const 604 i32.gt_u if local.get $0 @@ -1348,7 +1350,7 @@ ) (func $~lib/rt/__typeinfo (; 20 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 - i32.const 400 + i32.const 496 i32.load i32.gt_u if @@ -1362,7 +1364,7 @@ local.get $0 i32.const 3 i32.shl - i32.const 404 + i32.const 500 i32.add i32.load ) @@ -1734,7 +1736,7 @@ ) (func $~lib/rt/pure/__release (; 26 ;) (type $FUNCSIG$vi) (param $0 i32) local.get $0 - i32.const 508 + i32.const 604 i32.gt_u if local.get $0 @@ -2107,12 +2109,17 @@ call $~lib/util/hash/hash8 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 35 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) @@ -2796,12 +2803,17 @@ call $~lib/util/hash/hash8 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 42 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) @@ -3535,12 +3547,17 @@ call $~lib/util/hash/hash16 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 51 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) @@ -4224,12 +4241,17 @@ call $~lib/util/hash/hash16 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 58 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) @@ -4965,12 +4987,17 @@ call $~lib/util/hash/hash32 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 67 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) @@ -6104,12 +6131,17 @@ call $~lib/util/hash/hash64 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=8 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=8 ) (func $~lib/map/Map#delete (; 79 ;) (type $FUNCSIG$vij) (param $0 i32) (param $1 i64) (local $2 i32) @@ -7163,12 +7195,17 @@ call $~lib/util/hash/hash32 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) (func $~lib/map/Map#delete (; 89 ;) (type $FUNCSIG$vif) (param $0 i32) (param $1 f32) (local $2 i32) @@ -7870,12 +7907,17 @@ call $~lib/util/hash/hash64 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=8 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=8 ) (func $~lib/map/Map#delete (; 97 ;) (type $FUNCSIG$vid) (param $0 i32) (param $1 f64) (local $2 i32) @@ -8381,7 +8423,7 @@ ) (func $~lib/rt/pure/__visit (; 104 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) local.get $0 - i32.const 508 + i32.const 604 i32.lt_u if return diff --git a/tests/compiler/std/map.untouched.wat b/tests/compiler/std/map.untouched.wat index 0e4cde4c9a..183ce25e54 100644 --- a/tests/compiler/std/map.untouched.wat +++ b/tests/compiler/std/map.untouched.wat @@ -31,7 +31,9 @@ (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/\00m\00a\00p\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\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 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") (table $0 1 funcref) (elem (i32.const 0) $null) (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) @@ -39,8 +41,8 @@ (global $~lib/rt/pure/CUR (mut i32) (i32.const 0)) (global $~lib/rt/pure/END (mut i32) (i32.const 0)) (global $~lib/rt/pure/ROOTS (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/rt/__rtti_base i32 (i32.const 496)) + (global $~lib/heap/__heap_base i32 (i32.const 604)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/tlsf/removeBlock (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) @@ -3663,12 +3665,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 36 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -4542,12 +4549,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 46 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -5435,12 +5447,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 57 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -6314,12 +6331,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 67 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -7211,12 +7233,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 78 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -8050,12 +8077,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 88 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -8979,12 +9011,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=8 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=8 ) (func $~lib/map/Map#get:size (; 99 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -9828,12 +9865,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=8 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=8 ) (func $~lib/map/Map#get:size (; 109 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -10681,12 +10723,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 ) (func $~lib/map/Map#get:size (; 119 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 @@ -11535,12 +11582,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=8 - else + i32.eqz + if + i32.const 416 + i32.const 472 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=8 ) (func $~lib/map/Map#get:size (; 129 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index 99ff5fceeb..60d5db95ac 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -14,25 +14,27 @@ (data (i32.const 32) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00s\00t\00d\00/\00s\00y\00m\00b\00o\00l\00.\00t\00s") (data (i32.const 80) "\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 128) "&\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 188) "\01\00\00\00\01") - (data (i32.const 200) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e") - (data (i32.const 240) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e") - (data (i32.const 296) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00i\00s\00R\00e\00g\00E\00x\00p") - (data (i32.const 328) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00m\00a\00t\00c\00h") - (data (i32.const 360) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00r\00e\00p\00l\00a\00c\00e") - (data (i32.const 392) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00s\00e\00a\00r\00c\00h") - (data (i32.const 424) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00s\00p\00e\00c\00i\00e\00s") - (data (i32.const 456) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00s\00p\00l\00i\00t") - (data (i32.const 488) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00P\00r\00i\00m\00i\00t\00i\00v\00e") - (data (i32.const 528) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00S\00t\00r\00i\00n\00g\00T\00a\00g") - (data (i32.const 568) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00u\00n\00s\00c\00o\00p\00a\00b\00l\00e\00s") - (data (i32.const 608) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00S\00y\00m\00b\00o\00l\00(") - (data (i32.const 640) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l") - (data (i32.const 664) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00)") - (data (i32.const 688) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00S\00y\00m\00b\00o\00l\00(\00)") - (data (i32.const 720) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00S\00y\00m\00b\00o\00l\00(\001\002\003\00)") - (data (i32.const 760) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00S\00y\00m\00b\00o\00l\00(\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00)") - (data (i32.const 816) "4\00\00\00\01\00\00\00\01\00\00\004\00\00\00S\00y\00m\00b\00o\00l\00(\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00)") + (data (i32.const 184) "$\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 240) "\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 284) "\01\00\00\00\01") + (data (i32.const 296) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e") + (data (i32.const 336) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e") + (data (i32.const 392) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00i\00s\00R\00e\00g\00E\00x\00p") + (data (i32.const 424) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00m\00a\00t\00c\00h") + (data (i32.const 456) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00r\00e\00p\00l\00a\00c\00e") + (data (i32.const 488) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00s\00e\00a\00r\00c\00h") + (data (i32.const 520) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00s\00p\00e\00c\00i\00e\00s") + (data (i32.const 552) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00s\00p\00l\00i\00t") + (data (i32.const 584) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00P\00r\00i\00m\00i\00t\00i\00v\00e") + (data (i32.const 624) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00S\00t\00r\00i\00n\00g\00T\00a\00g") + (data (i32.const 664) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00u\00n\00s\00c\00o\00p\00a\00b\00l\00e\00s") + (data (i32.const 704) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00S\00y\00m\00b\00o\00l\00(") + (data (i32.const 736) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l") + (data (i32.const 760) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00)") + (data (i32.const 784) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00S\00y\00m\00b\00o\00l\00(\00)") + (data (i32.const 816) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00S\00y\00m\00b\00o\00l\00(\001\002\003\00)") + (data (i32.const 856) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00S\00y\00m\00b\00o\00l\00(\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00)") + (data (i32.const 912) "4\00\00\00\01\00\00\00\01\00\00\004\00\00\00S\00y\00m\00b\00o\00l\00(\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00)") (global $~lib/symbol/nextId (mut i32) (i32.const 12)) (global $std/symbol/sym1 (mut i32) (i32.const 0)) (global $std/symbol/sym2 (mut i32) (i32.const 0)) @@ -609,7 +611,25 @@ end i32.const 0 ) - (func $~lib/map/Map<~lib/string/String,usize>#rehash (; 13 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map<~lib/string/String,usize>#get (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + local.get $0 + i32.const 24 + call $~lib/util/hash/hashStr + call $~lib/map/Map<~lib/string/String,usize>#find + local.tee $0 + i32.eqz + if + i32.const 200 + i32.const 256 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + ) + (func $~lib/map/Map<~lib/string/String,usize>#rehash (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -716,7 +736,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map<~lib/string/String,usize>#set (; 14 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map<~lib/string/String,usize>#set (; 15 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -805,7 +825,7 @@ i32.store end ) - (func $~lib/util/hash/hash32 (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/util/hash/hash32 (; 16 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) local.get $0 i32.const 255 i32.and @@ -836,7 +856,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/map/Map#find (; 16 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 17 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) local.get $0 i32.load local.get $0 @@ -879,7 +899,7 @@ end i32.const 0 ) - (func $~lib/map/Map#rehash (; 17 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 18 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -986,7 +1006,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 18 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#set (; 19 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1082,7 +1102,7 @@ i32.store end ) - (func $~lib/symbol/_Symbol.for (; 19 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/symbol/_Symbol.for (; 20 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) global.get $~lib/symbol/stringToId if @@ -1092,16 +1112,7 @@ call $~lib/map/Map<~lib/string/String,usize>#find if global.get $~lib/symbol/stringToId - i32.const 24 - call $~lib/util/hash/hashStr - call $~lib/map/Map<~lib/string/String,usize>#find - local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else - unreachable - end + call $~lib/map/Map<~lib/string/String,usize>#get return end else @@ -1128,7 +1139,7 @@ call $~lib/map/Map#set local.get $0 ) - (func $~lib/map/Map#has (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#has (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 local.get $1 @@ -1137,21 +1148,26 @@ i32.const 0 i32.ne ) - (func $~lib/map/Map#get (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#get (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 local.get $1 call $~lib/util/hash/hash32 call $~lib/map/Map#find local.tee $0 - if (result i32) - local.get $0 - i32.load offset=4 - else + i32.eqz + if + i32.const 200 + i32.const 256 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $0 + i32.load offset=4 ) - (func $~lib/symbol/_Symbol.keyFor (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/symbol/_Symbol.keyFor (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) global.get $~lib/symbol/idToString if (result i32) global.get $~lib/symbol/idToString @@ -1168,7 +1184,7 @@ i32.const 0 end ) - (func $~lib/memory/memory.copy (; 23 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/memory/memory.copy (; 24 ;) (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 @@ -1343,7 +1359,7 @@ end end ) - (func $~lib/string/String#concat (; 24 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#concat (; 25 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1353,7 +1369,7 @@ i32.shl local.tee $3 local.get $1 - i32.const 656 + i32.const 752 local.get $1 select local.tee $1 @@ -1365,7 +1381,7 @@ local.tee $2 i32.eqz if - i32.const 200 + i32.const 296 return end local.get $2 @@ -1383,16 +1399,16 @@ call $~lib/memory/memory.copy local.get $2 ) - (func $~lib/string/String.__concat (; 25 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__concat (; 26 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) local.get $0 - i32.const 656 + i32.const 752 local.get $0 select local.get $1 call $~lib/string/String#concat ) - (func $~lib/symbol/_Symbol#toString (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - i32.const 624 + (func $~lib/symbol/_Symbol#toString (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + i32.const 720 block $break|0 (result i32) block $case11|0 block $case10|0 @@ -1421,37 +1437,37 @@ end br $case11|0 end - i32.const 216 + i32.const 312 br $break|0 end - i32.const 256 + i32.const 352 br $break|0 end - i32.const 312 + i32.const 408 br $break|0 end - i32.const 344 + i32.const 440 br $break|0 end - i32.const 376 + i32.const 472 br $break|0 end - i32.const 408 + i32.const 504 br $break|0 end - i32.const 440 + i32.const 536 br $break|0 end - i32.const 472 + i32.const 568 br $break|0 end - i32.const 504 + i32.const 600 br $break|0 end - i32.const 544 + i32.const 640 br $break|0 end - i32.const 584 + i32.const 680 br $break|0 end global.get $~lib/symbol/idToString @@ -1467,14 +1483,14 @@ local.get $0 call $~lib/map/Map#get else - i32.const 200 + i32.const 296 end end call $~lib/string/String.__concat - i32.const 680 + i32.const 776 call $~lib/string/String.__concat ) - (func $start:std/symbol (; 27 ;) (type $FUNCSIG$v) + (func $start:std/symbol (; 28 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 24 call $~lib/symbol/Symbol @@ -1493,7 +1509,7 @@ call $~lib/builtins/abort unreachable end - i32.const 896 + i32.const 992 global.set $~lib/rt/stub/startOffset global.get $~lib/rt/stub/startOffset global.set $~lib/rt/stub/offset @@ -1581,7 +1597,7 @@ i32.const 0 call $~lib/symbol/Symbol call $~lib/symbol/_Symbol#toString - i32.const 704 + i32.const 800 call $~lib/string/String.__eq i32.eqz if @@ -1594,7 +1610,7 @@ end global.get $std/symbol/sym3 call $~lib/symbol/_Symbol#toString - i32.const 736 + i32.const 832 call $~lib/string/String.__eq i32.eqz if @@ -1611,7 +1627,7 @@ global.set $std/symbol/isConcatSpreadable global.get $std/symbol/hasInstance call $~lib/symbol/_Symbol#toString - i32.const 776 + i32.const 872 call $~lib/string/String.__eq i32.eqz if @@ -1624,7 +1640,7 @@ end global.get $std/symbol/isConcatSpreadable call $~lib/symbol/_Symbol#toString - i32.const 832 + i32.const 928 call $~lib/string/String.__eq i32.eqz if @@ -1636,10 +1652,10 @@ unreachable end ) - (func $start (; 28 ;) (type $FUNCSIG$v) + (func $start (; 29 ;) (type $FUNCSIG$v) call $start:std/symbol ) - (func $null (; 29 ;) (type $FUNCSIG$v) + (func $null (; 30 ;) (type $FUNCSIG$v) nop ) ) diff --git a/tests/compiler/std/symbol.untouched.wat b/tests/compiler/std/symbol.untouched.wat index 89ff851c1f..cb1393363e 100644 --- a/tests/compiler/std/symbol.untouched.wat +++ b/tests/compiler/std/symbol.untouched.wat @@ -14,25 +14,27 @@ (data (i32.const 32) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00s\00t\00d\00/\00s\00y\00m\00b\00o\00l\00.\00t\00s\00") (data (i32.const 80) "\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 128) "&\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 184) "\00\00\00\00\01\00\00\00\01\00\00\00\00\00\00\00") - (data (i32.const 200) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00") - (data (i32.const 240) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00") - (data (i32.const 296) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00i\00s\00R\00e\00g\00E\00x\00p\00") - (data (i32.const 328) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00m\00a\00t\00c\00h\00") - (data (i32.const 360) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00r\00e\00p\00l\00a\00c\00e\00") - (data (i32.const 392) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00s\00e\00a\00r\00c\00h\00") - (data (i32.const 424) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00s\00p\00e\00c\00i\00e\00s\00") - (data (i32.const 456) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00s\00p\00l\00i\00t\00") - (data (i32.const 488) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00P\00r\00i\00m\00i\00t\00i\00v\00e\00") - (data (i32.const 528) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00S\00t\00r\00i\00n\00g\00T\00a\00g\00") - (data (i32.const 568) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00u\00n\00s\00c\00o\00p\00a\00b\00l\00e\00s\00") - (data (i32.const 608) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00S\00y\00m\00b\00o\00l\00(\00") - (data (i32.const 640) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00") - (data (i32.const 664) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00)\00") - (data (i32.const 688) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00S\00y\00m\00b\00o\00l\00(\00)\00") - (data (i32.const 720) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00S\00y\00m\00b\00o\00l\00(\001\002\003\00)\00") - (data (i32.const 760) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00S\00y\00m\00b\00o\00l\00(\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00)\00") - (data (i32.const 816) "4\00\00\00\01\00\00\00\01\00\00\004\00\00\00S\00y\00m\00b\00o\00l\00(\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00)\00") + (data (i32.const 184) "$\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 240) "\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 280) "\00\00\00\00\01\00\00\00\01\00\00\00\00\00\00\00") + (data (i32.const 296) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00") + (data (i32.const 336) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00") + (data (i32.const 392) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00i\00s\00R\00e\00g\00E\00x\00p\00") + (data (i32.const 424) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00m\00a\00t\00c\00h\00") + (data (i32.const 456) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00r\00e\00p\00l\00a\00c\00e\00") + (data (i32.const 488) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00s\00e\00a\00r\00c\00h\00") + (data (i32.const 520) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00s\00p\00e\00c\00i\00e\00s\00") + (data (i32.const 552) "\n\00\00\00\01\00\00\00\01\00\00\00\n\00\00\00s\00p\00l\00i\00t\00") + (data (i32.const 584) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00P\00r\00i\00m\00i\00t\00i\00v\00e\00") + (data (i32.const 624) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00t\00o\00S\00t\00r\00i\00n\00g\00T\00a\00g\00") + (data (i32.const 664) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00u\00n\00s\00c\00o\00p\00a\00b\00l\00e\00s\00") + (data (i32.const 704) "\0e\00\00\00\01\00\00\00\01\00\00\00\0e\00\00\00S\00y\00m\00b\00o\00l\00(\00") + (data (i32.const 736) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00n\00u\00l\00l\00") + (data (i32.const 760) "\02\00\00\00\01\00\00\00\01\00\00\00\02\00\00\00)\00") + (data (i32.const 784) "\10\00\00\00\01\00\00\00\01\00\00\00\10\00\00\00S\00y\00m\00b\00o\00l\00(\00)\00") + (data (i32.const 816) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00S\00y\00m\00b\00o\00l\00(\001\002\003\00)\00") + (data (i32.const 856) "&\00\00\00\01\00\00\00\01\00\00\00&\00\00\00S\00y\00m\00b\00o\00l\00(\00h\00a\00s\00I\00n\00s\00t\00a\00n\00c\00e\00)\00") + (data (i32.const 912) "4\00\00\00\01\00\00\00\01\00\00\004\00\00\00S\00y\00m\00b\00o\00l\00(\00i\00s\00C\00o\00n\00c\00a\00t\00S\00p\00r\00e\00a\00d\00a\00b\00l\00e\00)\00") (table $0 1 funcref) (elem (i32.const 0) $null) (global $~lib/symbol/nextId (mut i32) (i32.const 12)) @@ -53,7 +55,7 @@ (global $std/symbol/hasInstance (mut i32) (i32.const 0)) (global $~lib/symbol/_Symbol.isConcatSpreadable i32 (i32.const 2)) (global $std/symbol/isConcatSpreadable (mut i32) (i32.const 0)) - (global $~lib/heap/__heap_base i32 (i32.const 884)) + (global $~lib/heap/__heap_base i32 (i32.const 980)) (export "memory" (memory $0)) (start $start) (func $~lib/rt/stub/__retain (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -919,12 +921,19 @@ call $~lib/map/Map<~lib/string/String,usize>#find local.set $4 local.get $4 - if (result i32) - local.get $4 - i32.load offset=4 - else + i32.eqz + if + local.get $1 + call $~lib/rt/stub/__release + i32.const 200 + i32.const 256 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $4 + i32.load offset=4 local.set $2 local.get $1 call $~lib/rt/stub/__release @@ -1655,7 +1664,6 @@ (func $~lib/map/Map#get (; 26 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) - (local $4 i32) local.get $0 local.get $1 block $~lib/util/hash/HASH|inlined.3 (result i32) @@ -1668,14 +1676,17 @@ call $~lib/map/Map#find local.set $3 local.get $3 - if (result i32) - local.get $3 - i32.load offset=4 - call $~lib/rt/stub/__retain - local.tee $2 - else + i32.eqz + if + i32.const 200 + i32.const 256 + i32.const 103 + i32.const 16 + call $~lib/builtins/abort unreachable end + local.get $3 + i32.load offset=4 call $~lib/rt/stub/__retain ) (func $~lib/symbol/_Symbol.keyFor (; 27 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) @@ -2965,7 +2976,7 @@ i32.const 0 i32.eq if - i32.const 656 + i32.const 752 local.tee $2 local.get $1 local.tee $3 @@ -2998,7 +3009,7 @@ i32.const 0 i32.eq if - i32.const 200 + i32.const 296 call $~lib/rt/stub/__retain local.set $2 local.get $1 @@ -3036,7 +3047,7 @@ call $~lib/rt/stub/__retain drop local.get $0 - i32.const 656 + i32.const 752 local.get $0 i32.const 0 i32.ne @@ -3058,7 +3069,7 @@ (local $5 i32) local.get $0 local.set $1 - i32.const 200 + i32.const 296 call $~lib/rt/stub/__retain local.set $2 block $break|0 @@ -3122,7 +3133,7 @@ br_if $case10|0 br $case11|0 end - i32.const 216 + i32.const 312 local.tee $3 local.get $2 local.tee $4 @@ -3138,7 +3149,7 @@ local.set $2 br $break|0 end - i32.const 256 + i32.const 352 local.tee $4 local.get $2 local.tee $3 @@ -3154,7 +3165,7 @@ local.set $2 br $break|0 end - i32.const 312 + i32.const 408 local.tee $3 local.get $2 local.tee $4 @@ -3170,7 +3181,7 @@ local.set $2 br $break|0 end - i32.const 344 + i32.const 440 local.tee $4 local.get $2 local.tee $3 @@ -3186,7 +3197,7 @@ local.set $2 br $break|0 end - i32.const 376 + i32.const 472 local.tee $3 local.get $2 local.tee $4 @@ -3202,7 +3213,7 @@ local.set $2 br $break|0 end - i32.const 408 + i32.const 504 local.tee $4 local.get $2 local.tee $3 @@ -3218,7 +3229,7 @@ local.set $2 br $break|0 end - i32.const 440 + i32.const 536 local.tee $3 local.get $2 local.tee $4 @@ -3234,7 +3245,7 @@ local.set $2 br $break|0 end - i32.const 472 + i32.const 568 local.tee $4 local.get $2 local.tee $3 @@ -3250,7 +3261,7 @@ local.set $2 br $break|0 end - i32.const 504 + i32.const 600 local.tee $3 local.get $2 local.tee $4 @@ -3266,7 +3277,7 @@ local.set $2 br $break|0 end - i32.const 544 + i32.const 640 local.tee $4 local.get $2 local.tee $3 @@ -3282,7 +3293,7 @@ local.set $2 br $break|0 end - i32.const 584 + i32.const 680 local.tee $3 local.get $2 local.tee $4 @@ -3320,11 +3331,11 @@ end br $break|0 end - i32.const 624 + i32.const 720 local.get $2 call $~lib/string/String.__concat local.tee $4 - i32.const 680 + i32.const 776 call $~lib/string/String.__concat local.tee $3 call $~lib/rt/stub/__retain @@ -3466,7 +3477,7 @@ call $~lib/symbol/Symbol call $~lib/symbol/_Symbol#toString local.tee $0 - i32.const 704 + i32.const 800 call $~lib/string/String.__eq i32.eqz if @@ -3480,7 +3491,7 @@ global.get $std/symbol/sym3 call $~lib/symbol/_Symbol#toString local.tee $1 - i32.const 736 + i32.const 832 call $~lib/string/String.__eq i32.eqz if @@ -3498,7 +3509,7 @@ global.get $std/symbol/hasInstance call $~lib/symbol/_Symbol#toString local.tee $2 - i32.const 776 + i32.const 872 call $~lib/string/String.__eq i32.eqz if @@ -3512,7 +3523,7 @@ global.get $std/symbol/isConcatSpreadable call $~lib/symbol/_Symbol#toString local.tee $3 - i32.const 832 + i32.const 928 call $~lib/string/String.__eq i32.eqz if diff --git a/tests/compiler/valueof.optimized.wat b/tests/compiler/valueof.optimized.wat deleted file mode 100644 index e396f28a3c..0000000000 --- a/tests/compiler/valueof.optimized.wat +++ /dev/null @@ -1,9 +0,0 @@ -(module - (type $FUNCSIG$v (func)) - (memory $0 1) - (data (i32.const 8) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s") - (export "memory" (memory $0)) - (func $start (; 0 ;) (type $FUNCSIG$v) - nop - ) -) diff --git a/tests/compiler/valueof.ts b/tests/compiler/valueof.ts deleted file mode 100644 index ee200c22a7..0000000000 --- a/tests/compiler/valueof.ts +++ /dev/null @@ -1,26 +0,0 @@ -// simple -assert(isInteger>()); -assert(isSigned>()); -assert(sizeof>() == 1); - -// alias -type u32Array = u32[]; -assert(isInteger>()); -assert(!isSigned>()); -assert(sizeof>() == 4); - -// float -assert(isFloat>()); -assert(sizeof>() == 4); - -// string -assert(isString>()); -assert(isManaged>()); - -// array -assert(isArray>()); - -// typed array -assert(isInteger>()); -assert(!isSigned>()); -assert(sizeof>() == 1); diff --git a/tests/compiler/valueof.untouched.wat b/tests/compiler/valueof.untouched.wat deleted file mode 100644 index 43cb6cdc94..0000000000 --- a/tests/compiler/valueof.untouched.wat +++ /dev/null @@ -1,168 +0,0 @@ -(module - (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) "\14\00\00\00\01\00\00\00\01\00\00\00\14\00\00\00v\00a\00l\00u\00e\00o\00f\00.\00t\00s\00") - (table $0 1 funcref) - (elem (i32.const 0) $null) - (export "memory" (memory $0)) - (start $start) - (func $start:valueof (; 1 ;) (type $FUNCSIG$v) - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 2 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 3 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.const 1 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 4 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 8 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 0 - i32.eqz - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 9 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 4 - i32.const 4 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 10 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 13 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 4 - i32.const 4 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 14 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 17 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 18 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 21 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 24 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 0 - i32.eqz - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 25 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - i32.const 1 - i32.const 1 - i32.eq - i32.eqz - if - i32.const 0 - i32.const 24 - i32.const 26 - i32.const 0 - call $~lib/builtins/abort - unreachable - end - ) - (func $start (; 2 ;) (type $FUNCSIG$v) - call $start:valueof - ) - (func $null (; 3 ;) (type $FUNCSIG$v) - ) -)