|
| 1 | +import wit.test.resource_aggregates.test; |
| 2 | + |
| 3 | +import wit.common; |
| 4 | +import std.algorithm.iteration : sum, map; |
| 5 | + |
| 6 | +@witExport("test:resource-aggregates/to-test", "thing") |
| 7 | +struct ThingImpl { |
| 8 | + uint val; |
| 9 | + |
| 10 | + @witExport("test:resource-aggregates/to-test", "[constructor]thing") |
| 11 | + static Thing constructor(uint v) { |
| 12 | + return Thing.makeNew((out typeof(this) self) { |
| 13 | + self.val = v + 1; |
| 14 | + }); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +@witExport("test:resource-aggregates/to-test", "foo") |
| 19 | +uint foo( |
| 20 | + scope ref R1 r1, scope ref R2 r2, scope ref R3 r3, |
| 21 | + scope ref T1 t1, scope ref T2 t2, |
| 22 | + scope ref V1 v1, scope ref V2 v2, |
| 23 | + scope ref L1 l1, scope ref L2 l2, |
| 24 | + scope ref Option!Thing o1, scope ref Option!(Thing.Borrow) o2, |
| 25 | + scope ref Result!(Thing, void) result1, scope ref Result!(Thing.Borrow, void) result2 |
| 26 | +) { |
| 27 | + scope(exit) { |
| 28 | + r1.witDrop; |
| 29 | + r2.witDrop; |
| 30 | + r3.witDrop; |
| 31 | + t1.witDrop; |
| 32 | + t2.witDrop; |
| 33 | + v1.witDrop; |
| 34 | + v2.witDrop; |
| 35 | + l1.witDrop; |
| 36 | + l2.witDrop; |
| 37 | + o1.witDrop; |
| 38 | + o2.witDrop; |
| 39 | + result1.witDrop; |
| 40 | + result2.witDrop; |
| 41 | + } |
| 42 | + |
| 43 | + return ( |
| 44 | + r1.thing.rep!ThingImpl.val |
| 45 | + + r2.thing.rep!ThingImpl.val |
| 46 | + + r3.thing1.rep!ThingImpl.val |
| 47 | + + r3.thing2.rep!ThingImpl.val |
| 48 | + + t1[0].rep!ThingImpl.val |
| 49 | + + t1[1].thing.rep!ThingImpl.val |
| 50 | + + t2[0].rep!ThingImpl.val |
| 51 | + + v1.getThing.rep!ThingImpl.val |
| 52 | + + v2.getThing.rep!ThingImpl.val |
| 53 | + + l1[].map!((a) => a.rep!ThingImpl.val).sum |
| 54 | + + l2[].map!((a) => a.rep!ThingImpl.val).sum |
| 55 | + + o1.unwrap.rep!ThingImpl.val |
| 56 | + + o2.unwrap.rep!ThingImpl.val |
| 57 | + + result1.unwrap.rep!ThingImpl.val |
| 58 | + + result2.unwrap.rep!ThingImpl.val |
| 59 | + + 3 |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +alias Exports = wit.test.resource_aggregates.test.Exports!( |
| 64 | + ThingImpl, |
| 65 | + foo |
| 66 | +); |
0 commit comments