From 29894d56e144223629e558070cbc52080e21342e Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Mon, 24 Jul 2023 20:12:26 +0200 Subject: Fully implement tokenizer and port value passing --- .gitignore | 3 + Makefile | 1 + test/test.asm | 11 ++-- tis-as.c | 143 +++++++++++++++++++++++++++--------------- tis-curses.c | 65 ++++++++++++------- tpu.c | 196 +++++++++++++++++++++++++++++++++------------------------- tpu.h | 14 +++-- 7 files changed, 265 insertions(+), 168 deletions(-) diff --git a/.gitignore b/.gitignore index a4bb5fd..28d072b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ tis-as tis-curses compile_commands.json .cache +notes +.gdb_history +vgcore* diff --git a/Makefile b/Makefile index 62c5c54..d950c5d 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PREFIX ?= /usr/local BINDIR ?= /bin CFLAGS = -Wunused-function -Wunused-variable -Wconversion -Wswitch +CFLAGS += -Og -g all: tis-as tis-curses diff --git a/test/test.asm b/test/test.asm index 80de3f5..a03a156 100644 --- a/test/test.asm +++ b/test/test.asm @@ -2,16 +2,13 @@ stdin X1 Y1 stdout X3 Y1 tpu X1 Y1 - mov acc, bak -label: - goto label + mov UP, RIGHT end tpu X2 Y1 - mov UP, RIGHT - mov RIGHT + mov LEFT, RIGHT end tpu X3 Y1 - -edn + mov LEFT, DOWN +end diff --git a/tis-as.c b/tis-as.c index fb0fc49..8077442 100644 --- a/tis-as.c +++ b/tis-as.c @@ -25,8 +25,7 @@ enum tok { TOK_NEG, TOK_JMP, TOK_JEZ, TOK_JNZ, TOK_JGZ, TOK_JLZ, TOK_JRO, /* Misc */ - TOK_COMMENT, TOK_LABEL, TOK_XPOS, TOK_YPOS, - TOK_SEP, TOK_NL, TOK_EOF + TOK_COMMENT, TOK_LABEL, TOK_XPOS, TOK_YPOS, TOK_NL, TOK_EOF }; struct tokenizer { @@ -46,20 +45,28 @@ static struct tpu_port stdout_port; static struct tpu_map tpu_map; +static const char *dir_names[] = { + "LEFT", "RIGHT", "UP", "DOWN" +}; + +static const char *status_names[] = { + "IDLE", "RUN", "READ", "WRITE" +}; + static const char *tok_reprs[] = { /* Global */ "'STDIN'", "'STDOUT'", "'TPU'", "'END'", - /* Operands */ - "'ACC'", "'BAK'", "'NIL'", "'LEFT'", "'RIGHT'", "'UP'", - "'DOWN'", "'ANY'", "'LAST'", "", "", + /* Operands (order like OP_*) */ + "'ACC'", "'BAK'", "'NIL'", "'LEFT'", "'RIGHT'", + "'UP'", "'DOWN'", "'ANY'", "'LAST'", "", "", - /* Instructions */ + /* Instructions (order like INST_*) */ "'NOP'", "'MOV'", "'SWP'", "'SAV'", "'ADD'", "'SUB'", "'NEG'", "'JMP'", "'JEZ'", "'JNZ'", "'JGZ'", "'JLZ'", "'JRO'", /* Misc */ - "#", "