-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
109 lines (83 loc) · 2.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "doppl.hpp"
using namespace doppl;
int doppl_main() {
const int range = 1;
//Stdin and stdout
input_t input;
output_t output;
//Data oriented private task members
std::array<
DM<int>,
range
> _foo;
std::array<
FM<int>,
range
> _zee;
//Shared task members
shared<DM<int>> sha;
//Task body
auto task_body = [&] (
//Task id
const int tid
) -> int {
//Doppl runtime loop
std::promise<void> global_yield;
task_loop<void> loop;
//Private Members
decltype(_foo[tid])& foo = _foo[tid];
decltype(_zee[tid])& zee = _zee[tid];
//States
SM<void> init;
SM<void> bar;
SM<void, FM<int>> tar;
init.set([&] (auto& yield, auto& next, auto& finish) {
output.set("Init State Works\n");
//Data Members test
foo.set(42);
assert(foo.get() == 42);
output.set("Data Members Work\n");
//State Transition Test
next.set(bar);
});
bar.set([&] (auto& yield, auto& next, auto& finish) {
output.set("State Transition Works\n");
//Internal State Declarations Test
SM<int> temp([&output] (auto& yield, auto& next, auto& finish) {
SM<int> clone([&output] (auto& yield, auto& next, auto& finish) {
output.set("Transition in Cloned Tasks Works\n");
next.set(finish);
yield.set_value(99);
});
output.set("Internal State Declerations Work\n");
//Transition in Cloned Tasks test
next.set(clone);
});
//Future Members test
zee.set(temp, false);
assert(zee.get() == 99);
output.set("Future Members Work\n");
//Parametered Transition test
next.set(tar, zee);
});
tar.set([&] (auto& yield, auto& next, auto& finish, FM<int> param) {
assert(param.get() == 99);
output.set("Parameterized Transition Works\n");
//Shared Members test
sha.set(foo);
assert(sha.get() == 42);
output.set("Shared Members Work\n");
next.set(finish);
});
return loop(init, global_yield);
};
//Return
return doppl_run<range>(task_body);
};
//Start runtime
int main() {
std::cout << std::endl << "********Doppl Runtime Test" << std::endl << std::endl;
assert(doppl_main() == 0);
std::cout << std::endl << "********Doppl Runtime Test Success" << std::endl;
return 0;
};