From 5b910e31420fc2d7235899bb985bfb23d4449b33 Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Wed, 5 Aug 2020 10:27:29 -0700 Subject: [PATCH] fix: Propagate delayed file exports to `import * as` alias namespaces of the file --- src/compiler.ts | 8 +- src/program.ts | 20 +- tests/compiler/exports.optimized.wat | 6 + tests/compiler/exports.ts | 2 + tests/compiler/exports.untouched.wat | 9 + .../exportstar-rereexport.optimized.wat | 130 +++++- .../exportstar-rereexport.untouched.wat | 301 +++++++++++++- tests/compiler/reexport.optimized.wat | 241 ++++++++++- tests/compiler/reexport.ts | 11 + tests/compiler/reexport.untouched.wat | 382 +++++++++++++++++- tests/compiler/rereexport.optimized.wat | 130 +++++- tests/compiler/rereexport.ts | 15 + tests/compiler/rereexport.untouched.wat | 301 +++++++++++++- 13 files changed, 1546 insertions(+), 10 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 3d7228765c..99de950cd2 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -367,6 +367,8 @@ export class Compiler extends DiagnosticEmitter { virtualCalls: Set = new Set(); /** Elements currently undergoing compilation. */ pendingElements: Set = new Set(); + /** Elements, that are module exports, already processed */ + doneModuleExports: Set = new Set(); /** Compiles a {@link Program} to a {@link Module} using the specified options. */ static compile(program: Program): Module { @@ -815,7 +817,11 @@ export class Compiler extends DiagnosticEmitter { if (!classInstance.type.isUnmanaged) { let module = this.module; let internalName = classInstance.internalName; - module.addGlobal(internalName, NativeType.I32, false, module.i32(classInstance.id)); + + if (!this.doneModuleExports.has(element)) { + module.addGlobal(internalName, NativeType.I32, false, module.i32(classInstance.id)); + this.doneModuleExports.add(element); + } module.addGlobalExport(internalName, prefix + name); } break; diff --git a/src/program.ts b/src/program.ts index 8cc6ba4347..63fdf560da 100644 --- a/src/program.ts +++ b/src/program.ts @@ -1053,7 +1053,7 @@ export class Program extends DiagnosticEmitter { let localName = localIdentifier.text; localFile.add( localName, - foreignFile.asImportedNamespace( + foreignFile.asAliasNamespace( localName, localFile, localIdentifier @@ -2893,6 +2893,8 @@ export class File extends Element { exportsStar: File[] | null = null; /** Top-level start function of this file. */ startFunction!: Function; + /** Array of `import * as X` alias namespaces of this file. */ + aliasNamespaces: Array = new Array(); /** Constructs a new file. */ constructor( @@ -2962,6 +2964,12 @@ export class File extends Element { if (!exports) this.exports = exports = new Map(); exports.set(name, element); if (this.source.sourceKind == SourceKind.LIBRARY_ENTRY) this.program.ensureGlobal(name, element); + + // Also, add to the namespaces that capture our exports + for(let i = 0; i < this.aliasNamespaces.length; i++) { + let ns = this.aliasNamespaces[i]; + ns.add(name, element); + } } /** Ensures that another file is a re-export of this file. */ @@ -2987,12 +2995,20 @@ export class File extends Element { } /** Creates an imported namespace from this file. */ - asImportedNamespace(name: string, parent: Element, localIdentifier: IdentifierExpression): Namespace { + asAliasNamespace( + name: string, + parent: Element, + localIdentifier: IdentifierExpression + ): Namespace { var declaration = this.program.makeNativeNamespaceDeclaration(name); declaration.name = localIdentifier; var ns = new Namespace(name, parent, declaration); ns.set(CommonFlags.SCOPED); this.copyExportsToNamespace(ns); + // NOTE: Some exports are still queued, and can't yet be added here, + // so we remember all the alias namespaces and add to them as well + // when adding an element to the file. + this.aliasNamespaces.push(ns); return ns; } diff --git a/tests/compiler/exports.optimized.wat b/tests/compiler/exports.optimized.wat index 9e2849876f..d935ff06e9 100644 --- a/tests/compiler/exports.optimized.wat +++ b/tests/compiler/exports.optimized.wat @@ -44,6 +44,7 @@ (export "vehicles.Car.TIRES" (global $exports/vehicles.Car.TIRES)) (export "vehicles.Car.getNumTires" (func $exports/Car.getNumTires)) (export "outer.inner.a" (global $exports/outer.inner.a)) + (export "renamed_mul" (func $export/mul)) (export "__setArgumentsLength" (func $~setArgumentsLength)) (start $~start) (func $exports/add (param $0 i32) (param $1 i32) (result i32) @@ -137,6 +138,11 @@ (func $exports/Car#openDoors (param $0 i32) nop ) + (func $export/mul (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.mul + ) (func $~start i32.const 1024 global.set $~lib/rt/stub/offset diff --git a/tests/compiler/exports.ts b/tests/compiler/exports.ts index 5953536e4a..c18fc6a1fa 100644 --- a/tests/compiler/exports.ts +++ b/tests/compiler/exports.ts @@ -56,3 +56,5 @@ export namespace outer { export const a = 42; } } + +export {renamed_mul} from "./export"; diff --git a/tests/compiler/exports.untouched.wat b/tests/compiler/exports.untouched.wat index 43014ed255..642deb6a97 100644 --- a/tests/compiler/exports.untouched.wat +++ b/tests/compiler/exports.untouched.wat @@ -14,6 +14,9 @@ (global $exports/Car.TIRES i32 (i32.const 4)) (global $exports/vehicles.Car.TIRES i32 (i32.const 4)) (global $exports/outer.inner.a i32 (i32.const 42)) + (global $export/a i32 (i32.const 1)) + (global $export/b i32 (i32.const 2)) + (global $export/c i32 (i32.const 3)) (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) (global $~lib/heap/__heap_base i32 (i32.const 8)) @@ -47,6 +50,7 @@ (export "vehicles.Car.TIRES" (global $exports/vehicles.Car.TIRES)) (export "vehicles.Car.getNumTires" (func $exports/vehicles.Car.getNumTires)) (export "outer.inner.a" (global $exports/outer.inner.a)) + (export "renamed_mul" (func $export/mul)) (export "__setArgumentsLength" (func $~setArgumentsLength)) (start $~start) (func $exports/add (param $0 i32) (param $1 i32) (result i32) @@ -260,6 +264,11 @@ (func $exports/vehicles.Car#openDoors (param $0 i32) nop ) + (func $export/mul (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.mul + ) (func $~start global.get $~lib/heap/__heap_base i32.const 15 diff --git a/tests/compiler/exportstar-rereexport.optimized.wat b/tests/compiler/exportstar-rereexport.optimized.wat index b66c5fd158..606338749d 100644 --- a/tests/compiler/exportstar-rereexport.optimized.wat +++ b/tests/compiler/exportstar-rereexport.optimized.wat @@ -1,10 +1,19 @@ (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_none (func)) - (memory $0 0) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 1024) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s") + (data (i32.const 1072) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00r\00e\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s") (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $rereexport/car (mut i32) (i32.const 0)) + (global $rereexport/exportsNamespaceCar (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "a" (global $export/a)) (export "renamed_a" (global $export/a)) @@ -20,6 +29,7 @@ (export "exportstar.renamed_c" (global $export/c)) (export "exportstar.ns.two" (func $export-default/theDefault)) (export "exportstar.default.two" (func $export-default/theDefault)) + (start $~start) (func $export/add (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 @@ -30,6 +40,78 @@ local.get $1 i32.mul ) + (func $exports/Car#constructor (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + local.tee $0 + memory.size + local.tee $3 + i32.const 16 + i32.shl + local.tee $2 + i32.gt_u + if + local.get $3 + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $2 + local.get $3 + local.get $2 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $2 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const 1 + i32.store offset=4 + local.get $0 + i32.const 3 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $1 + i32.const 2 + i32.store + local.get $1 + i32.const 2 + i32.store + local.get $1 + ) (func $export-default/theDefault nop ) @@ -38,4 +120,50 @@ local.get $1 i32.sub ) + (func $~start + i32.const 1120 + global.set $~lib/rt/stub/offset + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1040 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $exports/Car#constructor + global.set $rereexport/car + global.get $rereexport/car + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1088 + i32.const 18 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $exports/Car#constructor + global.set $rereexport/exportsNamespaceCar + global.get $rereexport/exportsNamespaceCar + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1088 + i32.const 24 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + ) ) diff --git a/tests/compiler/exportstar-rereexport.untouched.wat b/tests/compiler/exportstar-rereexport.untouched.wat index 477f4788a2..57c3341551 100644 --- a/tests/compiler/exportstar-rereexport.untouched.wat +++ b/tests/compiler/exportstar-rereexport.untouched.wat @@ -1,11 +1,26 @@ (module (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (memory $0 0) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_=>_none (func (param i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 16) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s\00") + (data (i32.const 64) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00r\00e\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s\00") (table $0 1 funcref) (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $exports/Car.TIRES i32 (i32.const 4)) + (global $exports/vehicles.Car.TIRES i32 (i32.const 4)) + (global $exports/outer.inner.a i32 (i32.const 42)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $rereexport/car (mut i32) (i32.const 0)) + (global $rereexport/exportsNamespaceCar (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 108)) (export "memory" (memory $0)) (export "a" (global $export/a)) (export "renamed_a" (global $export/a)) @@ -32,6 +47,145 @@ local.get $1 i32.mul ) + (func $exports/add (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.add + ) + (func $~lib/rt/stub/maybeGrowMemory (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + i32.const 1 + drop + local.get $6 + i32.const 1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (param $0 i32) (result i32) + local.get $0 + ) + (func $exports/Car#constructor (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $exports/Car#get:numDoors (param $0 i32) (result i32) + local.get $0 + i32.load + ) (func $start:reexport i32.const 1 i32.const 2 @@ -41,9 +195,154 @@ call $export/mul i32.add drop + i32.const 2 + i32.const 2 + call $exports/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 37 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 38 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end ) (func $start:rereexport call $start:reexport + i32.const 2 + i32.const 2 + call $export/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 15 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 16 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $rereexport/car + global.get $rereexport/car + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 18 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $exports/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 21 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 22 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $rereexport/exportsNamespaceCar + global.get $rereexport/exportsNamespaceCar + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 24 + i32.const 1 + call $~lib/builtins/abort + unreachable + end ) (func $start:exportstar-rereexport call $start:rereexport diff --git a/tests/compiler/reexport.optimized.wat b/tests/compiler/reexport.optimized.wat index ff82192864..502c3cd9f8 100644 --- a/tests/compiler/reexport.optimized.wat +++ b/tests/compiler/reexport.optimized.wat @@ -1,10 +1,29 @@ (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_none (func)) - (memory $0 0) + (type $i32_=>_none (func (param i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 1024) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s") (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $exports/Animal.CAT i32 (i32.const 0)) + (global $exports/Animal.DOG i32 (i32.const 1)) + (global $exports/animals.Animal.CAT i32 (i32.const 0)) + (global $exports/animals.Animal.DOG i32 (i32.const 1)) + (global $exports/Car.TIRES i32 (i32.const 4)) + (global $exports/vehicles.Car.TIRES i32 (i32.const 4)) + (global $exports/outer.inner.a i32 (i32.const 42)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $exports/Car i32 (i32.const 3)) + (global $~argumentsLength (mut i32) (i32.const 0)) + (global $exports/vehicles.Car i32 (i32.const 4)) (export "memory" (memory $0)) (export "add" (func $export/add)) (export "renamed_sub" (func $export/sub)) @@ -14,6 +33,15 @@ (export "renamed_b" (global $export/b)) (export "renamed_c" (global $export/c)) (export "rerenamed_c" (global $export/c)) + (export "Car" (global $exports/Car)) + (export "Car#get:doors" (func $exports/Car#get:numDoors)) + (export "Car#set:doors" (func $exports/Car#set:doors)) + (export "Car#constructor" (func $exports/Car#constructor@varargs)) + (export "Car#get:numDoors" (func $exports/Car#get:numDoors)) + (export "Car#set:numDoors" (func $exports/Car#set:doors)) + (export "Car#openDoors" (func $exports/Car#openDoors)) + (export "Car.TIRES" (global $exports/Car.TIRES)) + (export "Car.getNumTires" (func $exports/Car.getNumTires)) (export "renamed_add" (func $export/add)) (export "rerenamed_sub" (func $export/mul)) (export "renamed_ns.two" (func $export/ns.one)) @@ -25,8 +53,37 @@ (export "exportstar.renamed_c" (global $export/c)) (export "exportstar.ns.two" (func $export/ns.one)) (export "exportstar.default.two" (func $export/ns.one)) + (export "ExportsNamespace.add" (func $export/add)) + (export "ExportsNamespace.subOpt" (func $exports/subOpt@varargs)) + (export "ExportsNamespace.math.sub" (func $export/sub)) + (export "ExportsNamespace.Animal.CAT" (global $exports/Animal.CAT)) + (export "ExportsNamespace.Animal.DOG" (global $exports/Animal.DOG)) + (export "ExportsNamespace.animals.Animal.CAT" (global $exports/animals.Animal.CAT)) + (export "ExportsNamespace.animals.Animal.DOG" (global $exports/animals.Animal.DOG)) + (export "ExportsNamespace.Car" (global $exports/Car)) + (export "ExportsNamespace.Car#get:doors" (func $exports/Car#get:numDoors)) + (export "ExportsNamespace.Car#set:doors" (func $exports/Car#set:doors)) + (export "ExportsNamespace.Car#constructor" (func $exports/Car#constructor@varargs)) + (export "ExportsNamespace.Car#get:numDoors" (func $exports/Car#get:numDoors)) + (export "ExportsNamespace.Car#set:numDoors" (func $exports/Car#set:doors)) + (export "ExportsNamespace.Car#openDoors" (func $exports/Car#openDoors)) + (export "ExportsNamespace.Car.TIRES" (global $exports/Car.TIRES)) + (export "ExportsNamespace.Car.getNumTires" (func $exports/Car.getNumTires)) + (export "ExportsNamespace.vehicles.Car" (global $exports/vehicles.Car)) + (export "ExportsNamespace.vehicles.Car#get:doors" (func $exports/Car#get:numDoors)) + (export "ExportsNamespace.vehicles.Car#set:doors" (func $exports/Car#set:doors)) + (export "ExportsNamespace.vehicles.Car#constructor" (func $exports/vehicles.Car#constructor@varargs)) + (export "ExportsNamespace.vehicles.Car#get:numDoors" (func $exports/Car#get:numDoors)) + (export "ExportsNamespace.vehicles.Car#set:numDoors" (func $exports/Car#set:doors)) + (export "ExportsNamespace.vehicles.Car#openDoors" (func $exports/Car#openDoors)) + (export "ExportsNamespace.vehicles.Car.TIRES" (global $exports/vehicles.Car.TIRES)) + (export "ExportsNamespace.vehicles.Car.getNumTires" (func $exports/Car.getNumTires)) + (export "ExportsNamespace.outer.inner.a" (global $exports/outer.inner.a)) + (export "ExportsNamespace.renamed_mul" (func $export/mul)) (export "default" (func $export/ns.one)) (export "renamed_default" (func $export/ns.one)) + (export "__setArgumentsLength" (func $~setArgumentsLength)) + (start $~start) (func $export/add (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 @@ -37,12 +94,194 @@ local.get $1 i32.mul ) + (func $~lib/rt/stub/__alloc (param $0 i32) (result i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $3 + i32.const 16 + i32.add + local.tee $1 + memory.size + local.tee $4 + i32.const 16 + i32.shl + local.tee $2 + i32.gt_u + if + local.get $4 + local.get $1 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $2 + local.get $4 + local.get $2 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $2 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $1 + global.set $~lib/rt/stub/offset + local.get $3 + i32.const 16 + i32.sub + local.tee $1 + i32.const 16 + i32.store + local.get $1 + i32.const 1 + i32.store offset=4 + local.get $1 + local.get $0 + i32.store offset=8 + local.get $1 + i32.const 4 + i32.store offset=12 + local.get $3 + ) + (func $exports/Car#constructor (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 3 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $exports/Car#get:numDoors (param $0 i32) (result i32) + local.get $0 + i32.load + ) (func $export/sub (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.sub ) + (func $exports/Car.getNumTires (result i32) + i32.const 4 + ) + (func $exports/Car#set:doors (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store + ) + (func $exports/Car#openDoors (param $0 i32) + nop + ) (func $export/ns.one nop ) + (func $~start + i32.const 1072 + global.set $~lib/rt/stub/offset + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1040 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + ) + (func $exports/Car#constructor@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 2 + local.set $1 + end + local.get $0 + local.get $1 + call $exports/Car#constructor + ) + (func $exports/subOpt@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + i32.const 1 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 0 + local.set $1 + end + local.get $0 + local.get $1 + i32.sub + ) + (func $exports/vehicles.Car#constructor@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 2 + local.set $1 + end + local.get $0 + i32.eqz + if + i32.const 4 + call $~lib/rt/stub/__alloc + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $~setArgumentsLength (param $0 i32) + local.get $0 + global.set $~argumentsLength + ) ) diff --git a/tests/compiler/reexport.ts b/tests/compiler/reexport.ts index f8b3fdb1cf..35d2addbf9 100644 --- a/tests/compiler/reexport.ts +++ b/tests/compiler/reexport.ts @@ -10,6 +10,10 @@ export { renamed_c as rerenamed_c } from "./export"; +export { + Car +} from "./exports"; + import { add as imported_add, renamed_mul as imported_sub, @@ -28,5 +32,12 @@ export { ns as renamed_ns } from "./export"; import * as exportstar from "./exportstar"; export { exportstar }; +import * as ExportsNamespace from "./exports"; +export { ExportsNamespace }; +assert(ExportsNamespace.add(2, 2) == 4); +assert(ExportsNamespace.renamed_mul(2, 2) == 4); +let car: ExportsNamespace.Car = new ExportsNamespace.Car(); +assert(car.numDoors == 2); + export { default } from "./export-default"; export { default as renamed_default } from "./export-default"; diff --git a/tests/compiler/reexport.untouched.wat b/tests/compiler/reexport.untouched.wat index f1fc2f503b..5c277543ef 100644 --- a/tests/compiler/reexport.untouched.wat +++ b/tests/compiler/reexport.untouched.wat @@ -1,11 +1,32 @@ (module - (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (memory $0 0) + (type $none_=>_none (func)) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_=>_none (func (param i32))) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $none_=>_i32 (func (result i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 16) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s\00") (table $0 1 funcref) (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $exports/Animal.CAT i32 (i32.const 0)) + (global $exports/Animal.DOG i32 (i32.const 1)) + (global $exports/animals.Animal.CAT i32 (i32.const 0)) + (global $exports/animals.Animal.DOG i32 (i32.const 1)) + (global $exports/Car.TIRES i32 (i32.const 4)) + (global $exports/vehicles.Car.TIRES i32 (i32.const 4)) + (global $exports/outer.inner.a i32 (i32.const 42)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 56)) + (global $exports/Car i32 (i32.const 3)) + (global $~argumentsLength (mut i32) (i32.const 0)) + (global $exports/vehicles.Car i32 (i32.const 4)) (export "memory" (memory $0)) (export "add" (func $export/add)) (export "renamed_sub" (func $export/sub)) @@ -15,6 +36,15 @@ (export "renamed_b" (global $export/b)) (export "renamed_c" (global $export/c)) (export "rerenamed_c" (global $export/c)) + (export "Car" (global $exports/Car)) + (export "Car#get:doors" (func $exports/Car#get:doors)) + (export "Car#set:doors" (func $exports/Car#set:doors)) + (export "Car#constructor" (func $exports/Car#constructor@varargs)) + (export "Car#get:numDoors" (func $exports/Car#get:numDoors)) + (export "Car#set:numDoors" (func $exports/Car#set:numDoors)) + (export "Car#openDoors" (func $exports/Car#openDoors)) + (export "Car.TIRES" (global $exports/Car.TIRES)) + (export "Car.getNumTires" (func $exports/Car.getNumTires)) (export "renamed_add" (func $export/add)) (export "rerenamed_sub" (func $export/mul)) (export "renamed_ns.two" (func $export/ns.two)) @@ -26,8 +56,36 @@ (export "exportstar.renamed_c" (global $export/c)) (export "exportstar.ns.two" (func $export/ns.two)) (export "exportstar.default.two" (func $export/ns.two)) + (export "ExportsNamespace.add" (func $exports/add)) + (export "ExportsNamespace.subOpt" (func $exports/subOpt@varargs)) + (export "ExportsNamespace.math.sub" (func $exports/math.sub)) + (export "ExportsNamespace.Animal.CAT" (global $exports/Animal.CAT)) + (export "ExportsNamespace.Animal.DOG" (global $exports/Animal.DOG)) + (export "ExportsNamespace.animals.Animal.CAT" (global $exports/animals.Animal.CAT)) + (export "ExportsNamespace.animals.Animal.DOG" (global $exports/animals.Animal.DOG)) + (export "ExportsNamespace.Car" (global $exports/Car)) + (export "ExportsNamespace.Car#get:doors" (func $exports/Car#get:doors)) + (export "ExportsNamespace.Car#set:doors" (func $exports/Car#set:doors)) + (export "ExportsNamespace.Car#constructor" (func $exports/Car#constructor@varargs)) + (export "ExportsNamespace.Car#get:numDoors" (func $exports/Car#get:numDoors)) + (export "ExportsNamespace.Car#set:numDoors" (func $exports/Car#set:numDoors)) + (export "ExportsNamespace.Car#openDoors" (func $exports/Car#openDoors)) + (export "ExportsNamespace.Car.TIRES" (global $exports/Car.TIRES)) + (export "ExportsNamespace.Car.getNumTires" (func $exports/Car.getNumTires)) + (export "ExportsNamespace.vehicles.Car" (global $exports/vehicles.Car)) + (export "ExportsNamespace.vehicles.Car#get:doors" (func $exports/vehicles.Car#get:doors)) + (export "ExportsNamespace.vehicles.Car#set:doors" (func $exports/vehicles.Car#set:doors)) + (export "ExportsNamespace.vehicles.Car#constructor" (func $exports/vehicles.Car#constructor@varargs)) + (export "ExportsNamespace.vehicles.Car#get:numDoors" (func $exports/vehicles.Car#get:numDoors)) + (export "ExportsNamespace.vehicles.Car#set:numDoors" (func $exports/vehicles.Car#set:numDoors)) + (export "ExportsNamespace.vehicles.Car#openDoors" (func $exports/vehicles.Car#openDoors)) + (export "ExportsNamespace.vehicles.Car.TIRES" (global $exports/vehicles.Car.TIRES)) + (export "ExportsNamespace.vehicles.Car.getNumTires" (func $exports/vehicles.Car.getNumTires)) + (export "ExportsNamespace.outer.inner.a" (global $exports/outer.inner.a)) + (export "ExportsNamespace.renamed_mul" (func $export/mul)) (export "default" (func $export-default/theDefault)) (export "renamed_default" (func $export-default/theDefault)) + (export "__setArgumentsLength" (func $~setArgumentsLength)) (start $~start) (func $export/add (param $0 i32) (param $1 i32) (result i32) local.get $0 @@ -39,6 +97,145 @@ local.get $1 i32.mul ) + (func $exports/add (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.add + ) + (func $~lib/rt/stub/maybeGrowMemory (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + i32.const 1 + drop + local.get $6 + i32.const 1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (param $0 i32) (result i32) + local.get $0 + ) + (func $exports/Car#constructor (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $exports/Car#get:numDoors (param $0 i32) (result i32) + local.get $0 + i32.load + ) (func $start:reexport i32.const 1 i32.const 2 @@ -48,22 +245,203 @@ call $export/mul i32.add drop + i32.const 2 + i32.const 2 + call $exports/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 37 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 38 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end ) (func $export/sub (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 i32.sub ) + (func $exports/Car.getNumTires (result i32) + global.get $exports/Car.TIRES + ) + (func $exports/Car#get:doors (param $0 i32) (result i32) + local.get $0 + i32.load + ) + (func $exports/Car#set:doors (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store + ) + (func $exports/Car#set:numDoors (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store + ) + (func $exports/Car#openDoors (param $0 i32) + nop + ) (func $export/ns.one nop ) (func $export/ns.two nop ) + (func $exports/subOpt (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.sub + ) + (func $exports/math.sub (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.sub + ) + (func $exports/vehicles.Car.getNumTires (result i32) + global.get $exports/vehicles.Car.TIRES + ) + (func $exports/vehicles.Car#constructor (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 4 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $exports/vehicles.Car#get:doors (param $0 i32) (result i32) + local.get $0 + i32.load + ) + (func $exports/vehicles.Car#set:doors (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store + ) + (func $exports/vehicles.Car#get:numDoors (param $0 i32) (result i32) + local.get $0 + i32.load + ) + (func $exports/vehicles.Car#set:numDoors (param $0 i32) (param $1 i32) + local.get $0 + local.get $1 + i32.store + ) + (func $exports/vehicles.Car#openDoors (param $0 i32) + nop + ) (func $export-default/theDefault nop ) (func $~start call $start:reexport ) + (func $exports/Car#constructor@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 2 + local.set $1 + end + local.get $0 + local.get $1 + call $exports/Car#constructor + ) + (func $exports/subOpt@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + i32.const 1 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 0 + local.set $1 + end + local.get $0 + local.get $1 + call $exports/subOpt + ) + (func $exports/vehicles.Car#constructor@varargs (param $0 i32) (param $1 i32) (result i32) + block $1of1 + block $0of1 + block $outOfRange + global.get $~argumentsLength + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 2 + local.set $1 + end + local.get $0 + local.get $1 + call $exports/vehicles.Car#constructor + ) + (func $~setArgumentsLength (param $0 i32) + local.get $0 + global.set $~argumentsLength + ) ) diff --git a/tests/compiler/rereexport.optimized.wat b/tests/compiler/rereexport.optimized.wat index b66c5fd158..606338749d 100644 --- a/tests/compiler/rereexport.optimized.wat +++ b/tests/compiler/rereexport.optimized.wat @@ -1,10 +1,19 @@ (module (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $none_=>_none (func)) - (memory $0 0) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $none_=>_i32 (func (result i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 1024) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s") + (data (i32.const 1072) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00r\00e\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s") (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $rereexport/car (mut i32) (i32.const 0)) + (global $rereexport/exportsNamespaceCar (mut i32) (i32.const 0)) (export "memory" (memory $0)) (export "a" (global $export/a)) (export "renamed_a" (global $export/a)) @@ -20,6 +29,7 @@ (export "exportstar.renamed_c" (global $export/c)) (export "exportstar.ns.two" (func $export-default/theDefault)) (export "exportstar.default.two" (func $export-default/theDefault)) + (start $~start) (func $export/add (param $0 i32) (param $1 i32) (result i32) local.get $0 local.get $1 @@ -30,6 +40,78 @@ local.get $1 i32.mul ) + (func $exports/Car#constructor (result i32) + (local $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.tee $1 + i32.const 16 + i32.add + local.tee $0 + memory.size + local.tee $3 + i32.const 16 + i32.shl + local.tee $2 + i32.gt_u + if + local.get $3 + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const -65536 + i32.and + i32.const 16 + i32.shr_u + local.tee $2 + local.get $3 + local.get $2 + i32.gt_s + select + memory.grow + i32.const 0 + i32.lt_s + if + local.get $2 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + local.get $1 + i32.const 16 + i32.sub + local.tee $0 + i32.const 16 + i32.store + local.get $0 + i32.const 1 + i32.store offset=4 + local.get $0 + i32.const 3 + i32.store offset=8 + local.get $0 + i32.const 4 + i32.store offset=12 + local.get $1 + i32.const 2 + i32.store + local.get $1 + i32.const 2 + i32.store + local.get $1 + ) (func $export-default/theDefault nop ) @@ -38,4 +120,50 @@ local.get $1 i32.sub ) + (func $~start + i32.const 1120 + global.set $~lib/rt/stub/offset + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1040 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $exports/Car#constructor + global.set $rereexport/car + global.get $rereexport/car + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1088 + i32.const 18 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + call $exports/Car#constructor + global.set $rereexport/exportsNamespaceCar + global.get $rereexport/exportsNamespaceCar + i32.load + i32.const 2 + i32.ne + if + i32.const 0 + i32.const 1088 + i32.const 24 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + ) ) diff --git a/tests/compiler/rereexport.ts b/tests/compiler/rereexport.ts index 29aeb41abe..b8a00c451c 100644 --- a/tests/compiler/rereexport.ts +++ b/tests/compiler/rereexport.ts @@ -9,3 +9,18 @@ export { import { exportstar } from "./reexport"; export { exportstar }; + +import * as ReexportsNamespace from "./reexport"; +// Test our import * as namespace works with different types +assert(ReexportsNamespace.add(2, 2) == 4); +assert(ReexportsNamespace.rerenamed_mul(2, 2) == 4); +let car: ReexportsNamespace.Car = new ReexportsNamespace.Car(); +assert(car.numDoors == 2); + +// Test our imported namespace with the exported import * as namespace +assert(ReexportsNamespace.ExportsNamespace.add(2, 2) == 4); +assert(ReexportsNamespace.ExportsNamespace.renamed_mul(2, 2) == 4); +let exportsNamespaceCar: ReexportsNamespace.Car = new ReexportsNamespace.ExportsNamespace.Car(); +assert(exportsNamespaceCar.numDoors == 2); + + diff --git a/tests/compiler/rereexport.untouched.wat b/tests/compiler/rereexport.untouched.wat index dd449374cc..97762fb368 100644 --- a/tests/compiler/rereexport.untouched.wat +++ b/tests/compiler/rereexport.untouched.wat @@ -1,11 +1,26 @@ (module (type $none_=>_none (func)) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (memory $0 0) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_=>_none (func (param i32))) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (memory $0 1) + (data (i32.const 16) "\16\00\00\00\01\00\00\00\01\00\00\00\16\00\00\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s\00") + (data (i32.const 64) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00r\00e\00r\00e\00e\00x\00p\00o\00r\00t\00.\00t\00s\00") (table $0 1 funcref) (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (global $export/c i32 (i32.const 3)) + (global $exports/Car.TIRES i32 (i32.const 4)) + (global $exports/vehicles.Car.TIRES i32 (i32.const 4)) + (global $exports/outer.inner.a i32 (i32.const 42)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $reexport/car (mut i32) (i32.const 0)) + (global $rereexport/car (mut i32) (i32.const 0)) + (global $rereexport/exportsNamespaceCar (mut i32) (i32.const 0)) + (global $~lib/heap/__heap_base i32 (i32.const 108)) (export "memory" (memory $0)) (export "a" (global $export/a)) (export "renamed_a" (global $export/a)) @@ -32,6 +47,145 @@ local.get $1 i32.mul ) + (func $exports/add (param $0 i32) (param $1 i32) (result i32) + local.get $0 + local.get $1 + i32.add + ) + (func $~lib/rt/stub/maybeGrowMemory (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + memory.size + local.set $1 + local.get $1 + i32.const 16 + i32.shl + local.set $2 + local.get $0 + local.get $2 + i32.gt_u + if + local.get $0 + local.get $2 + i32.sub + i32.const 65535 + i32.add + i32.const 65535 + i32.const -1 + i32.xor + i32.and + i32.const 16 + i32.shr_u + local.set $3 + local.get $1 + local.tee $4 + local.get $3 + local.tee $5 + local.get $4 + local.get $5 + i32.gt_s + select + local.set $4 + local.get $4 + memory.grow + i32.const 0 + i32.lt_s + if + local.get $3 + memory.grow + i32.const 0 + i32.lt_s + if + unreachable + end + end + end + local.get $0 + global.set $~lib/rt/stub/offset + ) + (func $~lib/rt/stub/__alloc (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) + (local $3 i32) + (local $4 i32) + (local $5 i32) + (local $6 i32) + local.get $0 + i32.const 1073741808 + i32.gt_u + if + unreachable + end + global.get $~lib/rt/stub/offset + i32.const 16 + i32.add + local.set $2 + local.get $0 + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + local.tee $3 + i32.const 16 + local.tee $4 + local.get $3 + local.get $4 + i32.gt_u + select + local.set $5 + local.get $2 + local.get $5 + i32.add + call $~lib/rt/stub/maybeGrowMemory + local.get $2 + i32.const 16 + i32.sub + local.set $6 + local.get $6 + local.get $5 + i32.store + i32.const 1 + drop + local.get $6 + i32.const 1 + i32.store offset=4 + local.get $6 + local.get $1 + i32.store offset=8 + local.get $6 + local.get $0 + i32.store offset=12 + local.get $2 + ) + (func $~lib/rt/stub/__retain (param $0 i32) (result i32) + local.get $0 + ) + (func $exports/Car#constructor (param $0 i32) (param $1 i32) (result i32) + local.get $0 + i32.eqz + if + i32.const 4 + i32.const 3 + call $~lib/rt/stub/__alloc + call $~lib/rt/stub/__retain + local.set $0 + end + local.get $0 + local.get $1 + i32.store + local.get $0 + local.get $1 + i32.store + local.get $0 + ) + (func $exports/Car#get:numDoors (param $0 i32) (result i32) + local.get $0 + i32.load + ) (func $start:reexport i32.const 1 i32.const 2 @@ -41,9 +195,154 @@ call $export/mul i32.add drop + i32.const 2 + i32.const 2 + call $exports/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 37 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 38 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + global.get $~lib/heap/__heap_base + i32.const 15 + i32.add + i32.const 15 + i32.const -1 + i32.xor + i32.and + global.set $~lib/rt/stub/startOffset + global.get $~lib/rt/stub/startOffset + global.set $~lib/rt/stub/offset + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $reexport/car + global.get $reexport/car + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 32 + i32.const 40 + i32.const 1 + call $~lib/builtins/abort + unreachable + end ) (func $start:rereexport call $start:reexport + i32.const 2 + i32.const 2 + call $export/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 15 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 16 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $rereexport/car + global.get $rereexport/car + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 18 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $exports/add + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 21 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 2 + i32.const 2 + call $export/mul + i32.const 4 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 22 + i32.const 1 + call $~lib/builtins/abort + unreachable + end + i32.const 0 + i32.const 2 + call $exports/Car#constructor + global.set $rereexport/exportsNamespaceCar + global.get $rereexport/exportsNamespaceCar + call $exports/Car#get:numDoors + i32.const 2 + i32.eq + i32.eqz + if + i32.const 0 + i32.const 80 + i32.const 24 + i32.const 1 + call $~lib/builtins/abort + unreachable + end ) (func $export-default/theDefault nop