forth-riscv

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

commit befdb1f165c3f13255de63d0ca7f3a9513ce6673
parent d8269ac8c0f566dbb8fd5e48acaeefa0ef04533e
Author: Christian Ermann <christianermann@gmail.com>
Date:   Mon,  4 Nov 2024 20:21:07 -0800

Add 'parse-char'

Diffstat:
Mforth.s | 31++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/forth.s b/forth.s @@ -245,7 +245,36 @@ defcode "fib", 3, 0, 0xBCE49236, fib, tib push w next -defcode "parse-word", 10, 0, 0xB218226F, parse_word, fib +defcode "parse-char", 10, 0, 0xDF4F729B, parse_char, fib + la w, _source + load_cell w, 0(w) + la x, _source_len + load_cell x, 0(x) + la y, _input_offset + load_cell y, 0(y) + add w, w, y + sub x, x, y + + li s3, 0x20 # space +1: # find start of word + beqz x, 3f # out of chars? -> stop! + lb t0, 0(w) # next char! + addi w, w, 1 # inc. addr + addi y, y, 1 # inc. offset + addi x, x, -1 # dec. len + beq t0, s3, 1b # space? -> skip! + +2: # done + la t1, _input_offset + store_cell y, 0(t1) + push t0 + next + +3: # out of chars + mv t0, zero + j 2b + +defcode "parse-word", 10, 0, 0xB218226F, parse_word, parse_char la w, _source load_cell w, 0(w) # buff addr la x, _source_len