From a0f71458dcf39a28d9687dbdadc8f5d95790dfa7 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 15 Apr 2020 17:38:17 -0700 Subject: [PATCH 01/10] Made the test fail --- tests/compiler/std/object-literal.ts | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/compiler/std/object-literal.ts b/tests/compiler/std/object-literal.ts index d5625db01c..26d304353b 100644 --- a/tests/compiler/std/object-literal.ts +++ b/tests/compiler/std/object-literal.ts @@ -27,3 +27,34 @@ function bar2(foo: Foo2): void { bar2({ bar: 2 }); ({ bar: 3 }).test(); + + +// Test omitted fields +class OmittedFoo { + bar: string | null; + baz: string | null; + quux: string | null; + quuz: string | null; + corge: string | null; + grault: string | null; + garply: string | null; + // waldo: string | null = 'Yo'; + // fred: i32; + // qux: i32 = -1; +} + +function testOmit(foo: OmittedFoo): void { + assert(changetype(foo.baz) == 0); + assert(changetype(foo.baz) == 0); + assert(changetype(foo.quux) == 0); + assert(changetype(foo.quuz) == 0); + assert(changetype(foo.corge) == 0); + assert(changetype(foo.grault) == 0); + assert(changetype(foo.garply) == 0); + // assert(foo.waldo == 'Yo'); + // assert(foo.fred == 0); + // assert(foo.qux == -1); +} + +testOmit({}); + From a3181501d3cda962074466a5aa88e6fb9d235f1d Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 15 Apr 2020 18:25:20 -0700 Subject: [PATCH 02/10] Start actually fixing the compiler --- src/compiler.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler.ts b/src/compiler.ts index 1c27c991e0..f6c975009c 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8688,6 +8688,12 @@ export class Compiler extends DiagnosticEmitter { ? flow.getAutoreleaseLocal(classReference.type) : flow.getTempLocal(classReference.type); assert(numNames == values.length); + if (names.length == 0) { + console.log('expression names', names); + console.log('class members', members); + } + + // Currently iterates through the passed names, should instead iterate through the members for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; if (!member || member.kind != ElementKind.FIELD) { From e8314c39239de691344c2ffac285899f718568d4 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 15 Apr 2020 18:25:44 -0700 Subject: [PATCH 03/10] Left a tag for me to jump to --- src/compiler.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler.ts b/src/compiler.ts index f6c975009c..cb76697c79 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8693,7 +8693,9 @@ export class Compiler extends DiagnosticEmitter { console.log('class members', members); } - // Currently iterates through the passed names, should instead iterate through the members + // torch2424: Currently iterates through the passed names, should instead iterate through the members + + for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; if (!member || member.kind != ElementKind.FIELD) { From 64c17cecc2018331fc31d15713029ac10c40b0e4 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Thu, 16 Apr 2020 15:55:50 -0700 Subject: [PATCH 04/10] Added error message for missing object literal fields, and added a test --- src/compiler.ts | 44 ++++++++++++++++--- src/diagnosticMessages.generated.ts | 2 + src/diagnosticMessages.json | 1 + .../compiler/std/object-literal-omitted.json | 5 +++ .../std/object-literal-omitted.optimized.wat | 4 ++ tests/compiler/std/object-literal-omitted.ts | 31 +++++++++++++ .../std/object-literal-omitted.untouched.wat | 5 +++ tests/compiler/std/object-literal.ts | 30 ------------- 8 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 tests/compiler/std/object-literal-omitted.json create mode 100644 tests/compiler/std/object-literal-omitted.optimized.wat create mode 100644 tests/compiler/std/object-literal-omitted.ts create mode 100644 tests/compiler/std/object-literal-omitted.untouched.wat diff --git a/src/compiler.ts b/src/compiler.ts index cb76697c79..e308cce4f0 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8688,14 +8688,19 @@ export class Compiler extends DiagnosticEmitter { ? flow.getAutoreleaseLocal(classReference.type) : flow.getTempLocal(classReference.type); assert(numNames == values.length); - if (names.length == 0) { - console.log('expression names', names); - console.log('class members', members); - } - // torch2424: Currently iterates through the passed names, should instead iterate through the members - + // Assume all class fields will be omitted, and add them to our omitted list + var omittedClassFieldMembers = new Map(); + if (members) { + for (let memberKey of members.keys()) { + let member = members.get(memberKey); + if (member && member.kind == ElementKind.FIELD) { + omittedClassFieldMembers.set(member.name, ''); + } + } + } + // Iterate through the members definted in our expression for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; if (!member || member.kind != ElementKind.FIELD) { @@ -8715,7 +8720,34 @@ export class Compiler extends DiagnosticEmitter { fieldType.toNativeType(), fieldInstance.memoryOffset ); + + // This member is no longer omitted, so delete from our omitted fields + omittedClassFieldMembers.delete(member.name); } + + // TODO: Iterate through the remaining omittedClassFieldMembers. + if (members) { + for(let omittedClassFieldMemberKey of omittedClassFieldMembers.keys()) { + let member = members.get(omittedClassFieldMemberKey); + + if(member) { + // TODO: Check if it is a number type, set it to zero + + // TODO: Check if it is a boolean, default to false + + // TODO: Check if it can be null, + } + + // Otherwise, error + // torch2424 + this.error( + DiagnosticCode.Object_literals_must_have_all_class_member_fields_explicitly_defined, + expression.range, classReference.toString() + ); + return module.unreachable(); + } + } + this.currentType = classReference.type.nonNullableType; if (hasErrors) return module.unreachable(); diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index 45988f1d65..7243247569 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -40,6 +40,7 @@ export enum DiagnosticCode { _0_is_not_a_valid_operator = 224, Expression_cannot_be_represented_by_a_type = 225, Expression_resolves_to_unusual_type_0 = 226, + Object_literals_must_have_all_class_member_fields_explicitly_defined = 227, Type_0_is_cyclic_Module_will_include_deferred_garbage_collection = 900, Importing_the_table_disables_some_indirect_call_optimizations = 901, Exporting_the_table_disables_some_indirect_call_optimizations = 902, @@ -194,6 +195,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 224: return "'{0}' is not a valid operator."; case 225: return "Expression cannot be represented by a type."; case 226: return "Expression resolves to unusual type '{0}'."; + case 227: return "Object literals must have all class member fields explicitly defined"; case 900: return "Type '{0}' is cyclic. Module will include deferred garbage collection."; case 901: return "Importing the table disables some indirect call optimizations."; case 902: return "Exporting the table disables some indirect call optimizations."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index 94ef96a447..31909d4771 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -33,6 +33,7 @@ "'{0}' is not a valid operator.": 224, "Expression cannot be represented by a type.": 225, "Expression resolves to unusual type '{0}'.": 226, + "Object literals must have all class member fields explicitly defined": 227, "Type '{0}' is cyclic. Module will include deferred garbage collection.": 900, "Importing the table disables some indirect call optimizations.": 901, diff --git a/tests/compiler/std/object-literal-omitted.json b/tests/compiler/std/object-literal-omitted.json new file mode 100644 index 0000000000..b1da366ff4 --- /dev/null +++ b/tests/compiler/std/object-literal-omitted.json @@ -0,0 +1,5 @@ +{ + "asc_flags": [ + "--runtime none" + ] +} \ No newline at end of file diff --git a/tests/compiler/std/object-literal-omitted.optimized.wat b/tests/compiler/std/object-literal-omitted.optimized.wat new file mode 100644 index 0000000000..23da3862e2 --- /dev/null +++ b/tests/compiler/std/object-literal-omitted.optimized.wat @@ -0,0 +1,4 @@ +(module + (memory $0 0) + (export "memory" (memory $0)) +) diff --git a/tests/compiler/std/object-literal-omitted.ts b/tests/compiler/std/object-literal-omitted.ts new file mode 100644 index 0000000000..385707aa27 --- /dev/null +++ b/tests/compiler/std/object-literal-omitted.ts @@ -0,0 +1,31 @@ +// Test omitted fields +class OmittedFoo { + bar: string = 'bar'; + baz: string | null = 'baz'; + quux: string | null; + quuz: string | null; + corge: string | null; + grault: string | null; + garply: string | null; + waldo: string | null; + fred: i32; + qux: i32 = -1; +} + +function testOmit(foo: OmittedFoo): void { + assert(foo.bar == 'bar'); + assert(foo.baz == 'baz'); + assert(changetype(foo.baz) == 0); + assert(changetype(foo.quux) == 0); + assert(changetype(foo.quuz) == 0); + assert(changetype(foo.corge) == 0); + assert(changetype(foo.grault) == 0); + assert(changetype(foo.garply) == 0); + assert(changetype(foo.waldo) == 0); + assert(foo.fred == 0); + assert(foo.qux == -1); +} + +// TODO: Test this one omitted implementation is complete +// testOmit({}); + diff --git a/tests/compiler/std/object-literal-omitted.untouched.wat b/tests/compiler/std/object-literal-omitted.untouched.wat new file mode 100644 index 0000000000..bffe105a3d --- /dev/null +++ b/tests/compiler/std/object-literal-omitted.untouched.wat @@ -0,0 +1,5 @@ +(module + (memory $0 0) + (table $0 1 funcref) + (export "memory" (memory $0)) +) diff --git a/tests/compiler/std/object-literal.ts b/tests/compiler/std/object-literal.ts index 26d304353b..72593ef552 100644 --- a/tests/compiler/std/object-literal.ts +++ b/tests/compiler/std/object-literal.ts @@ -28,33 +28,3 @@ bar2({ bar: 2 }); ({ bar: 3 }).test(); - -// Test omitted fields -class OmittedFoo { - bar: string | null; - baz: string | null; - quux: string | null; - quuz: string | null; - corge: string | null; - grault: string | null; - garply: string | null; - // waldo: string | null = 'Yo'; - // fred: i32; - // qux: i32 = -1; -} - -function testOmit(foo: OmittedFoo): void { - assert(changetype(foo.baz) == 0); - assert(changetype(foo.baz) == 0); - assert(changetype(foo.quux) == 0); - assert(changetype(foo.quuz) == 0); - assert(changetype(foo.corge) == 0); - assert(changetype(foo.grault) == 0); - assert(changetype(foo.garply) == 0); - // assert(foo.waldo == 'Yo'); - // assert(foo.fred == 0); - // assert(foo.qux == -1); -} - -testOmit({}); - From dd0a994df5be88a08eb40ad9763449521e9f371b Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Thu, 16 Apr 2020 17:38:32 -0700 Subject: [PATCH 05/10] Finished up support for basic type omission --- src/compiler.ts | 100 +- src/diagnosticMessages.generated.ts | 4 +- src/diagnosticMessages.json | 2 +- .../compiler/std/object-literal-omitted.json | 4 +- .../std/object-literal-omitted.optimized.wat | 1585 +++++++++++- tests/compiler/std/object-literal-omitted.ts | 57 +- .../std/object-literal-omitted.untouched.wat | 2136 ++++++++++++++++- 7 files changed, 3859 insertions(+), 29 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index e308cce4f0..5a7c9580ff 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8682,7 +8682,7 @@ export class Compiler extends DiagnosticEmitter { var values = expression.values; var members = classReference.members; var hasErrors = false; - var exprs = new Array(numNames + 2); + var exprs = new Array(); var flow = this.currentFlow; var tempLocal = isManaged ? flow.getAutoreleaseLocal(classReference.type) @@ -8700,6 +8700,17 @@ export class Compiler extends DiagnosticEmitter { } } + // Define a function to add a new expression on our Object literal + let storeObjectLiteralField = (fieldInstance: Field, fieldType: Type, valueExpr: ExpressionRef) => { + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + valueExpr, + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); + }; + // Iterate through the members definted in our expression for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; @@ -8713,54 +8724,103 @@ export class Compiler extends DiagnosticEmitter { } let fieldInstance = member; let fieldType = fieldInstance.type; - exprs[i + 1] = this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.compileExpression(values[i], fieldInstance.type, Constraints.CONV_IMPLICIT), - fieldType.toNativeType(), - fieldInstance.memoryOffset + storeObjectLiteralField( + fieldInstance, + fieldType, + this.compileExpression(values[i], fieldInstance.type, Constraints.CONV_IMPLICIT) ); // This member is no longer omitted, so delete from our omitted fields omittedClassFieldMembers.delete(member.name); } + this.currentType = classReference.type.nonNullableType; + if (hasErrors) return module.unreachable(); - // TODO: Iterate through the remaining omittedClassFieldMembers. + // Iterate through the remaining omittedClassFieldMembers. if (members) { for(let omittedClassFieldMemberKey of omittedClassFieldMembers.keys()) { - let member = members.get(omittedClassFieldMemberKey); + let member = members.get(omittedClassFieldMemberKey); if(member) { - // TODO: Check if it is a number type, set it to zero - // TODO: Check if it is a boolean, default to false + let fieldInstance = member; + let fieldType = fieldInstance.type; + + switch(fieldType.kind) { + // i32 Types + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.I32: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.U32: + case TypeKind.USIZE: + case TypeKind.ISIZE: + case TypeKind.BOOL: { + storeObjectLiteralField( + fieldInstance, + fieldType, + this.module.i32(0) + ); + continue; + } + + // i64 Types + case TypeKind.I64: + case TypeKind.U64: { + storeObjectLiteralField( + fieldInstance, + fieldType, + this.module.i64(0) + ); + continue; + } - // TODO: Check if it can be null, + // f32 Types + case TypeKind.F32: { + storeObjectLiteralField( + fieldInstance, + fieldType, + this.module.f32(0) + ); + continue; + } + + // f64 Types + case TypeKind.F64: { + storeObjectLiteralField( + fieldInstance, + fieldType, + this.module.f64(0) + ); + continue; + } + // TODO: Check if it is a class, with a default value (constructor with no params). + // TODO: Check if it can be null, and set to null + default: {} + } } // Otherwise, error - // torch2424 this.error( - DiagnosticCode.Object_literals_must_have_all_class_member_fields_explicitly_defined, + DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, expression.range, classReference.toString() ); - return module.unreachable(); + hasErrors = true; } } - - this.currentType = classReference.type.nonNullableType; if (hasErrors) return module.unreachable(); // allocate a new instance first and assign 'this' to the temp. local - exprs[0] = module.local_set( + exprs.unshift(module.local_set( tempLocal.index, isManaged ? this.makeRetain(this.makeAllocation(classReference)) : this.makeAllocation(classReference) - ); + )); // once all field values have been set, return 'this' - exprs[exprs.length - 1] = module.local_get(tempLocal.index, this.options.nativeSizeType); + exprs.push(module.local_get(tempLocal.index, this.options.nativeSizeType)); if (!isManaged) flow.freeTempLocal(tempLocal); this.currentType = classReference.type; diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index 7243247569..7da184da1b 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -40,7 +40,7 @@ export enum DiagnosticCode { _0_is_not_a_valid_operator = 224, Expression_cannot_be_represented_by_a_type = 225, Expression_resolves_to_unusual_type_0 = 226, - Object_literals_must_have_all_class_member_fields_explicitly_defined = 227, + Object_literal_is_missing_class_member_fields_that_must_be_defined = 227, Type_0_is_cyclic_Module_will_include_deferred_garbage_collection = 900, Importing_the_table_disables_some_indirect_call_optimizations = 901, Exporting_the_table_disables_some_indirect_call_optimizations = 902, @@ -195,7 +195,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 224: return "'{0}' is not a valid operator."; case 225: return "Expression cannot be represented by a type."; case 226: return "Expression resolves to unusual type '{0}'."; - case 227: return "Object literals must have all class member fields explicitly defined"; + case 227: return "Object literal is missing class member fields that must be defined"; case 900: return "Type '{0}' is cyclic. Module will include deferred garbage collection."; case 901: return "Importing the table disables some indirect call optimizations."; case 902: return "Exporting the table disables some indirect call optimizations."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index 31909d4771..ee78efe8b2 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -33,7 +33,7 @@ "'{0}' is not a valid operator.": 224, "Expression cannot be represented by a type.": 225, "Expression resolves to unusual type '{0}'.": 226, - "Object literals must have all class member fields explicitly defined": 227, + "Object literal is missing class member fields that must be defined": 227, "Type '{0}' is cyclic. Module will include deferred garbage collection.": 900, "Importing the table disables some indirect call optimizations.": 901, diff --git a/tests/compiler/std/object-literal-omitted.json b/tests/compiler/std/object-literal-omitted.json index b1da366ff4..a499d3adfc 100644 --- a/tests/compiler/std/object-literal-omitted.json +++ b/tests/compiler/std/object-literal-omitted.json @@ -1,5 +1,5 @@ { "asc_flags": [ - "--runtime none" + "--runtime full" ] -} \ No newline at end of file +} diff --git a/tests/compiler/std/object-literal-omitted.optimized.wat b/tests/compiler/std/object-literal-omitted.optimized.wat index 23da3862e2..a70a39a38b 100644 --- a/tests/compiler/std/object-literal-omitted.optimized.wat +++ b/tests/compiler/std/object-literal-omitted.optimized.wat @@ -1,4 +1,1587 @@ (module - (memory $0 0) + (type $i32_=>_none (func (param i32))) + (type $none_=>_none (func)) + (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 1024) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s") + (data (i32.const 1072) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00a\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e") + (data (i32.const 1136) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00p\00u\00r\00e\00.\00t\00s") + (data (i32.const 1184) ":\00\00\00\01\00\00\00\01\00\00\00:\00\00\00s\00t\00d\00/\00o\00b\00j\00e\00c\00t\00-\00l\00i\00t\00e\00r\00a\00l\00-\00o\00m\00i\00t\00t\00e\00d\00.\00t\00s") + (data (i32.const 1264) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00t\00e\00s\00t") + (data (i32.const 1296) "\05\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 ") + (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) + (global $~lib/rt/tlsf/collectLock (mut i32) (i32.const 0)) + (global $~lib/rt/__rtti_base i32 (i32.const 1296)) (export "memory" (memory $0)) + (export "__alloc" (func $~lib/rt/tlsf/__alloc)) + (export "__retain" (func $~lib/rt/pure/__retain)) + (export "__release" (func $~lib/rt/pure/__release)) + (export "__collect" (func $~lib/rt/pure/__collect)) + (export "__rtti_base" (global $~lib/rt/__rtti_base)) + (start $~start) + (func $~lib/rt/tlsf/removeBlock (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $1 + i32.load + local.tee $2 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 277 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $2 + i32.const -4 + i32.and + local.tee $2 + i32.const 16 + i32.ge_u + if (result i32) + local.get $2 + i32.const 1073741808 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 279 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $2 + i32.const 256 + i32.lt_u + if + local.get $2 + i32.const 4 + i32.shr_u + local.set $2 + else + local.get $2 + i32.const 31 + local.get $2 + i32.clz + i32.sub + local.tee $4 + i32.const 4 + i32.sub + i32.shr_u + i32.const 16 + i32.xor + local.set $2 + local.get $4 + i32.const 7 + i32.sub + local.set $4 + end + local.get $2 + i32.const 16 + i32.lt_u + i32.const 0 + local.get $4 + i32.const 23 + i32.lt_u + select + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 292 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.load offset=20 + local.set $3 + local.get $1 + i32.load offset=16 + local.tee $5 + if + local.get $5 + local.get $3 + i32.store offset=20 + end + local.get $3 + if + local.get $3 + local.get $5 + i32.store offset=16 + end + local.get $1 + local.get $0 + local.get $2 + local.get $4 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + i32.eq + if + local.get $0 + local.get $2 + local.get $4 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + local.get $3 + i32.store offset=96 + local.get $3 + i32.eqz + if + local.get $0 + local.get $4 + i32.const 2 + i32.shl + i32.add + local.tee $3 + i32.load offset=4 + i32.const 1 + local.get $2 + i32.shl + i32.const -1 + i32.xor + i32.and + local.set $1 + local.get $3 + local.get $1 + i32.store offset=4 + local.get $1 + i32.eqz + if + local.get $0 + local.get $0 + i32.load + i32.const 1 + local.get $4 + i32.shl + i32.const -1 + i32.xor + i32.and + i32.store + end + end + end + ) + (func $~lib/rt/tlsf/insertBlock (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + local.get $1 + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 205 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.load + local.tee $3 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 207 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 16 + i32.add + local.get $1 + i32.load + i32.const -4 + i32.and + i32.add + local.tee $4 + i32.load + local.tee $5 + i32.const 1 + i32.and + if + local.get $3 + i32.const -4 + i32.and + i32.const 16 + i32.add + local.get $5 + i32.const -4 + i32.and + i32.add + local.tee $2 + i32.const 1073741808 + i32.lt_u + if + local.get $0 + local.get $4 + call $~lib/rt/tlsf/removeBlock + local.get $1 + local.get $2 + local.get $3 + i32.const 3 + i32.and + i32.or + local.tee $3 + i32.store + local.get $1 + i32.const 16 + i32.add + local.get $1 + i32.load + i32.const -4 + i32.and + i32.add + local.tee $4 + i32.load + local.set $5 + end + end + local.get $3 + i32.const 2 + i32.and + if + local.get $1 + i32.const 4 + i32.sub + i32.load + local.tee $2 + i32.load + local.tee $7 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 228 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $7 + i32.const -4 + i32.and + i32.const 16 + i32.add + local.get $3 + i32.const -4 + i32.and + i32.add + local.tee $8 + i32.const 1073741808 + i32.lt_u + if + local.get $0 + local.get $2 + call $~lib/rt/tlsf/removeBlock + local.get $2 + local.get $8 + local.get $7 + i32.const 3 + i32.and + i32.or + local.tee $3 + i32.store + local.get $2 + local.set $1 + end + end + local.get $4 + local.get $5 + i32.const 2 + i32.or + i32.store + local.get $3 + i32.const -4 + i32.and + local.tee $2 + i32.const 16 + i32.ge_u + if (result i32) + local.get $2 + i32.const 1073741808 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 243 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $2 + local.get $1 + i32.const 16 + i32.add + i32.add + local.get $4 + i32.ne + if + i32.const 0 + i32.const 1040 + i32.const 244 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $4 + i32.const 4 + i32.sub + local.get $1 + i32.store + local.get $2 + i32.const 256 + i32.lt_u + if + local.get $2 + i32.const 4 + i32.shr_u + local.set $2 + else + local.get $2 + i32.const 31 + local.get $2 + i32.clz + i32.sub + local.tee $3 + i32.const 4 + i32.sub + i32.shr_u + i32.const 16 + i32.xor + local.set $2 + local.get $3 + i32.const 7 + i32.sub + local.set $6 + end + local.get $2 + i32.const 16 + i32.lt_u + i32.const 0 + local.get $6 + i32.const 23 + i32.lt_u + select + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 260 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $2 + local.get $6 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + local.set $3 + local.get $1 + i32.const 0 + i32.store offset=16 + local.get $1 + local.get $3 + i32.store offset=20 + local.get $3 + if + local.get $3 + local.get $1 + i32.store offset=16 + end + local.get $0 + local.get $2 + local.get $6 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + local.get $1 + i32.store offset=96 + local.get $0 + local.get $0 + i32.load + i32.const 1 + local.get $6 + i32.shl + i32.or + i32.store + local.get $0 + local.get $6 + i32.const 2 + i32.shl + i32.add + local.tee $0 + local.get $0 + i32.load offset=4 + i32.const 1 + local.get $2 + i32.shl + i32.or + i32.store offset=4 + ) + (func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + local.get $2 + i32.const 15 + i32.and + i32.eqz + i32.const 0 + local.get $1 + i32.const 15 + i32.and + i32.eqz + i32.const 0 + local.get $1 + local.get $2 + i32.le_u + select + select + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 386 + i32.const 5 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=1568 + local.tee $3 + if + local.get $1 + local.get $3 + i32.const 16 + i32.add + i32.lt_u + if + i32.const 0 + i32.const 1040 + i32.const 396 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $3 + local.get $1 + i32.const 16 + i32.sub + i32.eq + if + local.get $3 + i32.load + local.set $4 + local.get $1 + i32.const 16 + i32.sub + local.set $1 + end + else + local.get $1 + local.get $0 + i32.const 1572 + i32.add + i32.lt_u + if + i32.const 0 + i32.const 1040 + i32.const 408 + i32.const 5 + call $~lib/builtins/abort + unreachable + end + end + local.get $2 + local.get $1 + i32.sub + local.tee $2 + i32.const 48 + i32.lt_u + if + return + end + local.get $1 + local.get $4 + i32.const 2 + i32.and + local.get $2 + i32.const 32 + i32.sub + i32.const 1 + i32.or + i32.or + i32.store + local.get $1 + i32.const 0 + i32.store offset=16 + local.get $1 + i32.const 0 + i32.store offset=20 + local.get $1 + local.get $2 + i32.add + i32.const 16 + i32.sub + local.tee $2 + i32.const 2 + i32.store + local.get $0 + local.get $2 + i32.store offset=1568 + local.get $0 + local.get $1 + call $~lib/rt/tlsf/insertBlock + ) + (func $~lib/rt/tlsf/maybeInitialize (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) + global.get $~lib/rt/tlsf/ROOT + local.tee $0 + i32.eqz + if + i32.const 1 + memory.size + local.tee $0 + i32.gt_s + if (result i32) + i32.const 1 + local.get $0 + i32.sub + memory.grow + i32.const 0 + i32.lt_s + else + i32.const 0 + end + if + unreachable + end + i32.const 1344 + local.tee $0 + i32.const 0 + i32.store + i32.const 2912 + i32.const 0 + i32.store + loop $for-loop|0 + local.get $1 + i32.const 23 + i32.lt_u + if + local.get $1 + i32.const 2 + i32.shl + i32.const 1344 + i32.add + i32.const 0 + i32.store offset=4 + i32.const 0 + local.set $2 + loop $for-loop|1 + local.get $2 + i32.const 16 + i32.lt_u + if + local.get $2 + local.get $1 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.const 1344 + i32.add + i32.const 0 + i32.store offset=96 + local.get $2 + i32.const 1 + i32.add + local.set $2 + br $for-loop|1 + end + end + local.get $1 + i32.const 1 + i32.add + local.set $1 + br $for-loop|0 + end + end + i32.const 1344 + i32.const 2928 + memory.size + i32.const 16 + i32.shl + call $~lib/rt/tlsf/addMemory + i32.const 1344 + global.set $~lib/rt/tlsf/ROOT + end + local.get $0 + ) + (func $~lib/rt/tlsf/searchBlock (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + local.get $1 + i32.const 256 + i32.lt_u + if + local.get $1 + i32.const 4 + i32.shr_u + local.set $1 + else + local.get $1 + i32.const 536870904 + i32.lt_u + if + local.get $1 + i32.const 1 + i32.const 27 + local.get $1 + i32.clz + i32.sub + i32.shl + i32.add + i32.const 1 + i32.sub + local.set $1 + end + local.get $1 + i32.const 31 + local.get $1 + i32.clz + i32.sub + local.tee $2 + i32.const 4 + i32.sub + i32.shr_u + i32.const 16 + i32.xor + local.set $1 + local.get $2 + i32.const 7 + i32.sub + local.set $2 + end + local.get $1 + i32.const 16 + i32.lt_u + i32.const 0 + local.get $2 + i32.const 23 + i32.lt_u + select + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 338 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $2 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + i32.const -1 + local.get $1 + i32.shl + i32.and + local.tee $1 + if (result i32) + local.get $0 + local.get $1 + i32.ctz + local.get $2 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + else + local.get $0 + i32.load + i32.const -1 + local.get $2 + i32.const 1 + i32.add + i32.shl + i32.and + local.tee $1 + if (result i32) + local.get $0 + local.get $1 + i32.ctz + local.tee $1 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + local.tee $2 + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 351 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $2 + i32.ctz + local.get $1 + i32.const 4 + i32.shl + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + else + i32.const 0 + end + end + ) + (func $~lib/rt/tlsf/prepareBlock (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + local.get $1 + i32.load + local.set $3 + local.get $2 + i32.const 15 + i32.and + if + i32.const 0 + i32.const 1040 + i32.const 365 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $3 + i32.const -4 + i32.and + local.get $2 + i32.sub + local.tee $4 + i32.const 32 + i32.ge_u + if + local.get $1 + local.get $2 + local.get $3 + i32.const 2 + i32.and + i32.or + i32.store + local.get $2 + local.get $1 + i32.const 16 + i32.add + i32.add + local.tee $1 + local.get $4 + i32.const 16 + i32.sub + i32.const 1 + i32.or + i32.store + local.get $0 + local.get $1 + call $~lib/rt/tlsf/insertBlock + else + local.get $1 + local.get $3 + i32.const -2 + i32.and + i32.store + local.get $1 + i32.const 16 + i32.add + local.tee $0 + local.get $1 + i32.load + i32.const -4 + i32.and + i32.add + local.get $0 + local.get $1 + i32.load + i32.const -4 + i32.and + i32.add + i32.load + i32.const -3 + i32.and + i32.store + end + ) + (func $~lib/rt/tlsf/allocateBlock (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + global.get $~lib/rt/tlsf/collectLock + if + i32.const 0 + i32.const 1040 + i32.const 501 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 1073741808 + i32.ge_u + if + i32.const 1088 + i32.const 1040 + i32.const 461 + i32.const 30 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 15 + i32.add + i32.const -16 + i32.and + local.tee $3 + i32.const 16 + local.get $3 + i32.const 16 + i32.gt_u + select + local.tee $4 + call $~lib/rt/tlsf/searchBlock + local.tee $3 + i32.eqz + if + i32.const 1 + global.set $~lib/rt/tlsf/collectLock + i32.const 0 + global.set $~lib/rt/tlsf/collectLock + local.get $0 + local.get $4 + call $~lib/rt/tlsf/searchBlock + local.tee $3 + i32.eqz + if + i32.const 16 + memory.size + local.tee $3 + i32.const 16 + i32.shl + i32.const 16 + i32.sub + local.get $0 + i32.load offset=1568 + i32.ne + i32.shl + local.get $4 + i32.const 1 + i32.const 27 + local.get $4 + i32.clz + i32.sub + i32.shl + i32.const 1 + i32.sub + i32.add + local.get $4 + local.get $4 + i32.const 536870904 + i32.lt_u + select + i32.add + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.set $5 + local.get $3 + local.get $5 + local.get $3 + local.get $5 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $5 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + local.get $0 + local.get $3 + i32.const 16 + i32.shl + memory.size + i32.const 16 + i32.shl + call $~lib/rt/tlsf/addMemory + local.get $0 + local.get $4 + call $~lib/rt/tlsf/searchBlock + local.tee $3 + i32.eqz + if + i32.const 0 + i32.const 1040 + i32.const 513 + i32.const 20 + call $~lib/builtins/abort + unreachable + end + end + end + local.get $3 + i32.load + i32.const -4 + i32.and + local.get $4 + i32.lt_u + if + i32.const 0 + i32.const 1040 + i32.const 521 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $3 + i32.const 0 + i32.store offset=4 + local.get $3 + local.get $2 + i32.store offset=8 + local.get $3 + local.get $1 + i32.store offset=12 + local.get $0 + local.get $3 + call $~lib/rt/tlsf/removeBlock + local.get $0 + local.get $3 + local.get $4 + call $~lib/rt/tlsf/prepareBlock + local.get $3 + ) + (func $~lib/rt/tlsf/__alloc (param $0 i32) (param $1 i32) (result i32) + call $~lib/rt/tlsf/maybeInitialize + local.get $0 + local.get $1 + call $~lib/rt/tlsf/allocateBlock + i32.const 16 + i32.add + ) + (func $~lib/rt/pure/__retain (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.const 1340 + i32.gt_u + if + local.get $0 + i32.const 16 + i32.sub + local.tee $1 + i32.load offset=4 + local.tee $2 + i32.const -268435456 + i32.and + local.get $2 + i32.const 1 + i32.add + i32.const -268435456 + i32.and + i32.ne + if + i32.const 0 + i32.const 1152 + i32.const 109 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $1 + local.get $2 + i32.const 1 + i32.add + i32.store offset=4 + local.get $1 + i32.load + i32.const 1 + i32.and + if + i32.const 0 + i32.const 1152 + i32.const 112 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + end + local.get $0 + ) + (func $~lib/rt/pure/__release (param $0 i32) + local.get $0 + i32.const 1340 + i32.gt_u + if + local.get $0 + i32.const 16 + i32.sub + call $~lib/rt/pure/decrement + end + ) + (func $std/object-literal-omitted/testOmittedTypes (param $0 i32) + local.get $0 + i32.load + if + i32.const 0 + i32.const 1200 + i32.const 19 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + if + i32.const 0 + i32.const 1200 + i32.const 20 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i64.load offset=8 + i64.eqz + i32.eqz + if + i32.const 0 + i32.const 1200 + i32.const 21 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i64.load offset=16 + i64.eqz + i32.eqz + if + i32.const 0 + i32.const 1200 + i32.const 22 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f32.load offset=24 + f32.const 0 + f32.ne + if + i32.const 0 + i32.const 1200 + i32.const 23 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f64.load offset=32 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 1200 + i32.const 24 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_s offset=40 + if + i32.const 0 + i32.const 1200 + i32.const 25 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_u offset=41 + if + i32.const 0 + i32.const 1200 + i32.const 26 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load16_s offset=42 + if + i32.const 0 + i32.const 1200 + i32.const 27 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load16_u offset=44 + if + i32.const 0 + i32.const 1200 + i32.const 28 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=48 + if + i32.const 0 + i32.const 1200 + i32.const 29 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=52 + if + i32.const 0 + i32.const 1200 + i32.const 30 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f64.load offset=56 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 1200 + i32.const 31 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_u offset=64 + if + i32.const 0 + i32.const 1200 + i32.const 32 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + ) + (func $~lib/string/String#get:length (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + i32.const 1280 + local.set $3 + local.get $0 + i32.const 7 + i32.and + i32.eqz + i32.const 0 + local.get $1 + i32.const 4 + i32.ge_u + select + if + loop $do-continue|0 + local.get $0 + i64.load + local.get $3 + i64.load + i64.eq + if + local.get $0 + i32.const 8 + i32.add + local.set $0 + local.get $3 + i32.const 8 + i32.add + local.set $3 + local.get $1 + i32.const 4 + i32.sub + local.tee $1 + i32.const 4 + i32.ge_u + br_if $do-continue|0 + end + end + end + loop $while-continue|1 + local.get $1 + local.tee $2 + i32.const 1 + i32.sub + local.set $1 + local.get $2 + if + local.get $3 + i32.load16_u + local.tee $2 + local.get $0 + i32.load16_u + local.tee $4 + i32.ne + if + local.get $4 + local.get $2 + i32.sub + return + end + local.get $0 + i32.const 2 + i32.add + local.set $0 + local.get $3 + i32.const 2 + i32.add + local.set $3 + br $while-continue|1 + end + end + i32.const 0 + ) + (func $start:std/object-literal-omitted + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + i32.const 65 + i32.const 3 + call $~lib/rt/tlsf/__alloc + call $~lib/rt/pure/__retain + local.tee $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i64.const 0 + i64.store offset=8 + local.get $0 + i64.const 0 + i64.store offset=16 + local.get $0 + f32.const 0 + f32.store offset=24 + local.get $0 + f64.const 0 + f64.store offset=32 + local.get $0 + i32.const 0 + i32.store8 offset=40 + local.get $0 + i32.const 0 + i32.store8 offset=41 + local.get $0 + i32.const 0 + i32.store16 offset=42 + local.get $0 + i32.const 0 + i32.store16 offset=44 + local.get $0 + i32.const 0 + i32.store offset=48 + local.get $0 + i32.const 0 + i32.store offset=52 + local.get $0 + f64.const 0 + f64.store offset=56 + local.get $0 + i32.const 0 + i32.store8 offset=64 + local.get $0 + call $std/object-literal-omitted/testOmittedTypes + i32.const 16 + i32.const 4 + call $~lib/rt/tlsf/__alloc + call $~lib/rt/pure/__retain + local.tee $1 + i32.const 0 + i32.store + local.get $1 + i32.const 1280 + i32.store offset=4 + local.get $1 + f64.const 0 + f64.store offset=8 + local.get $1 + i32.load + if + i32.const 0 + i32.const 1200 + i32.const 44 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + block $__inlined_func$~lib/string/String.__eq (result i32) + i32.const 1 + local.get $1 + i32.load offset=4 + local.tee $2 + i32.const 1280 + i32.eq + br_if $__inlined_func$~lib/string/String.__eq + drop + i32.const 0 + i32.const 0 + i32.const 1 + local.get $2 + select + br_if $__inlined_func$~lib/string/String.__eq + drop + i32.const 0 + local.get $2 + call $~lib/string/String#get:length + local.tee $3 + i32.const 1280 + call $~lib/string/String#get:length + i32.ne + br_if $__inlined_func$~lib/string/String.__eq + drop + local.get $2 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + end + i32.eqz + if + i32.const 0 + i32.const 1200 + i32.const 45 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $1 + f64.load offset=8 + f64.const 0 + f64.ne + if + i32.const 0 + i32.const 1200 + i32.const 46 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + ) + (func $~start + call $start:std/object-literal-omitted + ) + (func $~lib/rt/pure/__collect + nop + ) + (func $~lib/rt/pure/decrement (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=4 + local.tee $2 + i32.const 268435455 + i32.and + local.set $1 + local.get $0 + i32.load + i32.const 1 + i32.and + if + i32.const 0 + i32.const 1152 + i32.const 122 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 1 + i32.eq + if + block $__inlined_func$~lib/rt/__visit_members + block $switch$1$default + block $switch$1$case$6 + block $switch$1$case$4 + local.get $0 + i32.const 16 + i32.add + local.tee $1 + i32.const 8 + i32.sub + i32.load + br_table $__inlined_func$~lib/rt/__visit_members $__inlined_func$~lib/rt/__visit_members $switch$1$case$4 $__inlined_func$~lib/rt/__visit_members $switch$1$case$6 $switch$1$default + end + local.get $1 + i32.load + local.tee $1 + if + local.get $1 + call $~lib/rt/pure/__visit + end + br $__inlined_func$~lib/rt/__visit_members + end + local.get $1 + i32.load offset=4 + local.tee $1 + if + local.get $1 + call $~lib/rt/pure/__visit + end + br $__inlined_func$~lib/rt/__visit_members + end + unreachable + end + local.get $2 + i32.const -2147483648 + i32.and + if + i32.const 0 + i32.const 1152 + i32.const 126 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $0 + i32.load + i32.const 1 + i32.or + i32.store + global.get $~lib/rt/tlsf/ROOT + local.get $0 + call $~lib/rt/tlsf/insertBlock + else + local.get $1 + i32.const 0 + i32.le_u + if + i32.const 0 + i32.const 1152 + i32.const 136 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.sub + local.get $2 + i32.const -268435456 + i32.and + i32.or + i32.store offset=4 + end + ) + (func $~lib/rt/pure/__visit (param $0 i32) + local.get $0 + i32.const 1340 + i32.lt_u + if + return + end + local.get $0 + i32.const 16 + i32.sub + call $~lib/rt/pure/decrement + ) ) diff --git a/tests/compiler/std/object-literal-omitted.ts b/tests/compiler/std/object-literal-omitted.ts index 385707aa27..ae4bf3f714 100644 --- a/tests/compiler/std/object-literal-omitted.ts +++ b/tests/compiler/std/object-literal-omitted.ts @@ -1,3 +1,56 @@ +class OmittedTypes { + int32: i32; + uint32: u32; + int64: i64; + uint64: u64; + float32: f32; + float64: f64; + int8: i8; + uint8: u8; + int16: i16; + uint16: u16; + intsize: isize; + uintsize: usize; + alias: number; + isTrue: boolean +} + +function testOmittedTypes(omitted: OmittedTypes): void { + assert(omitted.int32 == 0); + assert(omitted.uint32 == 0); + assert(omitted.int64 == 0); + assert(omitted.uint64 == 0); + assert(omitted.float32 == 0); + assert(omitted.float64 == 0); + assert(omitted.int8 == 0); + assert(omitted.uint8 == 0); + assert(omitted.int16 == 0); + assert(omitted.uint16 == 0); + assert(omitted.intsize == 0); + assert(omitted.uintsize == 0); + assert(omitted.alias == 0); + assert(omitted.isTrue == false); +} + +testOmittedTypes({}); + +class MixedOmitted { + simpleType: i32; + complexType: string; + anotherSimpleType: f64; +} + +function testMixedOmitted(omitted: MixedOmitted): void { + assert(omitted.simpleType == 0); + assert(omitted.complexType == 'test'); + assert(omitted.anotherSimpleType == 0); +} + +testMixedOmitted({ + simpleType: 0, + complexType: 'test' +}); + // Test omitted fields class OmittedFoo { bar: string = 'bar'; @@ -12,7 +65,7 @@ class OmittedFoo { qux: i32 = -1; } -function testOmit(foo: OmittedFoo): void { +function testOmittedFoo(foo: OmittedFoo): void { assert(foo.bar == 'bar'); assert(foo.baz == 'baz'); assert(changetype(foo.baz) == 0); @@ -27,5 +80,5 @@ function testOmit(foo: OmittedFoo): void { } // TODO: Test this one omitted implementation is complete -// testOmit({}); +// testOmittedFoo({}); diff --git a/tests/compiler/std/object-literal-omitted.untouched.wat b/tests/compiler/std/object-literal-omitted.untouched.wat index bffe105a3d..d1b9c65891 100644 --- a/tests/compiler/std/object-literal-omitted.untouched.wat +++ b/tests/compiler/std/object-literal-omitted.untouched.wat @@ -1,5 +1,2139 @@ (module - (memory $0 0) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $i32_=>_none (func (param i32))) + (type $none_=>_none (func)) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) + (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (type $i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32) (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 16) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s\00") + (data (i32.const 64) "(\00\00\00\01\00\00\00\01\00\00\00(\00\00\00a\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e\00") + (data (i32.const 128) "\1e\00\00\00\01\00\00\00\01\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00p\00u\00r\00e\00.\00t\00s\00") + (data (i32.const 176) ":\00\00\00\01\00\00\00\01\00\00\00:\00\00\00s\00t\00d\00/\00o\00b\00j\00e\00c\00t\00-\00l\00i\00t\00e\00r\00a\00l\00-\00o\00m\00i\00t\00t\00e\00d\00.\00t\00s\00") + (data (i32.const 256) "\08\00\00\00\01\00\00\00\01\00\00\00\08\00\00\00t\00e\00s\00t\00") + (data (i32.const 288) "\05\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00") (table $0 1 funcref) + (global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0)) + (global $~lib/ASC_LOW_MEMORY_LIMIT i32 (i32.const 0)) + (global $~lib/rt/tlsf/collectLock (mut i32) (i32.const 0)) + (global $~lib/gc/gc.auto (mut i32) (i32.const 1)) + (global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/rt/__rtti_base i32 (i32.const 288)) + (global $~lib/heap/__heap_base i32 (i32.const 332)) (export "memory" (memory $0)) + (export "__alloc" (func $~lib/rt/tlsf/__alloc)) + (export "__retain" (func $~lib/rt/pure/__retain)) + (export "__release" (func $~lib/rt/pure/__release)) + (export "__collect" (func $~lib/rt/pure/__collect)) + (export "__rtti_base" (global $~lib/rt/__rtti_base)) + (start $~start) + (func $~lib/rt/tlsf/removeBlock (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + local.get $1 + i32.load + local.set $2 + local.get $2 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 277 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $2 + i32.const 3 + i32.const -1 + i32.xor + i32.and + local.set $3 + local.get $3 + i32.const 16 + i32.ge_u + if (result i32) + local.get $3 + i32.const 1073741808 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 279 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $3 + i32.const 256 + i32.lt_u + if + i32.const 0 + local.set $4 + local.get $3 + i32.const 4 + i32.shr_u + local.set $5 + else + i32.const 31 + local.get $3 + i32.clz + i32.sub + local.set $4 + local.get $3 + local.get $4 + i32.const 4 + i32.sub + i32.shr_u + i32.const 1 + i32.const 4 + i32.shl + i32.xor + local.set $5 + local.get $4 + i32.const 8 + i32.const 1 + i32.sub + i32.sub + local.set $4 + end + local.get $4 + i32.const 23 + i32.lt_u + if (result i32) + local.get $5 + i32.const 16 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 292 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.load offset=16 + local.set $6 + local.get $1 + i32.load offset=20 + local.set $7 + local.get $6 + if + local.get $6 + local.get $7 + i32.store offset=20 + end + local.get $7 + if + local.get $7 + local.get $6 + i32.store offset=16 + end + local.get $1 + local.get $0 + local.set $10 + local.get $4 + local.set $9 + local.get $5 + local.set $8 + local.get $10 + local.get $9 + i32.const 4 + i32.shl + local.get $8 + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + i32.eq + if + local.get $0 + local.set $11 + local.get $4 + local.set $10 + local.get $5 + local.set $9 + local.get $7 + local.set $8 + local.get $11 + local.get $10 + i32.const 4 + i32.shl + local.get $9 + i32.add + i32.const 2 + i32.shl + i32.add + local.get $8 + i32.store offset=96 + local.get $7 + i32.eqz + if + local.get $0 + local.set $9 + local.get $4 + local.set $8 + local.get $9 + local.get $8 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + local.set $9 + local.get $0 + local.set $8 + local.get $4 + local.set $11 + local.get $9 + i32.const 1 + local.get $5 + i32.shl + i32.const -1 + i32.xor + i32.and + local.tee $9 + local.set $10 + local.get $8 + local.get $11 + i32.const 2 + i32.shl + i32.add + local.get $10 + i32.store offset=4 + local.get $9 + i32.eqz + if + local.get $0 + local.get $0 + i32.load + i32.const 1 + local.get $4 + i32.shl + i32.const -1 + i32.xor + i32.and + i32.store + end + end + end + ) + (func $~lib/rt/tlsf/insertBlock (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) + (local $13 i32) + local.get $1 + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 205 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.load + local.set $2 + local.get $2 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 207 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + local.set $3 + local.get $3 + i32.const 16 + i32.add + local.get $3 + i32.load + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + local.set $4 + local.get $4 + i32.load + local.set $5 + local.get $5 + i32.const 1 + i32.and + if + local.get $2 + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.add + local.get $5 + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + local.set $3 + local.get $3 + i32.const 1073741808 + i32.lt_u + if + local.get $0 + local.get $4 + call $~lib/rt/tlsf/removeBlock + local.get $1 + local.get $2 + i32.const 3 + i32.and + local.get $3 + i32.or + local.tee $2 + i32.store + local.get $1 + local.set $6 + local.get $6 + i32.const 16 + i32.add + local.get $6 + i32.load + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + local.set $4 + local.get $4 + i32.load + local.set $5 + end + end + local.get $2 + i32.const 2 + i32.and + if + local.get $1 + local.set $6 + local.get $6 + i32.const 4 + i32.sub + i32.load + local.set $6 + local.get $6 + i32.load + local.set $3 + local.get $3 + i32.const 1 + i32.and + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 228 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $3 + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.add + local.get $2 + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + local.set $7 + local.get $7 + i32.const 1073741808 + i32.lt_u + if + local.get $0 + local.get $6 + call $~lib/rt/tlsf/removeBlock + local.get $6 + local.get $3 + i32.const 3 + i32.and + local.get $7 + i32.or + local.tee $2 + i32.store + local.get $6 + local.set $1 + end + end + local.get $4 + local.get $5 + i32.const 2 + i32.or + i32.store + local.get $2 + i32.const 3 + i32.const -1 + i32.xor + i32.and + local.set $8 + local.get $8 + i32.const 16 + i32.ge_u + if (result i32) + local.get $8 + i32.const 1073741808 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 243 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 16 + i32.add + local.get $8 + i32.add + local.get $4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 244 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $4 + i32.const 4 + i32.sub + local.get $1 + i32.store + local.get $8 + i32.const 256 + i32.lt_u + if + i32.const 0 + local.set $9 + local.get $8 + i32.const 4 + i32.shr_u + local.set $10 + else + i32.const 31 + local.get $8 + i32.clz + i32.sub + local.set $9 + local.get $8 + local.get $9 + i32.const 4 + i32.sub + i32.shr_u + i32.const 1 + i32.const 4 + i32.shl + i32.xor + local.set $10 + local.get $9 + i32.const 8 + i32.const 1 + i32.sub + i32.sub + local.set $9 + end + local.get $9 + i32.const 23 + i32.lt_u + if (result i32) + local.get $10 + i32.const 16 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 260 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.set $7 + local.get $9 + local.set $3 + local.get $10 + local.set $6 + local.get $7 + local.get $3 + i32.const 4 + i32.shl + local.get $6 + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + local.set $11 + local.get $1 + i32.const 0 + i32.store offset=16 + local.get $1 + local.get $11 + i32.store offset=20 + local.get $11 + if + local.get $11 + local.get $1 + i32.store offset=16 + end + local.get $0 + local.set $12 + local.get $9 + local.set $7 + local.get $10 + local.set $3 + local.get $1 + local.set $6 + local.get $12 + local.get $7 + i32.const 4 + i32.shl + local.get $3 + i32.add + i32.const 2 + i32.shl + i32.add + local.get $6 + i32.store offset=96 + local.get $0 + local.get $0 + i32.load + i32.const 1 + local.get $9 + i32.shl + i32.or + i32.store + local.get $0 + local.set $13 + local.get $9 + local.set $12 + local.get $0 + local.set $3 + local.get $9 + local.set $6 + local.get $3 + local.get $6 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + i32.const 1 + local.get $10 + i32.shl + i32.or + local.set $7 + local.get $13 + local.get $12 + i32.const 2 + i32.shl + i32.add + local.get $7 + i32.store offset=4 + ) + (func $~lib/rt/tlsf/addMemory (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $1 + local.get $2 + i32.le_u + if (result i32) + local.get $1 + i32.const 15 + i32.and + i32.eqz + else + i32.const 0 + end + if (result i32) + local.get $2 + i32.const 15 + i32.and + i32.eqz + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 386 + i32.const 5 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.set $3 + local.get $3 + i32.load offset=1568 + local.set $4 + i32.const 0 + local.set $5 + local.get $4 + if + local.get $1 + local.get $4 + i32.const 16 + i32.add + i32.ge_u + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 396 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $1 + i32.const 16 + i32.sub + local.get $4 + i32.eq + if + local.get $1 + i32.const 16 + i32.sub + local.set $1 + local.get $4 + i32.load + local.set $5 + else + nop + end + else + local.get $1 + local.get $0 + i32.const 1572 + i32.add + i32.ge_u + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 408 + i32.const 5 + call $~lib/builtins/abort + unreachable + end + end + local.get $2 + local.get $1 + i32.sub + local.set $6 + local.get $6 + i32.const 48 + i32.lt_u + if + i32.const 0 + return + end + local.get $6 + i32.const 16 + i32.const 1 + i32.shl + i32.sub + local.set $7 + local.get $1 + local.set $8 + local.get $8 + local.get $7 + i32.const 1 + i32.or + local.get $5 + i32.const 2 + i32.and + i32.or + i32.store + local.get $8 + i32.const 0 + i32.store offset=16 + local.get $8 + i32.const 0 + i32.store offset=20 + local.get $1 + local.get $6 + i32.add + i32.const 16 + i32.sub + local.set $4 + local.get $4 + i32.const 0 + i32.const 2 + i32.or + i32.store + local.get $0 + local.set $9 + local.get $4 + local.set $3 + local.get $9 + local.get $3 + i32.store offset=1568 + local.get $0 + local.get $8 + call $~lib/rt/tlsf/insertBlock + i32.const 1 + ) + (func $~lib/rt/tlsf/maybeInitialize (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + global.get $~lib/rt/tlsf/ROOT + local.set $0 + local.get $0 + i32.eqz + if + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.set $1 + memory.size + local.set $2 + local.get $1 + i32.const 1572 + i32.add + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $3 + local.get $2 + i32.gt_s + if (result i32) + local.get $3 + local.get $2 + i32.sub + memory.grow + i32.const 0 + i32.lt_s + else + i32.const 0 + end + if + unreachable + end + local.get $1 + local.set $0 + local.get $0 + i32.const 0 + i32.store + local.get $0 + local.set $5 + i32.const 0 + local.set $4 + local.get $5 + local.get $4 + i32.store offset=1568 + i32.const 0 + local.set $5 + loop $for-loop|0 + local.get $5 + i32.const 23 + i32.lt_u + local.set $4 + local.get $4 + if + local.get $0 + local.set $8 + local.get $5 + local.set $7 + i32.const 0 + local.set $6 + local.get $8 + local.get $7 + i32.const 2 + i32.shl + i32.add + local.get $6 + i32.store offset=4 + i32.const 0 + local.set $8 + loop $for-loop|1 + local.get $8 + i32.const 16 + i32.lt_u + local.set $7 + local.get $7 + if + local.get $0 + local.set $11 + local.get $5 + local.set $10 + local.get $8 + local.set $9 + i32.const 0 + local.set $6 + local.get $11 + local.get $10 + i32.const 4 + i32.shl + local.get $9 + i32.add + i32.const 2 + i32.shl + i32.add + local.get $6 + i32.store offset=96 + local.get $8 + i32.const 1 + i32.add + local.set $8 + br $for-loop|1 + end + end + local.get $5 + i32.const 1 + i32.add + local.set $5 + br $for-loop|0 + end + end + local.get $1 + i32.const 1572 + i32.add + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.set $5 + local.get $0 + local.get $5 + memory.size + i32.const 16 + i32.shl + call $~lib/rt/tlsf/addMemory + drop + local.get $0 + global.set $~lib/rt/tlsf/ROOT + end + local.get $0 + ) + (func $~lib/rt/tlsf/prepareSize (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.const 1073741808 + i32.ge_u + if + i32.const 80 + i32.const 32 + i32.const 461 + i32.const 30 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $1 + i32.const 16 + local.tee $2 + local.get $1 + local.get $2 + i32.gt_u + select + ) + (func $~lib/rt/tlsf/searchBlock (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + local.get $1 + i32.const 256 + i32.lt_u + if + i32.const 0 + local.set $2 + local.get $1 + i32.const 4 + i32.shr_u + local.set $3 + else + local.get $1 + i32.const 536870904 + i32.lt_u + if (result i32) + local.get $1 + i32.const 1 + i32.const 27 + local.get $1 + i32.clz + i32.sub + i32.shl + i32.add + i32.const 1 + i32.sub + else + local.get $1 + end + local.set $4 + i32.const 31 + local.get $4 + i32.clz + i32.sub + local.set $2 + local.get $4 + local.get $2 + i32.const 4 + i32.sub + i32.shr_u + i32.const 1 + i32.const 4 + i32.shl + i32.xor + local.set $3 + local.get $2 + i32.const 8 + i32.const 1 + i32.sub + i32.sub + local.set $2 + end + local.get $2 + i32.const 23 + i32.lt_u + if (result i32) + local.get $3 + i32.const 16 + i32.lt_u + else + i32.const 0 + end + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 338 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.set $5 + local.get $2 + local.set $4 + local.get $5 + local.get $4 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + i32.const 0 + i32.const -1 + i32.xor + local.get $3 + i32.shl + i32.and + local.set $6 + i32.const 0 + local.set $7 + local.get $6 + i32.eqz + if + local.get $0 + i32.load + i32.const 0 + i32.const -1 + i32.xor + local.get $2 + i32.const 1 + i32.add + i32.shl + i32.and + local.set $5 + local.get $5 + i32.eqz + if + i32.const 0 + local.set $7 + else + local.get $5 + i32.ctz + local.set $2 + local.get $0 + local.set $8 + local.get $2 + local.set $4 + local.get $8 + local.get $4 + i32.const 2 + i32.shl + i32.add + i32.load offset=4 + local.set $6 + local.get $6 + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 351 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.set $9 + local.get $2 + local.set $8 + local.get $6 + i32.ctz + local.set $4 + local.get $9 + local.get $8 + i32.const 4 + i32.shl + local.get $4 + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + local.set $7 + end + else + local.get $0 + local.set $9 + local.get $2 + local.set $8 + local.get $6 + i32.ctz + local.set $4 + local.get $9 + local.get $8 + i32.const 4 + i32.shl + local.get $4 + i32.add + i32.const 2 + i32.shl + i32.add + i32.load offset=96 + local.set $7 + end + local.get $7 + ) + (func $~lib/rt/tlsf/growMemory (param $0 i32) (param $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + local.get $1 + i32.const 536870904 + i32.lt_u + if + local.get $1 + i32.const 1 + i32.const 27 + local.get $1 + i32.clz + i32.sub + i32.shl + i32.const 1 + i32.sub + i32.add + local.set $1 + end + memory.size + local.set $2 + local.get $1 + i32.const 16 + local.get $2 + i32.const 16 + i32.shl + i32.const 16 + i32.sub + local.get $0 + local.set $3 + local.get $3 + i32.load offset=1568 + i32.ne + i32.shl + i32.add + local.set $1 + local.get $1 + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $4 + local.get $2 + local.tee $3 + local.get $4 + local.tee $5 + local.get $3 + local.get $5 + i32.gt_s + select + local.set $6 + local.get $6 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + memory.size + local.set $7 + local.get $0 + local.get $2 + i32.const 16 + i32.shl + local.get $7 + i32.const 16 + i32.shl + call $~lib/rt/tlsf/addMemory + drop + ) + (func $~lib/rt/tlsf/prepareBlock (param $0 i32) (param $1 i32) (param $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + local.get $1 + i32.load + local.set $3 + local.get $2 + i32.const 15 + i32.and + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 365 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $3 + i32.const 3 + i32.const -1 + i32.xor + i32.and + local.get $2 + i32.sub + local.set $4 + local.get $4 + i32.const 32 + i32.ge_u + if + local.get $1 + local.get $2 + local.get $3 + i32.const 2 + i32.and + i32.or + i32.store + local.get $1 + i32.const 16 + i32.add + local.get $2 + i32.add + local.set $5 + local.get $5 + local.get $4 + i32.const 16 + i32.sub + i32.const 1 + i32.or + i32.store + local.get $0 + local.get $5 + call $~lib/rt/tlsf/insertBlock + else + local.get $1 + local.get $3 + i32.const 1 + i32.const -1 + i32.xor + i32.and + i32.store + local.get $1 + local.set $5 + local.get $5 + i32.const 16 + i32.add + local.get $5 + i32.load + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + local.get $1 + local.set $5 + local.get $5 + i32.const 16 + i32.add + local.get $5 + i32.load + i32.const 3 + i32.const -1 + i32.xor + i32.and + i32.add + i32.load + i32.const 2 + i32.const -1 + i32.xor + i32.and + i32.store + end + ) + (func $~lib/rt/tlsf/allocateBlock (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (local $3 i32) + (local $4 i32) + global.get $~lib/rt/tlsf/collectLock + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 501 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $1 + call $~lib/rt/tlsf/prepareSize + local.set $3 + local.get $0 + local.get $3 + call $~lib/rt/tlsf/searchBlock + local.set $4 + local.get $4 + i32.eqz + if + global.get $~lib/gc/gc.auto + if + i32.const 1 + global.set $~lib/rt/tlsf/collectLock + call $~lib/rt/pure/__collect + i32.const 0 + global.set $~lib/rt/tlsf/collectLock + local.get $0 + local.get $3 + call $~lib/rt/tlsf/searchBlock + local.set $4 + local.get $4 + i32.eqz + if + local.get $0 + local.get $3 + call $~lib/rt/tlsf/growMemory + local.get $0 + local.get $3 + call $~lib/rt/tlsf/searchBlock + local.set $4 + local.get $4 + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 513 + i32.const 20 + call $~lib/builtins/abort + unreachable + end + end + else + local.get $0 + local.get $3 + call $~lib/rt/tlsf/growMemory + local.get $0 + local.get $3 + call $~lib/rt/tlsf/searchBlock + local.set $4 + local.get $4 + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 518 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + end + end + local.get $4 + i32.load + i32.const -4 + i32.and + local.get $3 + i32.ge_u + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 521 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $4 + i32.const 0 + i32.store offset=4 + local.get $4 + local.get $2 + i32.store offset=8 + local.get $4 + local.get $1 + i32.store offset=12 + local.get $0 + local.get $4 + call $~lib/rt/tlsf/removeBlock + local.get $0 + local.get $4 + local.get $3 + call $~lib/rt/tlsf/prepareBlock + local.get $4 + ) + (func $~lib/rt/tlsf/__alloc (param $0 i32) (param $1 i32) (result i32) + call $~lib/rt/tlsf/maybeInitialize + local.get $0 + local.get $1 + call $~lib/rt/tlsf/allocateBlock + i32.const 16 + i32.add + ) + (func $~lib/rt/pure/increment (param $0 i32) + (local $1 i32) + local.get $0 + i32.load offset=4 + local.set $1 + local.get $1 + i32.const -268435456 + i32.and + local.get $1 + i32.const 1 + i32.add + i32.const -268435456 + i32.and + i32.eq + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 109 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 1 + i32.add + i32.store offset=4 + local.get $0 + i32.load + i32.const 1 + i32.and + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 112 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + ) + (func $~lib/rt/pure/__retain (param $0 i32) (result i32) + local.get $0 + global.get $~lib/heap/__heap_base + i32.gt_u + if + local.get $0 + i32.const 16 + i32.sub + call $~lib/rt/pure/increment + end + local.get $0 + ) + (func $~lib/rt/pure/__release (param $0 i32) + local.get $0 + global.get $~lib/heap/__heap_base + i32.gt_u + if + local.get $0 + i32.const 16 + i32.sub + call $~lib/rt/pure/decrement + end + ) + (func $std/object-literal-omitted/testOmittedTypes (param $0 i32) + local.get $0 + call $~lib/rt/pure/__retain + local.set $0 + local.get $0 + i32.load + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 19 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 20 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i64.load offset=8 + i64.const 0 + i64.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 21 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i64.load offset=16 + i64.const 0 + i64.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 22 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f32.load offset=24 + f32.const 0 + f32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 23 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f64.load offset=32 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 24 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_s offset=40 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 25 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_u offset=41 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 26 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load16_s offset=42 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 27 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load16_u offset=44 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 28 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=48 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 29 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=52 + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 30 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f64.load offset=56 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 31 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load8_u offset=64 + i32.const 0 + i32.ne + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 32 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/pure/__release + ) + (func $~lib/string/String#get:length (param $0 i32) (result i32) + local.get $0 + i32.const 16 + i32.sub + i32.load offset=12 + i32.const 1 + i32.shr_u + ) + (func $~lib/util/string/compareImpl (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) (result i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + local.get $0 + call $~lib/rt/pure/__retain + local.set $0 + local.get $2 + call $~lib/rt/pure/__retain + local.set $2 + local.get $0 + local.get $1 + i32.const 1 + i32.shl + i32.add + local.set $5 + local.get $2 + local.get $3 + i32.const 1 + i32.shl + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.ge_u + if (result i32) + local.get $5 + i32.const 7 + i32.and + local.get $6 + i32.const 7 + i32.and + i32.or + i32.eqz + else + i32.const 0 + end + if + block $do-break|0 + loop $do-continue|0 + local.get $5 + i64.load + local.get $6 + i64.load + i64.ne + if + br $do-break|0 + end + local.get $5 + i32.const 8 + i32.add + local.set $5 + local.get $6 + i32.const 8 + i32.add + local.set $6 + local.get $4 + i32.const 4 + i32.sub + local.set $4 + local.get $4 + i32.const 4 + i32.ge_u + local.set $7 + local.get $7 + br_if $do-continue|0 + end + end + end + loop $while-continue|1 + local.get $4 + local.tee $7 + i32.const 1 + i32.sub + local.set $4 + local.get $7 + local.set $7 + local.get $7 + if + local.get $5 + i32.load16_u + local.set $8 + local.get $6 + i32.load16_u + local.set $9 + local.get $8 + local.get $9 + i32.ne + if + local.get $8 + local.get $9 + i32.sub + local.set $10 + local.get $0 + call $~lib/rt/pure/__release + local.get $2 + call $~lib/rt/pure/__release + local.get $10 + return + end + local.get $5 + i32.const 2 + i32.add + local.set $5 + local.get $6 + i32.const 2 + i32.add + local.set $6 + br $while-continue|1 + end + end + i32.const 0 + local.set $7 + local.get $0 + call $~lib/rt/pure/__release + local.get $2 + call $~lib/rt/pure/__release + local.get $7 + ) + (func $~lib/string/String.__eq (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + local.get $0 + call $~lib/rt/pure/__retain + local.set $0 + local.get $1 + call $~lib/rt/pure/__retain + local.set $1 + local.get $0 + local.get $1 + i32.eq + if + i32.const 1 + local.set $2 + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + i32.eq + if (result i32) + i32.const 1 + else + local.get $1 + i32.const 0 + i32.eq + end + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + local.get $2 + return + end + local.get $0 + call $~lib/string/String#get:length + local.set $3 + local.get $3 + local.get $1 + call $~lib/string/String#get:length + i32.ne + if + i32.const 0 + local.set $2 + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + local.get $2 + return + end + local.get $0 + i32.const 0 + local.get $1 + i32.const 0 + local.get $3 + call $~lib/util/string/compareImpl + i32.eqz + local.set $2 + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + local.get $2 + ) + (func $std/object-literal-omitted/testMixedOmitted (param $0 i32) + local.get $0 + call $~lib/rt/pure/__retain + local.set $0 + local.get $0 + i32.load + i32.const 0 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 44 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.load offset=4 + i32.const 272 + call $~lib/string/String.__eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 45 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + f64.load offset=8 + f64.const 0 + f64.eq + i32.eqz + if + i32.const 0 + i32.const 192 + i32.const 46 + i32.const 3 + call $~lib/builtins/abort + unreachable + end + local.get $0 + call $~lib/rt/pure/__release + ) + (func $start:std/object-literal-omitted + (local $0 i32) + (local $1 i32) + i32.const 65 + i32.const 3 + call $~lib/rt/tlsf/__alloc + call $~lib/rt/pure/__retain + local.set $0 + local.get $0 + i32.const 0 + i32.store + local.get $0 + i32.const 0 + i32.store offset=4 + local.get $0 + i64.const 0 + i64.store offset=8 + local.get $0 + i64.const 0 + i64.store offset=16 + local.get $0 + f32.const 0 + f32.store offset=24 + local.get $0 + f64.const 0 + f64.store offset=32 + local.get $0 + i32.const 0 + i32.store8 offset=40 + local.get $0 + i32.const 0 + i32.store8 offset=41 + local.get $0 + i32.const 0 + i32.store16 offset=42 + local.get $0 + i32.const 0 + i32.store16 offset=44 + local.get $0 + i32.const 0 + i32.store offset=48 + local.get $0 + i32.const 0 + i32.store offset=52 + local.get $0 + f64.const 0 + f64.store offset=56 + local.get $0 + i32.const 0 + i32.store8 offset=64 + local.get $0 + call $std/object-literal-omitted/testOmittedTypes + i32.const 16 + i32.const 4 + call $~lib/rt/tlsf/__alloc + call $~lib/rt/pure/__retain + local.set $1 + local.get $1 + i32.const 0 + i32.store + local.get $1 + i32.const 272 + i32.store offset=4 + local.get $1 + f64.const 0 + f64.store offset=8 + local.get $1 + call $std/object-literal-omitted/testMixedOmitted + local.get $0 + call $~lib/rt/pure/__release + local.get $1 + call $~lib/rt/pure/__release + ) + (func $~start + call $start:std/object-literal-omitted + ) + (func $~lib/rt/pure/__collect + return + ) + (func $~lib/rt/tlsf/freeBlock (param $0 i32) (param $1 i32) + (local $2 i32) + local.get $1 + i32.load + local.set $2 + local.get $1 + local.get $2 + i32.const 1 + i32.or + i32.store + local.get $0 + local.get $1 + call $~lib/rt/tlsf/insertBlock + ) + (func $~lib/rt/pure/decrement (param $0 i32) + (local $1 i32) + (local $2 i32) + local.get $0 + i32.load offset=4 + local.set $1 + local.get $1 + i32.const 268435455 + i32.and + local.set $2 + local.get $0 + i32.load + i32.const 1 + i32.and + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 122 + i32.const 14 + call $~lib/builtins/abort + unreachable + end + local.get $2 + i32.const 1 + i32.eq + if + local.get $0 + i32.const 16 + i32.add + i32.const 1 + call $~lib/rt/__visit_members + local.get $1 + i32.const -2147483648 + i32.and + i32.eqz + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 126 + i32.const 18 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/rt/tlsf/ROOT + local.get $0 + call $~lib/rt/tlsf/freeBlock + else + local.get $2 + i32.const 0 + i32.gt_u + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 136 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $0 + local.get $1 + i32.const 268435455 + i32.const -1 + i32.xor + i32.and + local.get $2 + i32.const 1 + i32.sub + i32.or + i32.store offset=4 + end + ) + (func $~lib/rt/pure/__visit (param $0 i32) (param $1 i32) + local.get $0 + global.get $~lib/heap/__heap_base + i32.lt_u + if + return + end + local.get $1 + i32.const 1 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 144 + i32.const 69 + i32.const 16 + call $~lib/builtins/abort + unreachable + end + local.get $0 + i32.const 16 + i32.sub + call $~lib/rt/pure/decrement + ) + (func $~lib/rt/__visit_members (param $0 i32) (param $1 i32) + (local $2 i32) + block $switch$1$default + block $switch$1$case$6 + block $switch$1$case$4 + block $switch$1$case$2 + local.get $0 + i32.const 8 + i32.sub + i32.load + br_table $switch$1$case$2 $switch$1$case$2 $switch$1$case$4 $switch$1$case$2 $switch$1$case$6 $switch$1$default + end + return + end + local.get $0 + i32.load + local.tee $2 + if + local.get $2 + local.get $1 + call $~lib/rt/pure/__visit + end + return + end + local.get $0 + i32.load offset=4 + local.tee $2 + if + local.get $2 + local.get $1 + call $~lib/rt/pure/__visit + end + return + end + unreachable + ) ) From 005d587ff131fcfe7ece2b83daa8a71fae8dd8b1 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Thu, 16 Apr 2020 17:45:59 -0700 Subject: [PATCH 06/10] Finished up Basic AS types for omitted Object Literals --- src/compiler.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 5a7c9580ff..53820e2613 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8746,6 +8746,19 @@ export class Compiler extends DiagnosticEmitter { let fieldInstance = member; let fieldType = fieldInstance.type; + if (fieldType.classReference) { + // TODO: Check if it is a class, with a default value (constructor with no params). + // TODO: Check if it can be null, and set to null + + // Otherwise, error + this.error( + DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, + expression.range, classReference.toString() + ); + hasErrors = true; + continue; + } + switch(fieldType.kind) { // i32 Types case TypeKind.I8: @@ -8795,8 +8808,6 @@ export class Compiler extends DiagnosticEmitter { ); continue; } - // TODO: Check if it is a class, with a default value (constructor with no params). - // TODO: Check if it can be null, and set to null default: {} } } From 904e48f97642c31bd5b9adcd837e46d695b475f3 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Fri, 17 Apr 2020 15:41:43 -0700 Subject: [PATCH 07/10] Made requested changes --- src/compiler.ts | 151 +++++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 71 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 53820e2613..963e5d3913 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8690,11 +8690,12 @@ export class Compiler extends DiagnosticEmitter { assert(numNames == values.length); // Assume all class fields will be omitted, and add them to our omitted list - var omittedClassFieldMembers = new Map(); + let omittedClassFieldMembers = new Map(); if (members) { - for (let memberKey of members.keys()) { - let member = members.get(memberKey); - if (member && member.kind == ElementKind.FIELD) { + for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { + let memberKey = _keys[i]; + let member = assert(members.get(memberKey)); + if (member !== null && member.kind == ElementKind.FIELD) { omittedClassFieldMembers.set(member.name, ''); } } @@ -8724,11 +8725,13 @@ export class Compiler extends DiagnosticEmitter { } let fieldInstance = member; let fieldType = fieldInstance.type; - storeObjectLiteralField( - fieldInstance, - fieldType, - this.compileExpression(values[i], fieldInstance.type, Constraints.CONV_IMPLICIT) - ); + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.compileExpression(values[i], fieldInstance.type, Constraints.CONV_IMPLICIT), + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); // This member is no longer omitted, so delete from our omitted fields omittedClassFieldMembers.delete(member.name); @@ -8738,78 +8741,84 @@ export class Compiler extends DiagnosticEmitter { // Iterate through the remaining omittedClassFieldMembers. if (members) { - for(let omittedClassFieldMemberKey of omittedClassFieldMembers.keys()) { - let member = members.get(omittedClassFieldMemberKey); + for(let _keys = Map_keys(omittedClassFieldMembers), i = 0, k = _keys.length; i < k; ++i) { + let omittedMemberKey = _keys[i]; + let member = assert(members.get(omittedMemberKey)); - if(member) { + let fieldInstance = member; + let fieldType = fieldInstance.type; - let fieldInstance = member; - let fieldType = fieldInstance.type; + if (fieldType.is(TypeFlags.REFERENCE) && fieldType.classReference !== null) { + // TODO: Check if it is a class, with a default value (constructor with no params). + // TODO: Check if it can be null, and set to null - if (fieldType.classReference) { - // TODO: Check if it is a class, with a default value (constructor with no params). - // TODO: Check if it can be null, and set to null + // Otherwise, error + this.error( + DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, + expression.range, classReference.toString() + ); + hasErrors = true; + continue; + } - // Otherwise, error - this.error( - DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, - expression.range, classReference.toString() - ); - hasErrors = true; + switch(fieldType.kind) { + // i32 Types + case TypeKind.I8: + case TypeKind.I16: + case TypeKind.I32: + case TypeKind.U8: + case TypeKind.U16: + case TypeKind.U32: + case TypeKind.USIZE: + case TypeKind.ISIZE: + case TypeKind.BOOL: { + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.module.i32(0), + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); continue; } - switch(fieldType.kind) { - // i32 Types - case TypeKind.I8: - case TypeKind.I16: - case TypeKind.I32: - case TypeKind.U8: - case TypeKind.U16: - case TypeKind.U32: - case TypeKind.USIZE: - case TypeKind.ISIZE: - case TypeKind.BOOL: { - storeObjectLiteralField( - fieldInstance, - fieldType, - this.module.i32(0) - ); - continue; - } - - // i64 Types - case TypeKind.I64: - case TypeKind.U64: { - storeObjectLiteralField( - fieldInstance, - fieldType, - this.module.i64(0) - ); - continue; - } + // i64 Types + case TypeKind.I64: + case TypeKind.U64: { + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.module.i64(0), + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); + continue; + } - // f32 Types - case TypeKind.F32: { - storeObjectLiteralField( - fieldInstance, - fieldType, - this.module.f32(0) - ); - continue; - } + // f32 Types + case TypeKind.F32: { + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.module.f32(0), + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); + continue; + } - // f64 Types - case TypeKind.F64: { - storeObjectLiteralField( - fieldInstance, - fieldType, - this.module.f64(0) - ); - continue; - } - default: {} + // f64 Types + case TypeKind.F64: { + exprs.push(this.module.store( // TODO: handle setters as well + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.module.f64(0), + fieldType.toNativeType(), + fieldInstance.memoryOffset + )); + continue; } + default: {} } // Otherwise, error From 0704c1924bea50d75f67301c05c3f9c173efccb4 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Fri, 17 Apr 2020 15:54:00 -0700 Subject: [PATCH 08/10] Removed remaning asbuild breaking code --- src/compiler.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 963e5d3913..bfbd0c9722 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8701,17 +8701,6 @@ export class Compiler extends DiagnosticEmitter { } } - // Define a function to add a new expression on our Object literal - let storeObjectLiteralField = (fieldInstance: Field, fieldType: Type, valueExpr: ExpressionRef) => { - exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - valueExpr, - fieldType.toNativeType(), - fieldInstance.memoryOffset - )); - }; - // Iterate through the members definted in our expression for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; From 042ee8247c151d750895c83c90a01a2ee1b3f179 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Mon, 20 Apr 2020 11:32:09 -0700 Subject: [PATCH 09/10] Made requested changes --- src/compiler.ts | 66 +++++++++-------------------- src/diagnosticMessages.generated.ts | 4 +- src/diagnosticMessages.json | 2 +- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index bfbd0c9722..80e9b34920 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8690,13 +8690,13 @@ export class Compiler extends DiagnosticEmitter { assert(numNames == values.length); // Assume all class fields will be omitted, and add them to our omitted list - let omittedClassFieldMembers = new Map(); + let omittedClassFieldMembers = new Set(); if (members) { for (let _keys = Map_keys(members), i = 0, k = _keys.length; i < k; ++i) { let memberKey = _keys[i]; let member = assert(members.get(memberKey)); if (member !== null && member.kind == ElementKind.FIELD) { - omittedClassFieldMembers.set(member.name, ''); + omittedClassFieldMembers.add(member.name); } } } @@ -8714,10 +8714,15 @@ export class Compiler extends DiagnosticEmitter { } let fieldInstance = member; let fieldType = fieldInstance.type; + + let expr = this.compileExpression(values[i], fieldType, Constraints.CONV_IMPLICIT | Constraints.WILL_RETAIN); + if (isManaged && fieldType.isManaged && !this.skippedAutoreleases.has(expr)) { + expr = this.makeRetain(expr); + } exprs.push(this.module.store( // TODO: handle setters as well fieldType.byteSize, this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.compileExpression(values[i], fieldInstance.type, Constraints.CONV_IMPLICIT), + expr, fieldType.toNativeType(), fieldInstance.memoryOffset )); @@ -8730,8 +8735,8 @@ export class Compiler extends DiagnosticEmitter { // Iterate through the remaining omittedClassFieldMembers. if (members) { - for(let _keys = Map_keys(omittedClassFieldMembers), i = 0, k = _keys.length; i < k; ++i) { - let omittedMemberKey = _keys[i]; + for(let _values = Set_values(omittedClassFieldMembers), i = 0, v = _values.length; i < v; ++i) { + let omittedMemberKey = _values[i]; let member = assert(members.get(omittedMemberKey)); let fieldInstance = member; @@ -8743,15 +8748,15 @@ export class Compiler extends DiagnosticEmitter { // Otherwise, error this.error( - DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, - expression.range, classReference.toString() + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + expression.range, "", classReference.toString() ); hasErrors = true; continue; } switch(fieldType.kind) { - // i32 Types + // Number Types (and Number alias types) case TypeKind.I8: case TypeKind.I16: case TypeKind.I32: @@ -8760,48 +8765,15 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.U32: case TypeKind.USIZE: case TypeKind.ISIZE: - case TypeKind.BOOL: { - exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.module.i32(0), - fieldType.toNativeType(), - fieldInstance.memoryOffset - )); - continue; - } - - // i64 Types + case TypeKind.BOOL: case TypeKind.I64: - case TypeKind.U64: { - exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.module.i64(0), - fieldType.toNativeType(), - fieldInstance.memoryOffset - )); - continue; - } - - // f32 Types - case TypeKind.F32: { - exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.module.f32(0), - fieldType.toNativeType(), - fieldInstance.memoryOffset - )); - continue; - } - - // f64 Types + case TypeKind.U64: + case TypeKind.F32: case TypeKind.F64: { exprs.push(this.module.store( // TODO: handle setters as well fieldType.byteSize, this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.module.f64(0), + this.makeZero(fieldType), fieldType.toNativeType(), fieldInstance.memoryOffset )); @@ -8812,8 +8784,8 @@ export class Compiler extends DiagnosticEmitter { // Otherwise, error this.error( - DiagnosticCode.Object_literal_is_missing_class_member_fields_that_must_be_defined, - expression.range, classReference.toString() + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + expression.range, "", classReference.toString() ); hasErrors = true; } diff --git a/src/diagnosticMessages.generated.ts b/src/diagnosticMessages.generated.ts index 7da184da1b..464c749203 100644 --- a/src/diagnosticMessages.generated.ts +++ b/src/diagnosticMessages.generated.ts @@ -40,7 +40,6 @@ export enum DiagnosticCode { _0_is_not_a_valid_operator = 224, Expression_cannot_be_represented_by_a_type = 225, Expression_resolves_to_unusual_type_0 = 226, - Object_literal_is_missing_class_member_fields_that_must_be_defined = 227, Type_0_is_cyclic_Module_will_include_deferred_garbage_collection = 900, Importing_the_table_disables_some_indirect_call_optimizations = 901, Exporting_the_table_disables_some_indirect_call_optimizations = 902, @@ -151,6 +150,7 @@ export enum DiagnosticCode { Namespace_0_has_no_exported_member_1 = 2694, Required_type_parameters_may_not_follow_optional_type_parameters = 2706, Duplicate_property_0 = 2718, + Property_0_is_missing_in_type_1_but_required_in_type_2 = 2741, Type_0_has_no_call_signatures = 2757, File_0_not_found = 6054, Numeric_separators_are_not_allowed_here = 6188, @@ -195,7 +195,6 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 224: return "'{0}' is not a valid operator."; case 225: return "Expression cannot be represented by a type."; case 226: return "Expression resolves to unusual type '{0}'."; - case 227: return "Object literal is missing class member fields that must be defined"; case 900: return "Type '{0}' is cyclic. Module will include deferred garbage collection."; case 901: return "Importing the table disables some indirect call optimizations."; case 902: return "Exporting the table disables some indirect call optimizations."; @@ -306,6 +305,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string { case 2694: return "Namespace '{0}' has no exported member '{1}'."; case 2706: return "Required type parameters may not follow optional type parameters."; case 2718: return "Duplicate property '{0}'."; + case 2741: return "Property '{0}' is missing in type '{1}' but required in type '{2}'."; case 2757: return "Type '{0}' has no call signatures."; case 6054: return "File '{0}' not found."; case 6188: return "Numeric separators are not allowed here."; diff --git a/src/diagnosticMessages.json b/src/diagnosticMessages.json index ee78efe8b2..eb7a2771cb 100644 --- a/src/diagnosticMessages.json +++ b/src/diagnosticMessages.json @@ -33,7 +33,6 @@ "'{0}' is not a valid operator.": 224, "Expression cannot be represented by a type.": 225, "Expression resolves to unusual type '{0}'.": 226, - "Object literal is missing class member fields that must be defined": 227, "Type '{0}' is cyclic. Module will include deferred garbage collection.": 900, "Importing the table disables some indirect call optimizations.": 901, @@ -147,6 +146,7 @@ "Namespace '{0}' has no exported member '{1}'.": 2694, "Required type parameters may not follow optional type parameters.": 2706, "Duplicate property '{0}'.": 2718, + "Property '{0}' is missing in type '{1}' but required in type '{2}'.": 2741, "Type '{0}' has no call signatures.": 2757, "File '{0}' not found.": 6054, From 8b34c13290aeb79455b71a89afa6d8e0a6fbaa7d Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Mon, 20 Apr 2020 17:47:21 -0700 Subject: [PATCH 10/10] Made requested changes :) --- src/compiler.ts | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 80e9b34920..4cf331166e 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -8701,7 +8701,7 @@ export class Compiler extends DiagnosticEmitter { } } - // Iterate through the members definted in our expression + // Iterate through the members defined in our expression for (let i = 0, k = numNames; i < k; ++i) { let member = members ? members.get(names[i].text) : null; if (!member || member.kind != ElementKind.FIELD) { @@ -8720,11 +8720,11 @@ export class Compiler extends DiagnosticEmitter { expr = this.makeRetain(expr); } exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - expr, - fieldType.toNativeType(), - fieldInstance.memoryOffset + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + expr, + fieldType.toNativeType(), + fieldInstance.memoryOffset )); // This member is no longer omitted, so delete from our omitted fields @@ -8735,8 +8735,9 @@ export class Compiler extends DiagnosticEmitter { // Iterate through the remaining omittedClassFieldMembers. if (members) { - for(let _values = Set_values(omittedClassFieldMembers), i = 0, v = _values.length; i < v; ++i) { - let omittedMemberKey = _values[i]; + + for (let _values = Set_values(omittedClassFieldMembers), j = 0, l = _values.length; j < l; ++j) { + let omittedMemberKey = _values[j]; let member = assert(members.get(omittedMemberKey)); let fieldInstance = member; @@ -8744,15 +8745,14 @@ export class Compiler extends DiagnosticEmitter { if (fieldType.is(TypeFlags.REFERENCE) && fieldType.classReference !== null) { // TODO: Check if it is a class, with a default value (constructor with no params). - // TODO: Check if it can be null, and set to null - - // Otherwise, error - this.error( - DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, - expression.range, "", classReference.toString() - ); - hasErrors = true; - continue; + if (!fieldType.is(TypeFlags.NULLABLE)) { + this.error( + DiagnosticCode.Property_0_is_missing_in_type_1_but_required_in_type_2, + expression.range, "", classReference.toString() + ); + hasErrors = true; + continue; + } } switch(fieldType.kind) { @@ -8771,15 +8771,14 @@ export class Compiler extends DiagnosticEmitter { case TypeKind.F32: case TypeKind.F64: { exprs.push(this.module.store( // TODO: handle setters as well - fieldType.byteSize, - this.module.local_get(tempLocal.index, this.options.nativeSizeType), - this.makeZero(fieldType), - fieldType.toNativeType(), - fieldInstance.memoryOffset + fieldType.byteSize, + this.module.local_get(tempLocal.index, this.options.nativeSizeType), + this.makeZero(fieldType), + fieldType.toNativeType(), + fieldInstance.memoryOffset )); continue; } - default: {} } // Otherwise, error