commit 5a21f8b0aee0ac4eaf3a32a90a0157288aa40a11
parent 7df45e4e8f41c4a6c8bbb8f4011d9d1849e25708
Author: prenev <an2qzavok@gmail.com>
Date: Mon, 1 Aug 2022 03:03:42 +0300
send and receive messages from bus
Diffstat:
M | repl.c | | | 29 | +++++++++++++++++++++++++---- |
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/repl.c b/repl.c
@@ -17,6 +17,8 @@ struct {
void push(Cell *);
Cell * pop(void);
+Bus *bus;
+
#define CMD(x) void x(void)
CMD(str);
CMD(hex);
@@ -24,6 +26,7 @@ CMD(top);
CMD(drp);
CMD(hlp);
CMD(snd);
+CMD(rcv);
struct {
const char *cmd;
@@ -35,6 +38,7 @@ struct {
{"drp", drp},
{"hlp", hlp},
{"snd", snd},
+ {"rcv", rcv},
};
void
@@ -61,6 +65,7 @@ repl(void)
int
main(void)
{
+ bus = createbus();
repl();
return 0;
}
@@ -136,13 +141,29 @@ snd(void)
dstcell = pop();
dst = ((int*)dstcell->p)[0];
+ freecell(dstcell);
dat = pop();
- // Msg *msg = createmsg(ChDebug, ???, ???);
- // buspush(???, msg);
- printf("snd %d %s\n", dst, dat->p);
+ Msg *msg;
+ msg = createmsg(ChDebug, dst, dat);
+ buspush(bus, msg);
+}
+
+void
+rcv(void)
+{
+ /* receive a message from the bus */
+/* int dst;
+ Cell *dstcell;
+ dstcell = pop();
+ dst = ((int*)dstcell->p)[0];
freecell(dstcell);
- freecell(dat);
+*/
+ Msg *msg;
+ msg = buspull(bus, ChDebug);
+ if (msg == NULL) printf("rcv: NULL\n");
+ else printf("rcv: %d %s\n", msg->src, msg->dat->p);
+ freemsg(msg);
}
void