Namespaces

This commit is contained in:
dcodeIO
2017-12-13 23:24:13 +01:00
parent 7d85b0cc7f
commit 99b0fdf7a8
30 changed files with 514 additions and 128 deletions

View File

@ -1,5 +1,6 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(memory $0 1)
@ -7,6 +8,7 @@
(export "renamed_sub" (func $export/sub))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
@ -20,4 +22,7 @@
(get_local $1)
)
)
(func $export/ns.two (; 2 ;) (type $v)
(nop)
)
)

View File

@ -14,7 +14,7 @@ const b: i32 = 2;
export { b as renamed_b };
/* export namespace ns {
export namespace ns {
function one(): void {}
export function two(): void {}
} */
}

View File

@ -1,5 +1,6 @@
(module
(type $iii (func (param i32 i32) (result i32)))
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $HEAP_START i32 (i32.const 4))
@ -8,6 +9,7 @@
(export "renamed_sub" (func $export/sub))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
@ -25,6 +27,8 @@
)
)
)
(func $export/ns.two (; 2 ;) (type $v)
)
)
(;
[program.elements]
@ -60,9 +64,13 @@
export/sub
export/a
export/b
export/ns
export/ns.one
export/ns.two
[program.exports]
export/add
export/renamed_sub
export/a
export/renamed_b
export/ns
;)

View File

@ -41,5 +41,10 @@
)
)
)
(block
(block $__inlined_func$export/ns.two
(nop)
)
)
)
)

View File

@ -16,7 +16,10 @@
(get_local $1)
)
)
(func $start (; 2 ;) (type $v)
(func $export/ns.two (; 2 ;) (type $v)
(nop)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.add
(call $export/add
@ -29,5 +32,6 @@
)
)
)
(call $export/ns.two)
)
)

View File

@ -1,3 +1,5 @@
import { add, renamed_sub as sub, a, renamed_b as b } from "./export";
import { add, renamed_sub as sub, a, renamed_b as b, ns as renamed_ns } from "./export";
add(a, b) + sub(b, a);
renamed_ns.two();

View File

@ -23,7 +23,9 @@
)
)
)
(func $start (; 2 ;) (type $v)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.add
(call $export/add
@ -36,6 +38,7 @@
)
)
)
(call $export/ns.two)
)
)
(;
@ -72,13 +75,18 @@
export/sub
export/a
export/b
export/ns
export/ns.one
export/ns.two
import/add
import/sub
import/a
import/b
import/renamed_ns
[program.exports]
export/add
export/renamed_sub
export/a
export/renamed_b
export/ns
;)

View File

@ -0,0 +1,11 @@
(module
(type $v (func))
(memory $0 1)
(export "test" (func $namespace/test))
(export "memory" (memory $0))
(func $namespace/test (; 0 ;) (type $v)
(block $__inlined_func$namespace/Outer.Inner.aFunc
(nop)
)
)
)

View File

@ -0,0 +1,12 @@
(module
(type $v (func))
(memory $0 1)
(export "test" (func $namespace/test))
(export "memory" (memory $0))
(func $namespace/Outer.Inner.aFunc (; 0 ;) (type $v)
(nop)
)
(func $namespace/test (; 1 ;) (type $v)
(call $namespace/Outer.Inner.aFunc)
)
)

View File

@ -0,0 +1,13 @@
namespace Outer {
export namespace Inner {
export let aVar: i32;
export function aFunc(): void {}
export enum anEnum { ONE = 1 }
}
}
export function test(): void {
Outer.Inner.aVar;
Outer.Inner.aFunc();
Outer.Inner.anEnum.ONE;
}

View File

@ -0,0 +1,58 @@
(module
(type $v (func))
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
(global $HEAP_START i32 (i32.const 4))
(memory $0 1)
(export "test" (func $namespace/test))
(export "memory" (memory $0))
(func $namespace/Outer.Inner.aFunc (; 0 ;) (type $v)
)
(func $namespace/test (; 1 ;) (type $v)
(drop
(get_global $namespace/Outer.Inner.aVar)
)
(call $namespace/Outer.Inner.aFunc)
(drop
(get_global $namespace/Outer.Inner.anEnum.ONE)
)
)
)
(;
[program.elements]
clz
ctz
popcnt
rotl
rotr
abs
ceil
copysign
floor
max
min
nearest
sqrt
trunc
current_memory
grow_memory
unreachable
load
store
reinterpret
select
sizeof
changetype
isNaN
isFinite
assert
parseInt
parseFloat
namespace/Outer
namespace/Outer.Inner
namespace/Outer.Inner.aVar
namespace/Outer.Inner.aFunc
namespace/Outer.Inner.anEnum
namespace/test
[program.exports]
namespace/test
;)

View File

@ -1,7 +1,9 @@
export { add, renamed_sub, a as renamed_a, renamed_b as rerenamed_b } from "./export";
import { add as imported_add, renamed_sub as imported_sub } from "./export";
import { add as imported_add, renamed_sub as imported_sub, ns as imported_ns } from "./export";
export { imported_add as renamed_add, imported_sub as rerenamed_sub };
imported_add(1, 2) + imported_sub(3, 4);
export { ns as renamed_ns } from "./export";

View File

@ -29,7 +29,9 @@
)
)
)
(func $start (; 2 ;) (type $v)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.add
(call $export/add
@ -78,17 +80,23 @@
export/sub
export/a
export/b
export/ns
export/ns.one
export/ns.two
reexport/imported_add
reexport/imported_sub
reexport/imported_ns
[program.exports]
export/add
export/renamed_sub
export/a
export/renamed_b
export/ns
reexport/add
reexport/renamed_sub
reexport/renamed_a
reexport/rerenamed_b
reexport/renamed_add
reexport/rerenamed_sub
reexport/renamed_ns
;)

11
tests/parser/namespace.ts Normal file
View File

@ -0,0 +1,11 @@
declare namespace A {
namespace B {
export namespace C {
let aVar: i32;
const aConst: i32;
function aFunc(): void {}
enum AnEnum {}
class AClass {}
}
}
}

View File

@ -0,0 +1,15 @@
declare namespace A {
namespace B {
export namespace C {
let aVar: i32;
const aConst: i32;
function aFunc(): void {
}
enum AnEnum {
}
class AClass {
}
}
}
}

3
tests/parser/var.ts Normal file
View File

@ -0,0 +1,3 @@
var a: i32;
let b: i32;
const c: i32;

View File

@ -0,0 +1,3 @@
let a: i32;
let b: i32;
const c: i32;