forth-riscv

My forth
git clone git://git.electrosoup.com/forth-riscv
Log | Files | Refs

commit 17d2b9223162bf54a64e828bdd2ef3585161a4f0
parent 08cebb6cb85636b72ec554b1a68dbfe90ceaa345
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sun, 23 Mar 2025 12:45:43 -0700

Change built-in strings and buffers to proper variables

Diffstat:
Msrc/forth.s | 56+++++++++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 29 deletions(-)

diff --git a/src/forth.s b/src/forth.s @@ -281,6 +281,18 @@ defvar "source-offset", source_offset, 0x7F8C1674 defvar "source-id", source_id, 0x965ED1E2 .int 0 +defvar "tib", tib, 0xC90B0194 + .int _tib_len + .int _tib_addr + +defvar "prompt", prompt, 0xDFE6493B + .int _prompt_len + .int _prompt_addr + +defvar "okay", okay, 0xBA9EEB49 + .int _okay_len + .int _okay_addr + # ----------------------------------------------------------------------------- # input and output # ----------------------------------------------------------------------------- @@ -333,13 +345,15 @@ defword "accept-tib", accept_tib, 0x18571723 addi psp, psp, -2*cell sw w, 1*cell(psp) # load tib addr and len - la x, _tib + 1*cell + la x, _tib + lw w, 0*cell(x) + lw x, 1*cell(x) sw x, 0*cell(psp) - lw w, -1*cell(x) jal accept # reserve stack space and configure outputs addi psp, psp, -2*cell - la x, _tib + 1*cell + la x, _tib + lw x, 1*cell(x) sw x, 1*cell(psp) sw w, 0*cell(psp) li w, -1 @@ -1005,34 +1019,18 @@ _branch_done: addi ra, ra, cell next -defcode "prompt", prompt, 0xDFE6493B - push w - la w, _prompt - la x, _prompt_len - push_ret ra - call uart_put_string - pop_ret ra - pop w - next - -defcode "okay", okay, 0xBA9EEB49 - push w - la w, _okay - la x, _okay_len - push_ret ra - call uart_put_string - pop_ret ra - pop w - next - defword "quit", quit, 0x47878736 jal rp_top jal rp_store jal prompt + jal two_fetch + jal type jal refill jal drop # TODO: What should happen when 'refill' fails? jal interpret jal okay + jal two_fetch + jal type jal branch .int quit @@ -1764,19 +1762,19 @@ version_string: .ascii "soup forth rv32\n" version_string_len = (. - version_string) -_prompt: +_prompt_addr: .ascii "> " - _prompt_len = (. - _prompt) + _prompt_len = (. - _prompt_addr) -_okay: +_okay_addr: .ascii "ok\n" - _okay_len = (. - _okay) + _okay_len = (. - _okay_addr) .section ".data" .balign cell -_tib: - .int 255 +_tib_addr: .space 255 + _tib_len = (. - _tib_addr) _fib: .int 255 .space 255