mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 15:31:31 +00:00
Namespaced imports
This commit is contained in:
@ -61,7 +61,12 @@ glob.sync(filter, { cwd: __dirname + "/compiler" }).forEach(filename => {
|
||||
var wasmModule = new WebAssembly.Module(module.toBinary());
|
||||
var wasmInstance = new WebAssembly.Instance(wasmModule, {
|
||||
env: {
|
||||
external: function() {}
|
||||
externalFunc: function() {},
|
||||
externalConst: 1
|
||||
},
|
||||
external: {
|
||||
externalFunc: function() {},
|
||||
externalConst: 2
|
||||
}
|
||||
});
|
||||
console.log(chalk.default.green("instantiate OK"));
|
||||
|
@ -1,7 +1,12 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(import "env" "external" (func $declare/external))
|
||||
(import "env" "externalFunc" (func $declare/externalFunc))
|
||||
(import "external" "externalFunc" (func $declare/external.externalFunc))
|
||||
(memory $0 1)
|
||||
(export "external" (func $declare/external))
|
||||
(export "test" (func $declare/test))
|
||||
(export "memory" (memory $0))
|
||||
(func $declare/test (; 2 ;) (type $v)
|
||||
(call $declare/externalFunc)
|
||||
(call $declare/external.externalFunc)
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,15 @@
|
||||
declare function external(): void;
|
||||
declare function externalFunc(): void;
|
||||
declare const externalConst: i32;
|
||||
|
||||
export { external };
|
||||
namespace external {
|
||||
export declare function externalFunc(): void;
|
||||
export declare const externalConst: i32;
|
||||
}
|
||||
|
||||
export function test(): void {
|
||||
// cannot be interpreted
|
||||
externalFunc();
|
||||
externalConst;
|
||||
external.externalFunc();
|
||||
external.externalConst;
|
||||
}
|
||||
|
@ -1,10 +1,23 @@
|
||||
(module
|
||||
(type $v (func))
|
||||
(import "env" "external" (func $declare/external))
|
||||
(import "env" "externalFunc" (func $declare/externalFunc))
|
||||
(import "env" "externalConst" (global $declare/externalConst i32))
|
||||
(import "external" "externalFunc" (func $declare/external.externalFunc))
|
||||
(import "external" "externalConst" (global $declare/external.externalConst i32))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
(export "external" (func $declare/external))
|
||||
(export "test" (func $declare/test))
|
||||
(export "memory" (memory $0))
|
||||
(func $declare/test (; 2 ;) (type $v)
|
||||
(call $declare/externalFunc)
|
||||
(drop
|
||||
(get_global $declare/externalConst)
|
||||
)
|
||||
(call $declare/external.externalFunc)
|
||||
(drop
|
||||
(get_global $declare/external.externalConst)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
[program.elements]
|
||||
@ -52,7 +65,12 @@
|
||||
FUNCTION_PROTOTYPE: isize
|
||||
FUNCTION_PROTOTYPE: usize
|
||||
GLOBAL: HEAP_BASE
|
||||
FUNCTION_PROTOTYPE: declare/external
|
||||
FUNCTION_PROTOTYPE: declare/externalFunc
|
||||
GLOBAL: declare/externalConst
|
||||
NAMESPACE: declare/external
|
||||
FUNCTION_PROTOTYPE: declare/external.externalFunc
|
||||
GLOBAL: declare/external.externalConst
|
||||
FUNCTION_PROTOTYPE: declare/test
|
||||
[program.exports]
|
||||
FUNCTION_PROTOTYPE: declare/external
|
||||
FUNCTION_PROTOTYPE: declare/test
|
||||
;)
|
||||
|
@ -2,6 +2,7 @@
|
||||
(type $i (func (result i32)))
|
||||
(type $v (func))
|
||||
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
||||
(global $namespace/Joined.THREE i32 (i32.const 3))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
@ -13,5 +14,12 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(drop
|
||||
(block (result i32)
|
||||
(block $__inlined_func$namespace/Joined.anotherFunc (result i32)
|
||||
(get_global $namespace/Joined.THREE)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -2,15 +2,22 @@
|
||||
(type $i (func (result i32)))
|
||||
(type $v (func))
|
||||
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
||||
(global $namespace/Joined.THREE i32 (i32.const 3))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
(start $start)
|
||||
(func $namespace/Outer.Inner.aFunc (; 0 ;) (type $i) (result i32)
|
||||
(get_global $namespace/Outer.Inner.aVar)
|
||||
)
|
||||
(func $start (; 1 ;) (type $v)
|
||||
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
||||
(get_global $namespace/Joined.THREE)
|
||||
)
|
||||
(func $start (; 2 ;) (type $v)
|
||||
(drop
|
||||
(call $namespace/Outer.Inner.aFunc)
|
||||
)
|
||||
(drop
|
||||
(call $namespace/Joined.anotherFunc)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -9,3 +9,12 @@ namespace Outer {
|
||||
Outer.Inner.aVar;
|
||||
Outer.Inner.aFunc();
|
||||
Outer.Inner.anEnum.ONE;
|
||||
|
||||
enum Joined {
|
||||
THREE = 3
|
||||
}
|
||||
namespace Joined {
|
||||
export function anotherFunc(): i32 { return Joined.THREE; }
|
||||
}
|
||||
|
||||
Joined.anotherFunc();
|
||||
|
@ -4,6 +4,7 @@
|
||||
(global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0))
|
||||
(global $namespace/Outer.Inner.anEnum.ONE i32 (i32.const 1))
|
||||
(global $namespace/Outer.Inner.anEnum.TWO i32 (i32.const 2))
|
||||
(global $namespace/Joined.THREE i32 (i32.const 3))
|
||||
(global $HEAP_BASE i32 (i32.const 4))
|
||||
(memory $0 1)
|
||||
(export "memory" (memory $0))
|
||||
@ -13,7 +14,12 @@
|
||||
(get_global $namespace/Outer.Inner.aVar)
|
||||
)
|
||||
)
|
||||
(func $start (; 1 ;) (type $v)
|
||||
(func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32)
|
||||
(return
|
||||
(get_global $namespace/Joined.THREE)
|
||||
)
|
||||
)
|
||||
(func $start (; 2 ;) (type $v)
|
||||
(drop
|
||||
(get_global $namespace/Outer.Inner.aVar)
|
||||
)
|
||||
@ -23,6 +29,9 @@
|
||||
(drop
|
||||
(get_global $namespace/Outer.Inner.anEnum.ONE)
|
||||
)
|
||||
(drop
|
||||
(call $namespace/Joined.anotherFunc)
|
||||
)
|
||||
)
|
||||
)
|
||||
(;
|
||||
@ -76,6 +85,8 @@
|
||||
GLOBAL: namespace/Outer.Inner.aVar
|
||||
FUNCTION_PROTOTYPE: namespace/Outer.Inner.aFunc
|
||||
ENUM: namespace/Outer.Inner.anEnum
|
||||
ENUM: namespace/Joined
|
||||
FUNCTION_PROTOTYPE: namespace/Joined.anotherFunc
|
||||
[program.exports]
|
||||
|
||||
;)
|
||||
|
Reference in New Issue
Block a user