commit 08cebb6cb85636b72ec554b1a68dbfe90ceaa345
parent 2f58dad429aa64c72bd3fa31e2c7fb1eb5bd6403
Author: Christian Ermann <christianermann@gmail.com>
Date: Sat, 22 Mar 2025 23:29:51 -0700
Modify 'refill' to use dispatch table
Diffstat:
| M | src/forth.s | | | 60 | +++++++++++++++++++++++++++++++++++------------------------- |
1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/src/forth.s b/src/forth.s
@@ -327,43 +327,53 @@ _accept_done:
sub w, w, y
exit
-defword "refill", refill, 0x238BAA91
+defword "accept-tib", accept_tib, 0x18571723
+ # ( -- addr len flag )
+ # reserve stack space and push w
addi psp, psp, -2*cell
- sw w, -1*cell(psp)
- # check input source
- la w, _source_id
- lw w, 0(w)
- beqz w, _refill_tib
-_refill_fib:
- la y, _fib + 1*cell
- lw x, -1*cell(y)
- sw y, 0*cell(psp)
- push x
- jal read_line # ( dst max-len file-id -- len status )
- pop x
- beqz w, _refill_fail
- mv w, x
- la x, _fib + 1*cell
- j _refill_okay
-_refill_tib:
+ sw w, 1*cell(psp)
+ # load tib addr and len
la x, _tib + 1*cell
- lw w, -1*cell(x)
sw x, 0*cell(psp)
- jal accept # ( dst max-len -- len )
- beqz w, _refill_fail
+ lw w, -1*cell(x)
+ jal accept
+ # reserve stack space and configure outputs
+ addi psp, psp, -2*cell
la x, _tib + 1*cell
+ sw x, 1*cell(psp)
+ sw w, 0*cell(psp)
+ li w, -1
+ exit
+
+defword "refill", refill, 0x238BAA91
+ # ( -- flag )
+ # dispatch based on input source
+ la x, _source_id
+ lw x, 0(x)
+ slli x, x, 2
+ la y, _refill_dispatch_table
+ add x, x, y
+ lw x, 0(x)
+ # ( -- addr len flag )
+ jalr x
+ addi psp, psp, 2*cell
+ beqz w, _refill_fail
+ lw x, -1*cell(psp)
+ lw w, -2*cell(psp)
_refill_okay:
la y, _tick_source
sw w, 0*cell(y)
sw x, 1*cell(y)
- la x, _source_offset
- sw zero, 0*cell(x)
+ la y, _source_offset
+ sw zero, 0*cell(y)
li w, -1
- exit
_refill_fail:
- mv w, zero
exit
+.section ".data"
+_refill_dispatch_table:
+ .int accept_tib
+
defword "source", source, 0x1BCF29D8
jal tick_source
jal two_fetch