Initial support for default imports/exports, see #98

Does not implement combinations like 'import theDefault, *' yet
This commit is contained in:
dcode
2019-06-04 08:55:22 +02:00
parent 27e54ed07b
commit fa667386d9
20 changed files with 336 additions and 73 deletions

View File

@ -1,6 +1,6 @@
{
"asc_flags": [
"--runtime none",
"--runtime half",
"--use ASC_RTRACE=1"
]
}

View File

@ -0,0 +1,5 @@
{
"asc_flags": [
"--runtime none"
]
}

View File

@ -0,0 +1,10 @@
(module
(type $FUNCSIG$v (func))
(memory $0 0)
(export "memory" (memory $0))
(export "theDefault" (func $export-default/theDefault))
(export "default" (func $export-default/theDefault))
(func $export-default/theDefault (; 0 ;) (type $FUNCSIG$v)
nop
)
)

View File

@ -0,0 +1 @@
export default function theDefault(): void {}

View File

@ -0,0 +1,14 @@
(module
(type $FUNCSIG$v (func))
(memory $0 0)
(table $0 1 funcref)
(elem (i32.const 0) $null)
(export "memory" (memory $0))
(export "theDefault" (func $export-default/theDefault))
(export "default" (func $export-default/theDefault))
(func $export-default/theDefault (; 0 ;) (type $FUNCSIG$v)
nop
)
(func $null (; 1 ;) (type $FUNCSIG$v)
)
)

View File

@ -13,6 +13,7 @@
(export "b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "ns.two" (func $export/ns.one))
(export "default.two" (func $export/ns.one))
(func $export/add (; 0 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
local.get $0
local.get $1

View File

@ -28,3 +28,5 @@ export namespace ns {
function one(): void {}
export function two(): void {}
}
export default ns;

View File

@ -15,6 +15,7 @@
(export "b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "ns.two" (func $export/ns.two))
(export "default.two" (func $export/ns.two))
(func $export/add (; 0 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
local.get $0
local.get $1

View File

@ -21,3 +21,11 @@ other.sub(other.b, other.renamed_c) +
other.renamed_mul(other.renamed_c, other.a);
other.ns.two();
import theDefault from "./export";
theDefault.two();
import theOtherDefault from "./export-default";
theOtherDefault();

View File

@ -27,37 +27,42 @@
(func $export/ns.two (; 3 ;) (type $FUNCSIG$v)
nop
)
(func $start:import (; 4 ;) (type $FUNCSIG$v)
global.get $export/a
global.get $export/b
call $export/add
global.get $export/b
global.get $export/c
call $export/sub
i32.add
global.get $export/c
global.get $export/a
call $export/mul
i32.add
drop
call $export/ns.two
global.get $export/a
global.get $export/b
call $export/add
global.get $export/b
global.get $export/c
call $export/sub
i32.add
global.get $export/c
global.get $export/a
call $export/mul
i32.add
drop
call $export/ns.two
(func $export-default/theDefault (; 4 ;) (type $FUNCSIG$v)
nop
)
(func $start (; 5 ;) (type $FUNCSIG$v)
(func $start:import (; 5 ;) (type $FUNCSIG$v)
global.get $export/a
global.get $export/b
call $export/add
global.get $export/b
global.get $export/c
call $export/sub
i32.add
global.get $export/c
global.get $export/a
call $export/mul
i32.add
drop
call $export/ns.two
global.get $export/a
global.get $export/b
call $export/add
global.get $export/b
global.get $export/c
call $export/sub
i32.add
global.get $export/c
global.get $export/a
call $export/mul
i32.add
drop
call $export/ns.two
call $export/ns.two
call $export-default/theDefault
)
(func $start (; 6 ;) (type $FUNCSIG$v)
call $start:import
)
(func $null (; 6 ;) (type $FUNCSIG$v)
(func $null (; 7 ;) (type $FUNCSIG$v)
)
)