8000 exception wordset by jkotlinski · Pull Request #583 · jkotlinski/durexforth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

exception wordset #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2f02f05
added testexception test suite
jkotlinski Dec 15, 2024
ea2d0e5
start work on exceptions
jkotlinski Dec 15, 2024
cc6c527
implement catch
jkotlinski Dec 15, 2024
fc931b1
catch&throw seem ok
jkotlinski Dec 15, 2024
f8728f4
add abort, abort"
jkotlinski Dec 15, 2024
dcd9dfc
replace some error messages with exceptions
jkotlinski Dec 15, 2024
0dab547
almost working
jkotlinski Dec 15, 2024
85a8c36
fix broken throws
jkotlinski Dec 16, 2024
12c8815
try restoring input sources... not there yet
jkotlinski Dec 16, 2024
daa67ed
remove set-error-count call
jkotlinski Dec 16, 2024
6376025
fix drop
jkotlinski Dec 17, 2024
166c751
Merge branch 'master' into exception
jkotlinski Dec 22, 2024
c09d861
reset HANDLER on QUIT
jkotlinski Dec 22, 2024
94dd6f8
refactoring: rename variable
jkotlinski Dec 22, 2024
7deb457
nearly works, except for abort"
jkotlinski Dec 22, 2024
c015c59
seems to work a little
jkotlinski Dec 22, 2024
8c9b315
fix header validation
jkotlinski Dec 22, 2024
c0d2ec6
rename label
jkotlinski Dec 22, 2024
0fd5a8a
edit changelog
jkotlinski Dec 22, 2024
a6244ef
code golf
jkotlinski Dec 22, 2024
c9120bc
tweak error message
jkotlinski Dec 22, 2024
cceca35
add comment
jkotlinski Dec 22, 2024
834ad3c
fix header
jkotlinski Dec 22, 2024
f43de04
add divison by zero exception
jkotlinski Dec 22, 2024
ae7d36a
hook up user interrupt to exceptions
jkotlinski Dec 23, 2024
8684938
document exceptions
jkotlinski Dec 24, 2024
4473541
tidy up
jkotlinski Dec 24, 2024
5067f57
tidy up
jkotlinski Dec 24, 2024
df925b5
fix spelling
jkotlinski Dec 24, 2024
d2a5ab3
update comment
jkotlinski Dec 24, 2024
a8323c8
Merge branch 'master' into exception
jkotlinski Dec 25, 2024
825fb21
add comment
jkotlinski Dec 25, 2024
972e277
Merge branch 'master' into exception
jkotlinski Dec 25, 2024
e08dd10
added catch example
jkotlinski Dec 26, 2024
874bbb1
allow -13 and -37 to print errors before THROW
jkotlinski Dec 26, 2024
f8193c2
document 0>
jkotlinski Dec 26, 2024
b2a7a63
update ioabort docs
jkotlinski Dec 26, 2024
a2c02e1
Merge branch 'master' into exception
jkotlinski Dec 27, 2024
4bd3a5b
print unknown exception numbers
jkotlinski Dec 27, 2024
6eec889
expand "throw" documentation
jkotlinski Dec 27, 2024
98ced48
remove STRING, - it is not needed
jkotlinski Dec 27, 2024
d069b23
fix merge error
jkotlinski Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Exception support with CATCH and THROW.
- ABORT and ABORT" throw exceptions -1 and -2.
- S" now works in interpretation mode. It returns a transient buffer.
- STRING, stores a counted string.
- 0> to compat.
### Fixed
- V: crash when entering ":w!"

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SRC_NAMES = base debug v asm gfx gfxdemo rnd sin ls turtle fractals \
wordlist io open dos see accept
SRCS = $(addprefix $(SRC_DIR)/,$(addsuffix .fs,$(SRC_NAMES)))

TEST_SRC_NAMES = test testcore testcoreplus testcoreext tester testsee 1
TEST_SRC_NAMES = test testcore testcoreplus testcoreext testexception tester testsee 1
TEST2_SRC_NAMES = see gfx gfxdemo fractals mmldemo mml sid spritedemo sprite compat rnd sin turtle
TEST_SRCS = $(addprefix test/,$(addsuffix .fs,$(TEST_SRC_NAMES)))

Expand Down Expand Up @@ -90,7 +90,7 @@ docs: docs/index.html

docs/index.html: manual/index.adoc manual/words.adoc manual/links.adoc manual/sid.adoc manual/asm.adoc \
manual/mnemonics.adoc manual/memmap.adoc manual/anatomy.adoc LICENSE.txt manual/tutorial.adoc \
manual/intro.adoc
manual/intro.adoc manual/exceptions.adoc
rm -rf docs
asciidoctor -a revnumber=$(shell git describe --tags --dirty) -a revdate=$(shell git log -1 --format=%as) -o docs/index.html manual/index.adoc

Expand Down
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"
lda #-16 ; attempt to use zero-length string as a name
jmp throw_a
+ sta .putlen+1

; Move back [W]LATEST.
Expand Down
3 changes: 2 additions & 1 deletion asm/disk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ INCLUDED
jsr READST
beq +
jsr _errorchread
jmp ABORT
lda #-37 ; file i/o exception
jmp throw_a
+
pla
tax
Expand Down
1 change: 1 addition & 0 deletions asm/durexforth.asm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ MINUS_ONE
!src "io.asm"
!src "lowercase.asm"
!src "disk.asm"
!src "exception.asm"
!src "format.asm"

BOOT_STRING
Expand Down
171 changes: 171 additions & 0 deletions 171 asm/exception.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
; CATCH THROW (ABORT")

EXCEPTION_HANDLER
+VALUE _EXCEPTION_HANDLER
_EXCEPTION_HANDLER
!word 0

+BACKLINK "catch", 5
CATCH
; save data stack pointer
txa
jsr pushya
jsr TO_R
; save previous handler
jsr EXCEPTION_HANDLER
jsr FETCH
jsr TO_R
; set current handler
stx W
tsx
txa
ldx W
jsr pushya
jsr EXCEPTION_HANDLER
jsr STORE
; execute returns if no THROW
jsr EXECUTE
; restore previous handler
jsr R_TO
jsr EXCEPTION_HANDLER
jsr STORE
; discard saved stack pointer
jsr R_TO
inx ; drop
; normal completion
jmp ZERO

+BACKLINK "throw", 5
THROW
lda LSB,x
ora MSB,x
bne +
; 0 throw is no-op
inx
rts
+ lda _EXCEPTION_HANDLER + 1
beq .print_error_and_abort

; restore previous return stack
jsr EXCEPTION_HANDLER
jsr FETCH
stx W
lda LSB,x
tax
txs
ldx W
inx

; restore previous handler
jsr R_TO
jsr EXCEPTION_HANDLER
jsr STORE

; exc# on return stack
jsr R_TO
jsr SWAP
jsr TO_R

; restore stack
lda LSB,x
tax
inx
jsr R_TO
rts

.print_error_and_abort
lda MSB,x
cmp #-1
bne .unknown_exception
lda LSB,x
cmp #-13 ; Undefined word is printed before THROW.
beq .cr_and_abort
cmp #-37 ; File I/O errors are printed before THROW.
beq .cr_and_abort
cmp #-2 ; abort"
bne +
jsr .get_abort_string
jmp .type_and_abort
+ jsr .get_system_exception_string
jsr COUNT
.type_and_abort
jsr RVS
jsr TYPE
.cr_and_abort
jsr CR
ldx #X_INIT
jmp QUIT

; It is a bit cheesy to use a hardcoded list, but it works.
; A linked list would be more flexible.
.get_system_exception_string
cmp #-1
bne +
+VALUE .abort_string
+ cmp #-4
bne +
+VALUE .stack_underflow
+ cmp #-8
bne +
+VALUE .mem_full
+ cmp #-10
bne +
+VALUE .div_error
+ cmp #-16
bne +
+VALUE .no_word
+ cmp #-28
bne .unknown_exception
+VALUE .user_interrupt

.unknown_exception
jsr RVS
jsr DOT
lda #'e'
jsr PUTCHR
lda #'r'
jsr PUTCHR
jsr PUTCHR
jmp .cr_and_abort

.get_abort_string
.msg_lsb = * + 1
lda #0
.msg_msb = * + 1
ldy #0
jsr pushya
.msg_len = * + 1
lda #0
ldy #0
jmp pushya

.abort_string
!byte 5
!text "abort"
.stack_underflow
!byte 5
!text "stack"
.mem_full
!byte 4
!text "full"
.no_word
!byte 7
!text "no name"
.div_error
!byte 2
!text "/0" ; division by zero
.user_interrupt
!byte 3
!text "brk"

+BACKLINK "(abort\")", 8 ; ( addr u -- )
lda LSB,x
sta .msg_len
inx
lda LSB,x
sta .msg_lsb
lda MSB,x
sta .msg_msb
inx
lda #-2
jmp throw_a
7 changes: 6 additions & 1 deletion asm/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def verify(path):
for line in lines:
if "+BACKLINK" not in line:
continue
words += [line.split('"')[1].rsplit('"')[0].upper()]
start = line.find('"') + 1
end = line.rfind('"')
word = line[start:end]
word = word.replace('\\"', '"')
word = word.upper()
words += [word]

if not words:
return
Expand Down
Loading
0