Files
@ 3ffeb97c88a7
Branch filter:
Location: CSY/reowolf/examples/bench_23/main.c - annotation
3ffeb97c88a7
3.0 KiB
text/x-csrc
Add docs for implementing infinite types in a value based language.
Since we are a value based language and do not have the concept of
pointers, then if we want to lay out the memory of datatypes we run
into a problem when the types represent recursive datastructures:
these are infinite in size. So we have an algorithm for turning
some types into pointer-like things, such that we can lay everything
out in memory.
Since we are a value based language and do not have the concept of
pointers, then if we want to lay out the memory of datatypes we run
into a problem when the types represent recursive datastructures:
these are infinite in size. So we have an algorithm for turning
some types into pointer-like things, such that we can lay everything
out in memory.
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 110 111 112 113 114 115 116 117 118 119 120 121 122 | 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f 528578bffb3f | #include <time.h>
#include "../../reowolf.h"
#include "../utility.c"
int main(int argc, char** argv) {
int i;
// unsigned char pdl[] = "\
// primitive xrouter(in a, out b, out c) {\
// while(true) synchronous {\
// if(fires(a)) {\
// if(fires(b)) put(b, get(a));\
// else put(c, get(a));\
// }\
// }\
// }"
// ;
unsigned char pdl[] = "\
primitive lossy(in a, out b) {\
while(true) synchronous {\
if(fires(a)) {\
msg m = get(a);\
if(fires(b)) put(b, m);\
}\
}\
}\
primitive sync_drain(in a, in b) {\
while(true) synchronous {\
if(fires(a)) {\
get(a);\
get(b);\
}\
}\
}\
composite xrouter(in a, out b, out c) {\
channel d -> e;\
channel f -> g;\
channel h -> i;\
channel j -> k;\
channel l -> m;\
channel n -> o;\
channel p -> q;\
channel r -> s;\
channel t -> u;\
new replicator(a, d, f);\
new replicator(g, t, h);\
new lossy(e, l);\
new lossy(i, j);\
new replicator(m, b, p);\
new replicator(k, n, c);\
new merger(q, o, r);\
new sync_drain(u, s);\
}"
;
Arc_ProtocolDescription * pd = protocol_description_parse(pdl, sizeof(pdl)-1);
Connector * c = connector_new_with_id(pd, 0);
printf("Error str `%s`\n", reowolf_error_peek(NULL));
PortId ports[6];
for(i=0; i<3; i++) {
connector_add_port_pair(c, &ports[2*i], &ports[2*i+1]);
}
// [native~~~~~~~~~~]
// 0 1 2 3 4 5
// | ^ | ^ | ^
// `--` `--` `--`
char ident[] = "xrouter";
connector_add_component(
c,
ident,
sizeof(ident)-1,
(PortId[]) { ports[1], ports[2], ports[4] },
3);
printf("Error str `%s`\n", reowolf_error_peek(NULL));
// [native~~~~~~~~~~]
// 0 3 5
// V ^ ^
// 1 2 4
// [xrouter~~~~~~~~~]
connector_connect(c, -1);
printf("Connect OK!\n");
int msg_len = 1000;
char * msg = malloc(msg_len);
memset(msg, 42, msg_len);
{
clock_t begin = clock();
for (i=0; i<100000; i++) {
connector_put_bytes(c, ports[0], msg, msg_len);
connector_get(c, ports[3]);
connector_sync(c, -1);
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("First: %f\n", time_spent);
}
{
clock_t begin = clock();
for (i=0; i<100000; i++) {
connector_put_bytes(c, ports[0], msg, msg_len);
connector_get(c, ports[5]);
connector_sync(c, -1);
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Second: %f\n", time_spent);
}
{
clock_t begin = clock();
for (i=0; i<100000; i++) {
connector_put_bytes(c, ports[0], msg, msg_len);
connector_get(c, ports[3 + (i%2)*2]);
connector_sync(c, -1);
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Alternating: %f\n", time_spent);
}
free(msg);
return 0;
}
|