diff --git a/src/program.ts b/src/program.ts index 0a4c7963..024f09f4 100644 --- a/src/program.ts +++ b/src/program.ts @@ -222,6 +222,13 @@ export class Program extends DiagnosticEmitter { const prototype: ClassPrototype = new ClassPrototype(this, declaration.identifier.name, internalName, declaration); this.elements.set(internalName, prototype); + if (hasDecorator("global", declaration.decorators)) { + if (this.elements.has(declaration.identifier.name)) + this.error(DiagnosticCode.Duplicate_identifier_0, declaration.identifier.range, internalName); + else + this.elements.set(declaration.identifier.name, prototype); + } + if (namespace) { if (namespace.members) { if (namespace.members.has(declaration.identifier.name)) { @@ -461,6 +468,13 @@ export class Program extends DiagnosticEmitter { const prototype: FunctionPrototype = new FunctionPrototype(this, declaration.identifier.name, internalName, declaration, null); this.elements.set(internalName, prototype); + if (hasDecorator("global", declaration.decorators)) { + if (this.elements.has(declaration.identifier.name)) + this.error(DiagnosticCode.Duplicate_identifier_0, declaration.identifier.range, internalName); + else + this.elements.set(declaration.identifier.name, prototype); + } + if (namespace) { if (namespace.members) { if (namespace.members.has(declaration.identifier.name)) { @@ -650,6 +664,13 @@ export class Program extends DiagnosticEmitter { const global: Global = new Global(this, internalName, declaration, null); this.elements.set(internalName, global); + if (hasDecorator("global", declaration.decorators)) { + if (this.elements.has(declaration.identifier.name)) + this.error(DiagnosticCode.Duplicate_identifier_0, declaration.identifier.range, internalName); + else + this.elements.set(declaration.identifier.name, global); + } + if (namespace) { if (namespace.members) { if (namespace.members.has(declaration.identifier.name)) { diff --git a/tests/compiler/std/array.wast b/tests/compiler/std/array.wast index 56df39cc..f3e04e4c 100644 --- a/tests/compiler/std/array.wast +++ b/tests/compiler/std/array.wast @@ -49,29 +49,36 @@ isize usize HEAP_BASE + array/Array Array + error/Error Error + error/RangeError RangeError heap/ALIGN_LOG2 heap/ALIGN_SIZE heap/ALIGN_MASK heap/HEAP_OFFSET + heap/Heap Heap - Heap.get_used - Heap.get_free - Heap.get_size - Heap.allocate - Heap.dispose - Heap.copy + heap/Heap.get_used + heap/Heap.get_free + heap/Heap.get_size + heap/Heap.allocate + heap/Heap.dispose + heap/Heap.copy + map/Map Map + set/Set Set + string/String String [program.exports] - Array - Error - RangeError - Heap - Map - Set - String + array/Array + error/Error + error/RangeError + heap/Heap + map/Map + set/Set + string/String ;) diff --git a/tests/compiler/std/heap.optimized-inlined.wast b/tests/compiler/std/heap.optimized-inlined.wast index 131a40fc..74f402ca 100644 --- a/tests/compiler/std/heap.optimized-inlined.wast +++ b/tests/compiler/std/heap.optimized-inlined.wast @@ -8,7 +8,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -103,12 +103,12 @@ (get_global $HEAP_BASE) ) (set_global $std/heap/ptr - (call $Heap.allocate + (call $heap/Heap.allocate (i32.const 10) ) ) (block - (block $__inlined_func$Heap.dispose + (block $__inlined_func$heap/Heap.dispose (set_local $0 (get_global $std/heap/ptr) ) diff --git a/tests/compiler/std/heap.optimized.wast b/tests/compiler/std/heap.optimized.wast index d9bf10eb..3e61b325 100644 --- a/tests/compiler/std/heap.optimized.wast +++ b/tests/compiler/std/heap.optimized.wast @@ -8,7 +8,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (if @@ -97,7 +97,7 @@ ) (get_local $1) ) - (func $Heap.dispose (; 1 ;) (type $iv) (param $0 i32) + (func $heap/Heap.dispose (; 1 ;) (type $iv) (param $0 i32) (nop) ) (func $start (; 2 ;) (type $v) @@ -105,11 +105,11 @@ (get_global $HEAP_BASE) ) (set_global $std/heap/ptr - (call $Heap.allocate + (call $heap/Heap.allocate (i32.const 10) ) ) - (call $Heap.dispose + (call $heap/Heap.dispose (get_global $std/heap/ptr) ) ) diff --git a/tests/compiler/std/heap.wast b/tests/compiler/std/heap.wast index 290afa40..deca6c3c 100644 --- a/tests/compiler/std/heap.wast +++ b/tests/compiler/std/heap.wast @@ -12,7 +12,7 @@ (memory $0 1) (export "memory" (memory $0)) (start $start) - (func $Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) + (func $heap/Heap.allocate (; 0 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -109,18 +109,18 @@ (get_local $4) ) ) - (func $Heap.dispose (; 1 ;) (type $iv) (param $0 i32) + (func $heap/Heap.dispose (; 1 ;) (type $iv) (param $0 i32) ) (func $start (; 2 ;) (type $v) (set_global $heap/HEAP_OFFSET (get_global $HEAP_BASE) ) (set_global $std/heap/ptr - (call $Heap.allocate + (call $heap/Heap.allocate (i32.const 10) ) ) - (call $Heap.dispose + (call $heap/Heap.dispose (get_global $std/heap/ptr) ) ) @@ -171,30 +171,37 @@ isize usize HEAP_BASE + array/Array Array + error/Error Error + error/RangeError RangeError heap/ALIGN_LOG2 heap/ALIGN_SIZE heap/ALIGN_MASK heap/HEAP_OFFSET + heap/Heap Heap - Heap.get_used - Heap.get_free - Heap.get_size - Heap.allocate - Heap.dispose - Heap.copy + heap/Heap.get_used + heap/Heap.get_free + heap/Heap.get_size + heap/Heap.allocate + heap/Heap.dispose + heap/Heap.copy + map/Map Map + set/Set Set + string/String String std/heap/ptr [program.exports] - Array - Error - RangeError - Heap - Map - Set - String + array/Array + error/Error + error/RangeError + heap/Heap + map/Map + set/Set + string/String ;)