uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit fe22b6288eefe7e94d6b640777bf015bc2958456
parent 38f534d9ecda12cba041bcf23a9b59614aa1588d
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Wed,  3 Nov 2021 19:38:02 +0000

asma fix: disallow 1 and 3 chars in hex literals and raw hex

Diffstat:
Metc/asma-test.sh | 12++++++++++++
Mprojects/library/asma.tal | 15++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/etc/asma-test.sh b/etc/asma-test.sh @@ -46,6 +46,18 @@ EOD expect_failure 'Invalid hexadecimal: #' <<'EOD' |1000 # EOD +expect_failure 'Invalid hexadecimal: #0' <<'EOD' +|1000 #0 +EOD +expect_failure 'Invalid hexadecimal: #000' <<'EOD' +|1000 #000 +EOD +expect_failure 'Unrecognised token: 0' <<'EOD' +|1000 0 +EOD +expect_failure 'Unrecognised token: 000' <<'EOD' +|1000 000 +EOD expect_failure 'Address not in zero page: .hello' <<'EOD' |1000 @hello .hello diff --git a/projects/library/asma.tal b/projects/library/asma.tal @@ -371,13 +371,14 @@ include projects/library/file-read-chunks.tal #57 SUB JMP2r -@asma-parse-hex-string ( -- value* 06 if valid hex and 2 < length <= 4 - OR value* 03 if valid hex and length <= 2 - OR 00 otherwise ) +@asma-parse-hex-string ( strict -- value* 06 if valid hex and (length == 4 or (length == 3 and not strict)) + OR value* 03 if valid hex and (length == 2 or (length == 1 and not strict)) + OR 00 otherwise ) + STH ;asma/token LDA2 DUP2 ,strlen JSR ( token* length^ ) + DUP STHr AND ,&fail2 JCN DUP2 #0004 GTH2 ,&fail2 JCN ORAk #00 EQU ,&fail2 JCN - &resume #0002 GTH2 ROT ROT LIT2r 0000 @@ -624,7 +625,7 @@ include projects/library/heap.tal ( fall through ) @asma-pad-helper ( offset* -- ) - ;asma-parse-hex-string JSR2 + #00 ;asma-parse-hex-string JSR2 ,&valid JCN ;asma-msg-hex ;asma/error STA2 @@ -740,7 +741,7 @@ include projects/library/heap.tal JMP2r @asma-literal-hex - ;asma-parse-hex-string JSR2 JMP + #01 ;asma-parse-hex-string JSR2 JMP ( hex invalid ) ,&invalid JMP ( hex byte ) ,asma-byte-helper JMP ( hex short ) ,asma-short-helper JMP @@ -766,7 +767,7 @@ include projects/library/heap.tal ;asma-write-byte JMP2 ( tail call ) &not-opcode - ;asma-parse-hex-string JSR2 JMP + #01 ;asma-parse-hex-string JSR2 JMP ( hex invalid ) ,&not-hex JMP ( hex byte ) ,asma-byte-helper/raw JMP ( hex short ) ,asma-short-helper/raw JMP