Skip to content

Commit

Permalink
abort with error on empty HEADER name (#564)
Browse files Browse the repository at this point in the history
* abort with error on empty HEADER name

* changelog

* Print "err" instead.

Also moved W2 code up to not repeat the INX instructions.
  • Loading branch information
ekipan authored Nov 19, 2024
1 parent e20515e commit 5b6f114
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moved tests to a separate disk (tests.d64).
- gfx: Renamed ERASE to PEN.
- #> (the pictured numeric output string buffer) now uses its own buffer chopped from the end of PAD.
- CHAR, HEADER and other parsing words no longer do REFILL on missing text.
- CHAR no longer does REFILL on missing text.
- EVALUATE now accepts multi-line strings.
- ( refills to accept multi-line comments when parsing EVALUATE strings.
- Defining words based on HEADER now abort with an error on missing text.
### Removed
- GETC, 100/, INTERPRET, ;CODE (replace with: RTS, END-CODE)
### Fixed
Expand Down
42 changes: 23 additions & 19 deletions asm/compiler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,26 @@ COLON

jmp RBRAC ; enter compile mode


; --- HEADER ( name -- )
+BACKLINK "header", 6
HEADER
HEADER ; ( "name" -- )
inc last_word_no_tail_call_elimination

; update dictionary

; Parse, get [W2]name-addr and [LSB-2]length.
jsr PARSE_NAME

; update dictionary pointer
inx
lda LSB, x
sta .putlen+1
sta W2
lda MSB, x
sta W2 + 1
inx

; Abort if empty string.
lda LSB - 2, x
bne +
jmp .on_stack_underflow ; "err"
+ sta .putlen+1

; Move back [W]LATEST.
clc
adc #3
sta W
Expand All @@ -160,31 +167,28 @@ HEADER
dec LATEST_MSB
+ lda LATEST_MSB
sta W + 1

; Store name length.
ldy #0
; Store length byte.
lda LSB, x
lda LSB - 2, x
sta (W), y
inx
lda LSB, x
sta W2
lda MSB, x
sta W2 + 1
; copy string

; Copy name.
- lda (W2), y
jsr CHAR_TO_LOWERCASE
iny
sta (W), y
.putlen
cpy #0
bne -
; store here

; Store xt.
iny
lda HERE_LSB
sta (W), y
iny
lda HERE_MSB
sta (W), y
inx
rts

+BACKLINK "lit", 3
Expand Down Expand Up @@ -248,7 +252,7 @@ COMPILE_COMMA
+BACKLINK "literal", 7 | F_IMMEDIATE
LITERAL
dex
lda MSB+1,x
lda MSB + 1,x
bne +
lda #<LITC
sta LSB,x
Expand Down

0 comments on commit 5b6f114

Please sign in to comment.