From af2c561c6bd1a40592ffca7048c5783e8399da33 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 27 May 2019 11:04:31 -0400 Subject: [PATCH] zasm: begin erroring out reliably Up until now, invalid source input had undefined behavior. We're now beginning to define that behavior so that zasm can be a bit more usable. --- apps/zasm/main.asm | 13 +++++++++---- tools/emul/zasm/zasm.bin | Bin 4042 -> 4047 bytes tools/emul/zasm/zasm.c | 9 +++++---- tools/tests/zasm/errtests.sh | 20 ++++++++++++++++++++ tools/tests/zasm/runtests.sh | 3 ++- 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100755 tools/tests/zasm/errtests.sh diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 177a789..8ee4477 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -15,6 +15,10 @@ .equ ZASM_ORG ZASM_CTX_PC+2 .equ ZASM_RAMEND ZASM_ORG+2 +; *** Errors *** +; Unknown instruction or directive +.equ ERR_UNKWN 0x01 + ; Read file through blockdev ID in H and outputs its upcodes through blockdev ; ID in L. zasmMain: @@ -98,7 +102,7 @@ zasmParseFile: ; resulting opcode(s) through ioPutC and increases (IO_PC) by the number of ; bytes written. BC is set to the result of the call to tokenize. ; Sets Z if parse was successful, unset if there was an error. EOF is not an -; error. +; error. If there is an error, A is set to the corresponding error code (ERR_*). parseLine: call tokenize ld a, b ; TOK_* @@ -109,9 +113,10 @@ parseLine: cp TOK_LABEL jr z, _parseLabel cp TOK_EOF - ret ; Z is correct. If EOF, Z is set and not an - ; error, otherwise, it means bad token and - ; errors out. + ret z ; We're finished, no error. + ; Bad token + ld a, ERR_UNKWN + jp unsetZ ; return with Z unset _parseInstr: ld a, c ; I_* diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index 162e76ed72ee1f12025a04c1c18cdb79d92f4c4a..8194765101941049246e233dd9764a23395b4984 100644 GIT binary patch delta 60 zcmV-C0K@;vAI~4KMGqjlR~YNR$<1U+c>V#(WmoVN7!w&$HU=JM& Sp;s6c%`8?Z1ve@cFXE5GyBaEaIZPo7Qjs`$rvDk1zI)2Wp3f6N-Z|Nfn /dev/null + local res=$? + if [[ $res == $2 ]]; then + echo "Good!" + else + echo "$res != $2" + exit 1 + fi +} + +chkerr "foo" 1 + diff --git a/tools/tests/zasm/runtests.sh b/tools/tests/zasm/runtests.sh index d7b82db..a97c8e2 100755 --- a/tools/tests/zasm/runtests.sh +++ b/tools/tests/zasm/runtests.sh @@ -23,7 +23,7 @@ cmpas() { fi } -for fn in *.asm; do +for fn in test*.asm; do echo "Comparing ${fn}" cmpas $fn done @@ -34,3 +34,4 @@ while read line; do cmpas ${TMPFILE} done +./errtests.sh