commit f4e58ce4ccf22ea7e101fa052cb52496addf1b3c
Author: prenev <an2qzavok@gmail.com>
Date: Sat, 9 Jul 2022 14:38:24 +0300
first commit
Diffstat:
7 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
diff --git a/cell.h b/cell.h
@@ -0,0 +1,9 @@
+/* concerning memory units */
+
+typedef struct Cell Cell;
+
+struct Cell {
+ long n;
+ char *p;
+};
+
diff --git a/main.c b/main.c
diff --git a/mem.c b/mem.c
@@ -0,0 +1,3 @@
+#include "cell.h"
+#include "mem.h"
+
diff --git a/mem.h b/mem.h
@@ -0,0 +1,3 @@
+/* concerning the memory management */
+
+
diff --git a/proc.c b/proc.c
@@ -0,0 +1,36 @@
+#include "cell.h"
+#include "proc.h"
+
+Proc *
+proccreate(void)
+{
+ Proc * p;
+ p = malloc(sizeof(Proc));
+ p->pc = 0;
+ p->state = 0;
+ p->send = NULL;
+ p->recv = NULL;
+ return p;
+}
+
+/*
+Proc logic is:
+- send 'read' msg to mem
+- recv reply
+- exec
+- loop
+*/
+
+void
+procstep(Proc *p)
+{
+ switch (p->state) {
+ case PSError:
+ case PSWait:
+ case PSHalt:
+ return;
+ default:
+ p->state = PSError;
+ }
+}
+
diff --git a/proc.h b/proc.h
@@ -0,0 +1,22 @@
+/* concerning the unit of computation */
+
+enum {
+ PSHalt,
+ PSWait,
+ PSError,
+
+typedef struct Proc Proc;
+
+struct Proc {
+ int pc;
+ int state;
+ Cell st[256];
+ Cell rs[256];
+
+ void (*send)(void*);
+ void (*recv)(void*);
+);
+
+Proc * proccreate(void);
+void procstep(Proc *);
+