aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/main.c b/main.c
index dad7e92..0743578 100644
--- a/main.c
+++ b/main.c
@@ -21,6 +21,43 @@ typedef struct
uint8_t memory[MEMORY_DEFAULT];
} machine_t;
+void interpret(machine_t *cpu, node_t *ast, size_t num)
+{
+ for (size_t i = 0; i < num; ++i)
+ {
+ node_t node = ast[i];
+ switch (node.type)
+ {
+ case NEXT:
+ ++cpu->dp;
+ break;
+ case PREV:
+ --cpu->dp;
+ break;
+ case INC:
+ ++cpu->memory[cpu->dp];
+ break;
+ case DEC:
+ --cpu->memory[cpu->dp];
+ break;
+ case OUT:
+ putchar(cpu->memory[cpu->dp]);
+ break;
+ case READ:
+ cpu->memory[cpu->dp] = getchar();
+ break;
+ case LIN:
+ if (cpu->memory[cpu->dp] == 0)
+ i = node.loop_ref;
+ break;
+ case LOUT:
+ if (cpu->memory[cpu->dp] != 0)
+ i = node.loop_ref;
+ break;
+ }
+ }
+}
+
int main(int argc, char *argv[])
{
if (argc == 1)
@@ -36,6 +73,8 @@ int main(int argc, char *argv[])
buffer_t *buffer;
struct PResult res;
+ machine_t machine = {0};
+
for (int i = 1; i < argc; ++i)
{
filepath = argv[i];
@@ -61,6 +100,8 @@ int main(int argc, char *argv[])
printf("%s=>%s\n", filepath, str);
+ interpret(&machine, res.nodes, res.size);
+
free(str);
free(res.nodes);
free(buffer);