forth-riscv

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

commit 5609af2e7bbe0ad0344c771d2c32009748349a4c
parent 5ed02979dda27d3818f3e4e1ed72e8dd63fc3e6a
Author: Christian Ermann <christian.ermann@joescan.com>
Date:   Tue,  1 Jul 2025 20:28:01 -0700

Factor '(interpret-execute)'

Diffstat:
Msrc/forth.s | 49++++++++++++++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/src/forth.s b/src/forth.s @@ -847,37 +847,48 @@ _interpret_parse_area_empty: # ( addr len=0 -- ) addi psp, psp, cell pop w - jal interpret_execute - exit - -defword "(interpret-execute)", interpret_execute, 0x2477F685 - # check state la x, _state lw x, 0(x) li y, state_executing - bne x, y, _inner_interpret_done - # append 'exit' - jal exit_comma - # save current execution heap address + bne x, y, _interpret_done + jal interpret_execute +_interpret_done: + exit + +defcode "nest-execution", nest_execution, 0xCCD56530 + # ( -- exec-heap r: exec-heap ) push w - la w, _exec_heap - lw x, 0(w) - push_ret x - # set new execution heap address past compiled code + # save exec heap address + la x, _exec_heap + lw w, 0(x) + push_ret w + # update exec heap to point past compiled code la y, _code_pointer lw y, 0(y) - sw y, 0(w) - pop w - # execute - jalr x - # reset code pointer and execution heap + sw y, 0(x) + next + +defcode "unnest-execution", unnest_execution, 0x9AC2B97B + # ( r: exec-heap -- ) + # restore code compilation pointer pop_ret x la y, _code_pointer sw x, 0(y) + # restore exec heap address la y, _exec_heap sw x, 0(y) + next + +defword "(interpret-execute)", interpret_execute, 0x2477F685 + # ( -- ) + # append 'exit' + jal exit_comma + # run! + jal nest_execution + jal execute + jal unnest_execution + # append 'docol' jal docol_comma -_inner_interpret_done: exit defcode "branch", branch, 0xB6873945