File tree Expand file tree Collapse file tree 6 files changed +110
-0
lines changed
tests/runtime/common-types Expand file tree Collapse file tree 6 files changed +110
-0
lines changed Original file line number Diff line number Diff line change
1
+ package example:composition;
2
+
3
+ let leaf = new test:leaf {
4
+ ...
5
+ };
6
+ let middle = new test:middle {
7
+ to-test: leaf.to-test,
8
+ ...
9
+ };
10
+ let runner = new test:runner {
11
+ to-test: middle.to-test,
12
+ ...
13
+ };
14
+
15
+ export runner...;
Original file line number Diff line number Diff line change
1
+ #include < leaf_cpp.h>
2
+
3
+ using namespace test ::common::test_types;
4
+
5
+ R1 exports::test::common::to_test::Wrap (F1 flag) {
6
+ if (flag == F1::kA ) {
7
+ return R1{ 1 , flag };
8
+ } else {
9
+ return R1{ 2 , flag };
10
+ }
11
+ }
12
+
13
+ V1 exports::test::common::to_test::VarF (void ) {
14
+ return V1 (V1::B (42 ));
15
+ }
Original file line number Diff line number Diff line change
1
+ #include < middle_cpp.h>
2
+
3
+ using namespace test ::common::test_types;
4
+
5
+ R1 exports::test::common::to_test::Wrap (F1 flag) {
6
+ return ::test::common::to_test::Wrap (flag);
7
+ }
8
+
9
+ V1 exports::test::common::to_test::VarF (void ) {
10
+ return ::test::common::to_test::VarF ();
11
+ }
Original file line number Diff line number Diff line change
1
+ include ! ( env!( "BINDINGS" ) ) ;
2
+
3
+ use crate :: test:: common:: to_test:: { F1 , R1 , V1 } ;
4
+
5
+ use exports:: test:: common:: to_test;
6
+
7
+ pub struct Test { }
8
+
9
+ export ! ( Test ) ;
10
+
11
+ impl to_test:: Guest for Test {
12
+ fn wrap ( flag : F1 ) -> R1 {
13
+ crate :: test:: common:: to_test:: wrap ( flag)
14
+ }
15
+
16
+ fn var_f ( ) -> V1 {
17
+ crate :: test:: common:: to_test:: var_f ( )
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ #include < assert.h>
2
+ #include < runner_cpp.h>
3
+
4
+ int main () {
5
+ using namespace ::test::common::test_types;
6
+
7
+ R1 res = test::common::to_test::Wrap (F1::kA );
8
+ assert (res.b == F1::kA );
9
+ assert (res.a == 1 );
10
+
11
+ R1 res2 = test::common::to_test::Wrap (F1::kB );
12
+ assert (res2.b == F1::kB );
13
+ assert (res2.a == 2 );
14
+
15
+ V1 res3 = test::common::to_test::VarF ();
16
+ assert (res3.variants .index () == 1 );
17
+ assert (std::get<1 >(res3.variants ).value == 42 );
18
+
19
+ return 0 ;
20
+ }
Original file line number Diff line number Diff line change
1
+ //@ dependencies = ['middle', 'leaf']
2
+ //@ wac = 'compose.wac'
3
+
4
+ package test : common ;
5
+
6
+ interface test-types {
7
+ flags f1 { a , b }
8
+ record r1 { a : u8 , b : f1 }
9
+ variant v1 { a , b (u8 ) }
10
+ }
11
+
12
+ interface to-test {
13
+ use test-types . {f1 , r1 , v1 };
14
+
15
+ wrap : func (flag : f1 ) -> r1 ;
16
+ var-f : func () -> v1 ;
17
+ }
18
+
19
+ world leaf {
20
+ export to-test ;
21
+ }
22
+
23
+ world middle {
24
+ import to-test ;
25
+ export to-test ;
26
+ }
27
+
28
+ world runner {
29
+ import to-test ;
30
+ }
You can’t perform that action at this time.
0 commit comments