mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 07:21:30 +00:00
Namespaces
This commit is contained in:
@ -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)
|
||||
)
|
||||
)
|
||||
|
@ -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 {}
|
||||
} */
|
||||
}
|
||||
|
@ -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
|
||||
;)
|
||||
|
@ -41,5 +41,10 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(block $__inlined_func$export/ns.two
|
||||
(nop)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -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)
|
||||
)
|
||||
)
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
;)
|
||||
|
11
tests/compiler/namespace.optimized-inlined.wast
Normal file
11
tests/compiler/namespace.optimized-inlined.wast
Normal 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)
|
||||
)
|
||||
)
|
||||
)
|
12
tests/compiler/namespace.optimized.wast
Normal file
12
tests/compiler/namespace.optimized.wast
Normal 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)
|
||||
)
|
||||
)
|
13
tests/compiler/namespace.ts
Normal file
13
tests/compiler/namespace.ts
Normal 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;
|
||||
}
|
58
tests/compiler/namespace.wast
Normal file
58
tests/compiler/namespace.wast
Normal 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
|
||||
;)
|
@ -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";
|
||||
|
@ -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
11
tests/parser/namespace.ts
Normal 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 {}
|
||||
}
|
||||
}
|
||||
}
|
15
tests/parser/namespace.ts.fixture.ts
Normal file
15
tests/parser/namespace.ts.fixture.ts
Normal 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
3
tests/parser/var.ts
Normal file
@ -0,0 +1,3 @@
|
||||
var a: i32;
|
||||
let b: i32;
|
||||
const c: i32;
|
3
tests/parser/var.ts.fixture.ts
Normal file
3
tests/parser/var.ts.fixture.ts
Normal file
@ -0,0 +1,3 @@
|
||||
let a: i32;
|
||||
let b: i32;
|
||||
const c: i32;
|
Reference in New Issue
Block a user