Mercurial > hg > Members > nobuyasu > CbC
view ABP/sender2.c @ 33:3946f8d26710 draft default tip
add benchmarck/binary-trees
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 09 Apr 2013 16:41:30 +0900 |
parents | 18d2a590bc10 |
children |
line wrap: on
line source
#define __environment _CbC_environment #define __return _CbC_return int comm_bit; /* communication bit */ char *comm_msg; /* communication message */ struct packet { int bit; /* alternating bit */ char **msg; /* messages */ code (*next)(); /* next code segment */ }; code (*ret)(int,void*); void *env; code sendState(struct packet, int); code receiveState(struct packet, int); char *msgs[6] = { "hoge1", "hoge2", "hoge3", "hoge4", "hoge5", 0 }; code receiveState(struct packet pkt, int i) { if (pkt.bit == comm_bit) { pkt.bit = !pkt.bit; printf("bit: %d\n", comm_bit); printf("message: %s\n", comm_msg); i++; pkt.next = sendState; goto pkt.next(pkt, i); } else { printf("wrong bit!\n"); comm_bit = pkt.bit; pkt.next = sendState; goto pkt.next(pkt, i); } } code sendState(struct packet pkt, int i) { // if (pkt.msg[i] == 0) goto ret(0), env; if (pkt.msg[i] == 0) goto ret(0, env); comm_bit = pkt.bit; comm_msg = pkt.msg[i]; pkt.next = receiveState; goto pkt.next(pkt, i); } code initSender(struct packet pkt, int init_bit) { pkt.bit = 0; pkt.msg = msgs; comm_bit = init_bit; pkt.next = sendState; goto pkt.next(pkt, 0); } int main(void) { struct packet pkt; ret = _CbC_return; env = _CbC_environment; goto initSender(pkt, 0); }