commit efe2699622b09eea984ebc4b659b86cfa5fa90fa
parent b06256d81a433245c592c9b78c716861f9d9a4d3
Author: prenev <an2qzavok@gmail.com>
Date: Mon, 11 Jul 2022 01:21:13 +0300
some mem code
Diffstat:
4 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
-main: main.o bus.o cell.o
- cc -o main main.o bus.o cell.o
+main: main.o bus.o cell.o mem.o
+ cc -o main main.o bus.o cell.o mem.o
bus.o: bus.c bus.h cell.h
cc -c bus.c
@@ -7,4 +7,8 @@ bus.o: bus.c bus.h cell.h
cell.o: cell.c cell.h
cc -c cell.c
+main.o: main.c
+ cc -c main.c
+mem.o: mem.c mem.h bus.h cell.h
+ cc -c mem.c
diff --git a/main.c b/main.c
@@ -3,17 +3,20 @@
#include "cell.h"
#include "bus.h"
+#include "mem.h"
int
main(void)
{
Bus *bus = createbus();
Cell *cell = createcell(6, strdup("hello"));
- Msg *msg = createmsg(0, 0, cell);
- printf("in: %s\n", msg->dat->p);
+ Msg *msg = createmsg(1, 0, cell);
buspush(bus, msg);
- Msg *ret = buspull(bus, 0);
- if (ret != NULL) printf("out: %s\n", ret->dat->p);
+
+ Mem mem = {bus};
+ memstep((void *)&mem);
+ Msg *ret = buspull(bus, 1);
+ if (ret != NULL) printf("yep\n");
else printf("nope\n");
freemsg(ret);
return 0;
diff --git a/mem.c b/mem.c
@@ -1,3 +1,19 @@
+#include <stdlib.h>
+
#include "cell.h"
+#include "bus.h"
#include "mem.h"
+int
+memstep(void *v)
+{
+ Mem *mem = (Mem *)v;
+
+ Msg *msg = buspull(mem->bus, 0);
+ if (msg == NULL) return 1;
+ Msg *ret = createmsg(0, msg->src, createcell(0, NULL));
+ buspush(mem->bus, ret);
+ freemsg(msg);
+ return 0;
+}
+
diff --git a/mem.h b/mem.h
@@ -1,3 +1,9 @@
/* concerning the memory management */
+typedef struct Mem Mem;
+struct Mem {
+ Bus *bus;
+};
+
+int memstep(void *);