forth-riscv

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

commit c59a8073517db071a7a6f33026abafe5834b5c3e
parent 3e449eac809e251b44ccc84636e97ec8afada326
Author: Christian Ermann <christianermann@gmail.com>
Date:   Mon, 28 Oct 2024 23:25:26 -0700

Redefine 'interpret' as a high-level word

Diffstat:
Mforth.s | 77+++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
1 file changed, 49 insertions(+), 28 deletions(-)

diff --git a/forth.s b/forth.s @@ -211,41 +211,43 @@ defcode "execute", 7, 0, 0xA01E3D98, execute, to_cfa jr x # 'next' should be called by the executed word -defcode "interpret", 9, 0, 0x1F98C57A, interpret, execute - jal word_impl - jal find_impl - beqz w, _not_found - mv t2, w - addi w, w, code_offset - - la t0, _state - load_cell x, 0(t0) - li t1, state_immediate - beq x, t1, _execute_word - - mv x, t2 - addi x, x, flag_offset - lb x, 0(x) - andi x, x, flag_immediate - bnez x, _execute_word - - # compile - push w - la w, comma - #addi w, w, code_offset - +defword "interpret", 9, 0, 0x1F98C57A, interpret, execute + .int word, find, dup, q_branch, _not_found + .int to_cfa + .int compiling_q, q_branch, _execute_word + .int dup + .int immediate_q, zero_equal, q_branch, _execute_word + .int comma, exit _execute_word: - load_cell x, 0(w) - jr x + .int execute, exit _not_found: - next + .int drop, exit defcode "branch", 6, 0, 0xB6873945, branch, interpret load_cell t0, 0(ip) add ip, ip, t0 next -defword "quit", 4, 0, 0x47878736, quit, branch +defcode "?branch", 7, 0, 0x6AF3C1DE, q_branch, branch + pop w + bnez w, _branch_done + load_cell w, 0(ip) + mv ip, w + next +_branch_done: + addi ip, ip, cell + next + +defcode "0=", 2, 0, 0x14ED5DD6, zero_equal, q_branch + pop w + mv x, zero + bnez w, _zero_done + addi x, x, -1 +_zero_done: + push x + next + +defword "quit", 4, 0, 0x47878736, quit, zero_equal .int interpret .int branch .int -dcell @@ -324,7 +326,11 @@ defcode "swap", 4, 0, 0x64ED874E, swap, dup push x next -defword "allot", 5, 0, 0xADB1A69F, allot, swap +defcode "drop", 4, 0, 0xA9A58D8C, drop, swap + pop zero + next + +defword "allot", 5, 0, 0xADB1A69F, allot, drop .int dp, add_store .int exit @@ -422,6 +428,21 @@ defword ";", 1, flag_immediate, 0x3E0CB6DA, semicolon, colon .int l_bracket # enter 'immediate' mode .int exit +defcode "compiling?", 10, 0, 0x94652AE2, compiling_q, execute + la w, _state + load_cell w, 0(w) + andi w, w, state_compile + push w + next + +defcode "immediate?", 10, 0, 0x89F23E9F, immediate_q, execute + pop w + addi w, w, flag_offset - code_offset + lb w, 0(w) + andi w, w, flag_immediate + push w + next + .section ".rodata" program: .int type