Link globals into global scope instead

This commit is contained in:
dcodeIO
2017-12-16 20:08:33 +01:00
parent 2720515982
commit c70eb7792f
5 changed files with 72 additions and 37 deletions

View File

@ -222,6 +222,13 @@ export class Program extends DiagnosticEmitter {
const prototype: ClassPrototype = new ClassPrototype(this, declaration.identifier.name, internalName, declaration); const prototype: ClassPrototype = new ClassPrototype(this, declaration.identifier.name, internalName, declaration);
this.elements.set(internalName, prototype); 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) {
if (namespace.members) { if (namespace.members) {
if (namespace.members.has(declaration.identifier.name)) { 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); const prototype: FunctionPrototype = new FunctionPrototype(this, declaration.identifier.name, internalName, declaration, null);
this.elements.set(internalName, prototype); 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) {
if (namespace.members) { if (namespace.members) {
if (namespace.members.has(declaration.identifier.name)) { 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); const global: Global = new Global(this, internalName, declaration, null);
this.elements.set(internalName, global); 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) {
if (namespace.members) { if (namespace.members) {
if (namespace.members.has(declaration.identifier.name)) { if (namespace.members.has(declaration.identifier.name)) {

View File

@ -49,29 +49,36 @@
isize isize
usize usize
HEAP_BASE HEAP_BASE
array/Array
Array Array
error/Error
Error Error
error/RangeError
RangeError RangeError
heap/ALIGN_LOG2 heap/ALIGN_LOG2
heap/ALIGN_SIZE heap/ALIGN_SIZE
heap/ALIGN_MASK heap/ALIGN_MASK
heap/HEAP_OFFSET heap/HEAP_OFFSET
heap/Heap
Heap Heap
Heap.get_used heap/Heap.get_used
Heap.get_free heap/Heap.get_free
Heap.get_size heap/Heap.get_size
Heap.allocate heap/Heap.allocate
Heap.dispose heap/Heap.dispose
Heap.copy heap/Heap.copy
map/Map
Map Map
set/Set
Set Set
string/String
String String
[program.exports] [program.exports]
Array array/Array
Error error/Error
RangeError error/RangeError
Heap heap/Heap
Map map/Map
Set set/Set
String string/String
;) ;)

View File

@ -8,7 +8,7 @@
(memory $0 1) (memory $0 1)
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start) (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 $1 i32)
(local $2 i32) (local $2 i32)
(if (if
@ -103,12 +103,12 @@
(get_global $HEAP_BASE) (get_global $HEAP_BASE)
) )
(set_global $std/heap/ptr (set_global $std/heap/ptr
(call $Heap.allocate (call $heap/Heap.allocate
(i32.const 10) (i32.const 10)
) )
) )
(block (block
(block $__inlined_func$Heap.dispose (block $__inlined_func$heap/Heap.dispose
(set_local $0 (set_local $0
(get_global $std/heap/ptr) (get_global $std/heap/ptr)
) )

View File

@ -8,7 +8,7 @@
(memory $0 1) (memory $0 1)
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start) (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 $1 i32)
(local $2 i32) (local $2 i32)
(if (if
@ -97,7 +97,7 @@
) )
(get_local $1) (get_local $1)
) )
(func $Heap.dispose (; 1 ;) (type $iv) (param $0 i32) (func $heap/Heap.dispose (; 1 ;) (type $iv) (param $0 i32)
(nop) (nop)
) )
(func $start (; 2 ;) (type $v) (func $start (; 2 ;) (type $v)
@ -105,11 +105,11 @@
(get_global $HEAP_BASE) (get_global $HEAP_BASE)
) )
(set_global $std/heap/ptr (set_global $std/heap/ptr
(call $Heap.allocate (call $heap/Heap.allocate
(i32.const 10) (i32.const 10)
) )
) )
(call $Heap.dispose (call $heap/Heap.dispose
(get_global $std/heap/ptr) (get_global $std/heap/ptr)
) )
) )

View File

@ -12,7 +12,7 @@
(memory $0 1) (memory $0 1)
(export "memory" (memory $0)) (export "memory" (memory $0))
(start $start) (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 $1 i32)
(local $2 i32) (local $2 i32)
(local $3 i32) (local $3 i32)
@ -109,18 +109,18 @@
(get_local $4) (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) (func $start (; 2 ;) (type $v)
(set_global $heap/HEAP_OFFSET (set_global $heap/HEAP_OFFSET
(get_global $HEAP_BASE) (get_global $HEAP_BASE)
) )
(set_global $std/heap/ptr (set_global $std/heap/ptr
(call $Heap.allocate (call $heap/Heap.allocate
(i32.const 10) (i32.const 10)
) )
) )
(call $Heap.dispose (call $heap/Heap.dispose
(get_global $std/heap/ptr) (get_global $std/heap/ptr)
) )
) )
@ -171,30 +171,37 @@
isize isize
usize usize
HEAP_BASE HEAP_BASE
array/Array
Array Array
error/Error
Error Error
error/RangeError
RangeError RangeError
heap/ALIGN_LOG2 heap/ALIGN_LOG2
heap/ALIGN_SIZE heap/ALIGN_SIZE
heap/ALIGN_MASK heap/ALIGN_MASK
heap/HEAP_OFFSET heap/HEAP_OFFSET
heap/Heap
Heap Heap
Heap.get_used heap/Heap.get_used
Heap.get_free heap/Heap.get_free
Heap.get_size heap/Heap.get_size
Heap.allocate heap/Heap.allocate
Heap.dispose heap/Heap.dispose
Heap.copy heap/Heap.copy
map/Map
Map Map
set/Set
Set Set
string/String
String String
std/heap/ptr std/heap/ptr
[program.exports] [program.exports]
Array array/Array
Error error/Error
RangeError error/RangeError
Heap heap/Heap
Map map/Map
Set set/Set
String string/String
;) ;)