Skip to content

Commit

Permalink
replace some error messages with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotlinski committed Dec 15, 2024
1 parent f8728f4 commit dcd9dfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
3 changes: 2 additions & 1 deletion asm/compiler.asm
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ HEADER ; ( "name" -- )
; Abort if empty string.
lda LSB - 2, x
bne +
jmp .on_stack_underflow ; "err"
ldy #-16 ; attempt to use zero-length string as a name
jmp .throw_exception
+ sta .putlen+1

; Move back [W]LATEST.
Expand Down
46 changes: 14 additions & 32 deletions asm/interpreter.asm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ interpret_and_close
interpret_tib
jsr INTERPRET
cpx #X_INIT+1
bpl .on_stack_underflow
bpl .throw_stack_underflow
lda TO_IN_W
cmp TIB_SIZE
bne interpret_tib
Expand All @@ -135,7 +135,7 @@ interpret_tib
sbc HERE_LSB
lda LATEST_MSB
sbc HERE_MSB
beq .on_data_underflow
beq .throw_dictionary_overflow
lda STATE
bne +
lda #'o'
Expand All @@ -146,26 +146,16 @@ interpret_tib
jmp PUTCHR
+ rts

.on_stack_underflow
lda #$12 ; reverse on
jsr PUTCHR
lda #'e'
jsr PUTCHR
lda #'r'
jsr PUTCHR
jmp .stop_error_print

.on_data_underflow
lda #$12 ; reverse on
jsr PUTCHR
lda #'f'
jsr PUTCHR
lda #'u'
jsr PUTCHR
lda #'l'
jsr PUTCHR
lda #$d
jmp PUTCHR
.throw_stack_underflow
ldy #-4
jmp .throw_exception
.throw_dictionary_overflow
ldy #-8
; fall through
.throw_exception
lda #$ff
jsr pushya
jmp THROW

+BACKLINK "execute", 7
EXECUTE
Expand Down Expand Up @@ -236,16 +226,8 @@ FOUND_WORD_WITH_NO_TCE = * + 1

+BACKLINK "notfound",8
print_word_not_found_error ; ( caddr u -- )
lda #$12 ; reverse on
jsr PUTCHR
jsr TYPE
lda #'?'
.stop_error_print
jsr PUTCHR

lda #$d ; cr
jsr PUTCHR
jmp ABORT
ldy #-2 ; abort"
jmp throw_exception

+BACKLINK "'", 1
jsr PARSE_NAME
Expand Down

0 comments on commit dcd9dfc

Please sign in to comment.