aboutsummaryrefslogtreecommitdiff
path: root/src/test.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-19 09:23:31 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-19 09:23:31 -0700
commit60ce7fba21a6d37c0acbe152039fbc3d0e692bf0 (patch)
tree73fa0295dace25c23a00f4ec4e654b4f4fb85619 /src/test.c
parent1ae9a10d56fca8fe585e77533c49e5c9d680ff12 (diff)
chore: reorganized structure to allow for more parallel projects
Diffstat (limited to 'src/test.c')
-rw-r--r--src/test.c105
1 files changed, 0 insertions, 105 deletions
diff --git a/src/test.c b/src/test.c
deleted file mode 100644
index 3f8e608..0000000
--- a/src/test.c
+++ /dev/null
@@ -1,105 +0,0 @@
-#include <u.h>
-
-uintptr
-printtest(coro *c, uintptr d)
-{
- printf("--> Recieved %lu\n", d);
- d = coro·yield(c, d+10);
- printf("--> Now %lu\n", d);
-
- return d;
-}
-
-uintptr
-sequence(coro *c, uintptr start)
-{
- int d = start;
- for (;;) {
- coro·yield(c, d++);
- }
-
- return d;
-}
-
-struct PrimeMsg
-{
- coro *seq;
- int p;
-};
-
-uintptr
-filter(coro *c, uintptr data)
-{
- int x, p;
- coro *seq;
- struct PrimeMsg *msg;
-
- // Need to copy relevant variables onto the local stack
- // Data is volatile.
- msg = (struct PrimeMsg*)data;
- seq = msg->seq;
- p = msg->p;
-
- for (;;) {
- x = coro·yield(seq, x);
- if (x % p != 0) {
- x = coro·yield(c, x);
- }
- }
-
- return 0;
-}
-
-int
-main()
-{
- int i;
- coro *c[4];
- uintptr d;
-
- printf("Starting singleton test\n");
-
- for (i = 0; i < arrlen(c); i++) {
- c[i] = coro·new(0, &printtest);
- }
-
- /* Singleton test */
- d = 0;
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[0], d);
- }
-
- printf("Starting triplet test\n");
-
- /* Triplet test */
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[1], d);
- d = coro·yield(c[2], d+100);
- d = coro·yield(c[3], d+200);
- }
-
- for (i = 0; i < arrlen(c); i++) {
- coro·free(c[i]);
- }
-
- /* Prime sieve */
- printf("Starting prime test\n");
- uintptr num;
- coro *cur, *seq[50];
-
- num = 2;
- seq[0] = coro·new(4096, &sequence);
- cur = *seq;
-
- num = coro·yield(cur, num);
- for (i = 1; i < arrlen(seq); i++) {
- seq[i] = coro·new(4096, &filter);
- struct PrimeMsg msg = {
- .seq = cur,
- .p = num,
- };
- cur = seq[i];
- num = coro·yield(cur, (uintptr)&msg);
- printf("--> prime number %lu\n", num);
- }
-}