forth-riscv

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

commit 31170aa7bba69c8bbb786c7df9f7817b7cc79e9a
parent 4999fdd21730919a8723fd4bf8a9bebc737651ea
Author: Christian Ermann <christianermann@gmail.com>
Date:   Tue,  5 Nov 2024 22:01:27 -0800

Fix spaces in strings

Diffstat:
Mforth.f | 17+++++++++++++++--
Mforth.s | 23++++++++++++++++++++++-
2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/forth.f b/forth.f @@ -19,13 +19,26 @@ : \ begin parse-char while repeat ; immediate : ( begin parse-char dup while ')' = if exit then repeat ; immediate -: '"' [ parse-char " ] literal ; +: '"' [ parse-char " ] literal ; \ this is here to fix syntax highlighting: " +: '\' [ parse-char \ ] literal ; +: 'n' [ parse-char n ] literal ; +: 'r' [ parse-char r ] literal ; +: 'z' [ parse-char z ] literal ; : parse-string here begin - parse-char dup dup '"' <> and + parse-key dup dup '"' <> and while + dup '\' = if + drop parse-key + dup 'n' = if drop 10 else + dup 'r' = if drop 13 else + dup 'z' = if drop 0 else + dup '"' = if else + dup '\' = if else + then then then then then + then over c! 1 + repeat drop here - here swap ; diff --git a/forth.s b/forth.s @@ -245,7 +245,28 @@ defcode "fib", 3, 0, 0xBCE49236, fib, tib push w next -defcode "parse-char", 10, 0, 0xDF4F729B, parse_char, fib +defcode "parse-key" 9, 0, 0xB78FDA4A, parse_key, 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 + beqz x, 2f +1: + lb t0, 0(w) + addi y, y, 1 + la t1, _input_offset + store_cell y, 0(t1) + push t0 + next +2: + mv t0, zero + j 1b + +defcode "parse-char", 10, 0, 0xDF4F729B, parse_char, parse_key la w, _source load_cell w, 0(w) la x, _source_len