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

This commit is contained in:
Andrew Alderwick 2021-11-03 19:38:02 +00:00
parent 38f534d9ec
commit fe22b6288e
2 changed files with 20 additions and 7 deletions

View File

@ -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

View File

@ -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