Initial implementation if ugc, see #16; Fix tests

This commit is contained in:
dcodeIO
2018-01-18 01:46:41 +01:00
parent 461daab2a2
commit 9cdfa35938
24 changed files with 715 additions and 173 deletions

View File

@ -3,14 +3,16 @@
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/c i32 (i32.const 3))
(memory $0 1)
(export "add" (func $export/add))
(export "renamed_sub" (func $export/sub))
(export "sub" (func $export/sub))
(export "renamed_mul" (func $export/mul))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(start $export/ns.two)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(get_local $0)
@ -23,7 +25,13 @@
(get_local $1)
)
)
(func $export/ns.two (; 2 ;) (type $v)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $export/ns.two (; 3 ;) (type $v)
(nop)
)
)

View File

@ -6,14 +6,23 @@ function sub(a: i32, b: i32): i32 {
return a - b;
}
export { sub as renamed_sub };
export { sub };
function mul(a: i32, b: i32): i32 { // not exported as "mul"
return a * b;
}
export { mul as renamed_mul };
export const a: i32 = 1;
const b: i32 = 2;
b;
export { b as renamed_b };
export { b };
const c: i32 = 3; // not exported as "c"
export { c as renamed_c };
export namespace ns {
function one(): void {}

View File

@ -3,15 +3,17 @@
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/c i32 (i32.const 3))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "add" (func $export/add))
(export "renamed_sub" (func $export/sub))
(export "sub" (func $export/sub))
(export "renamed_mul" (func $export/mul))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "two" (func $export/ns.two))
(export "memory" (memory $0))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.add
@ -28,13 +30,16 @@
)
)
)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.mul
(get_local $0)
(get_local $1)
)
)
)
(func $export/ns.two (; 3 ;) (type $v)
)
)
(;
[program.elements]
@ -82,15 +87,19 @@
GLOBAL: HEAP_BASE
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/mul
GLOBAL: export/a
GLOBAL: export/b
GLOBAL: export/c
NAMESPACE: export/ns
FUNCTION_PROTOTYPE: export/ns.one
FUNCTION_PROTOTYPE: export/ns.two
[program.exports]
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/renamed_sub
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/renamed_mul
GLOBAL: export/a
GLOBAL: export/renamed_b
GLOBAL: export/b
GLOBAL: export/renamed_c
NAMESPACE: export/ns
;)

View File

@ -9,33 +9,51 @@
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(drop
(i32.add
(block (result i32)
(block $__inlined_func$export/add (result i32)
(set_local $0
(i32.const 1)
(i32.add
(block (result i32)
(block $__inlined_func$export/add (result i32)
(set_local $0
(i32.const 1)
)
(set_local $1
(i32.const 2)
)
(i32.add
(get_local $0)
(get_local $1)
)
)
(set_local $1
(i32.const 2)
)
(i32.add
(get_local $0)
(get_local $1)
)
(block (result i32)
(block $__inlined_func$export/sub (result i32)
(set_local $2
(i32.const 2)
)
(set_local $3
(i32.const 3)
)
(i32.sub
(get_local $2)
(get_local $3)
)
)
)
)
(block (result i32)
(block $__inlined_func$export/sub (result i32)
(set_local $2
(i32.const 2)
(block $__inlined_func$export/mul (result i32)
(set_local $4
(i32.const 3)
)
(set_local $3
(set_local $5
(i32.const 1)
)
(i32.sub
(get_local $2)
(get_local $3)
(i32.mul
(get_local $4)
(get_local $5)
)
)
)

View File

@ -16,18 +16,30 @@
(get_local $1)
)
)
(func $export/ns.two (; 2 ;) (type $v)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $export/ns.two (; 3 ;) (type $v)
(nop)
)
(func $start (; 3 ;) (type $v)
(func $start (; 4 ;) (type $v)
(drop
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
)
(call $export/sub
(i32.const 2)
(i32.const 3)
)
)
(call $export/sub
(i32.const 2)
(call $export/mul
(i32.const 3)
(i32.const 1)
)
)

View File

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

View File

@ -3,6 +3,7 @@
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/c i32 (i32.const 3))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "memory" (memory $0))
@ -23,20 +24,31 @@
)
)
)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.mul
(get_local $0)
(get_local $1)
)
)
)
(func $export/ns.two (; 3 ;) (type $v)
)
(func $start (; 4 ;) (type $v)
(drop
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
)
(call $export/sub
(i32.const 2)
(i32.const 3)
)
)
(call $export/sub
(i32.const 2)
(call $export/mul
(i32.const 3)
(i32.const 1)
)
)
@ -90,20 +102,26 @@
GLOBAL: HEAP_BASE
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/mul
GLOBAL: export/a
GLOBAL: export/b
GLOBAL: export/c
NAMESPACE: export/ns
FUNCTION_PROTOTYPE: export/ns.one
FUNCTION_PROTOTYPE: export/ns.two
FUNCTION_PROTOTYPE: import/add
FUNCTION_PROTOTYPE: import/sub
FUNCTION_PROTOTYPE: import/mul
GLOBAL: import/a
GLOBAL: import/b
GLOBAL: import/c
NAMESPACE: import/renamed_ns
[program.exports]
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/renamed_sub
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/renamed_mul
GLOBAL: export/a
GLOBAL: export/renamed_b
GLOBAL: export/b
GLOBAL: export/renamed_c
NAMESPACE: export/ns
;)

View File

@ -3,13 +3,18 @@
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/c i32 (i32.const 3))
(memory $0 1)
(export "add" (func $export/add))
(export "renamed_sub" (func $export/sub))
(export "renamed_a" (global $export/a))
(export "rerenamed_b" (global $export/b))
(export "renamed_mul" (func $export/mul))
(export "rerenamed_mul" (func $export/mul))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "rerenamed_c" (global $export/c))
(export "renamed_add" (func $export/add))
(export "rerenamed_sub" (func $export/sub))
(export "rerenamed_sub" (func $export/mul))
(export "memory" (memory $0))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
@ -24,14 +29,20 @@
(get_local $1)
)
)
(func $start (; 2 ;) (type $v)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(i32.mul
(get_local $0)
(get_local $1)
)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
)
(call $export/sub
(call $export/mul
(i32.const 3)
(i32.const 4)
)

View File

@ -1,8 +1,25 @@
export { add, renamed_sub, a as renamed_a, renamed_b as rerenamed_b } from "./export";
export {
add,
sub as renamed_sub,
renamed_mul,
renamed_mul as rerenamed_mul,
import { add as imported_add, renamed_sub as imported_sub, ns as imported_ns } from "./export";
a,
b as renamed_b,
renamed_c,
renamed_c as rerenamed_c
} from "./export";
export { imported_add as renamed_add, imported_sub as rerenamed_sub };
import {
add as imported_add,
renamed_mul 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);

View File

@ -3,14 +3,19 @@
(type $v (func))
(global $export/a i32 (i32.const 1))
(global $export/b i32 (i32.const 2))
(global $export/c i32 (i32.const 3))
(global $HEAP_BASE i32 (i32.const 4))
(memory $0 1)
(export "add" (func $export/add))
(export "renamed_sub" (func $export/sub))
(export "renamed_a" (global $export/a))
(export "rerenamed_b" (global $export/b))
(export "renamed_mul" (func $export/mul))
(export "rerenamed_mul" (func $export/mul))
(export "a" (global $export/a))
(export "renamed_b" (global $export/b))
(export "renamed_c" (global $export/c))
(export "rerenamed_c" (global $export/c))
(export "renamed_add" (func $export/add))
(export "rerenamed_sub" (func $export/sub))
(export "rerenamed_sub" (func $export/mul))
(export "memory" (memory $0))
(start $start)
(func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
@ -29,19 +34,24 @@
)
)
)
(func $export/ns.two (; 2 ;) (type $v)
)
(func $start (; 3 ;) (type $v)
(drop
(i32.const 2)
(func $export/mul (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32)
(return
(i32.mul
(get_local $0)
(get_local $1)
)
)
)
(func $export/ns.two (; 3 ;) (type $v)
)
(func $start (; 4 ;) (type $v)
(drop
(i32.add
(call $export/add
(i32.const 1)
(i32.const 2)
)
(call $export/sub
(call $export/mul
(i32.const 3)
(i32.const 4)
)
@ -95,8 +105,10 @@
GLOBAL: HEAP_BASE
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/mul
GLOBAL: export/a
GLOBAL: export/b
GLOBAL: export/c
NAMESPACE: export/ns
FUNCTION_PROTOTYPE: export/ns.one
FUNCTION_PROTOTYPE: export/ns.two
@ -105,14 +117,20 @@
NAMESPACE: reexport/imported_ns
[program.exports]
FUNCTION_PROTOTYPE: export/add
FUNCTION_PROTOTYPE: export/renamed_sub
FUNCTION_PROTOTYPE: export/sub
FUNCTION_PROTOTYPE: export/renamed_mul
GLOBAL: export/a
GLOBAL: export/renamed_b
GLOBAL: export/b
GLOBAL: export/renamed_c
NAMESPACE: export/ns
FUNCTION_PROTOTYPE: reexport/add
FUNCTION_PROTOTYPE: reexport/renamed_sub
GLOBAL: reexport/renamed_a
GLOBAL: reexport/rerenamed_b
FUNCTION_PROTOTYPE: reexport/renamed_mul
FUNCTION_PROTOTYPE: reexport/rerenamed_mul
GLOBAL: reexport/a
GLOBAL: reexport/renamed_b
GLOBAL: reexport/renamed_c
GLOBAL: reexport/rerenamed_c
FUNCTION_PROTOTYPE: reexport/renamed_add
FUNCTION_PROTOTYPE: reexport/rerenamed_sub
NAMESPACE: reexport/renamed_ns