forth-riscv

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

commit bce487fa1663817912ed99d02a5d89f0d5675b71
parent ee25a1856fdff412fadab7ac8829631722e5ccd8
Author: Christian Ermann <christianermann@gmail.com>
Date:   Wed,  6 Nov 2024 20:47:01 -0800

Change 'source' to use a '2var' internally

Diffstat:
Mforth.s | 90++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 48 insertions(+), 42 deletions(-)

diff --git a/forth.s b/forth.s @@ -128,7 +128,6 @@ code_\label: defhead "\name", \label, \hash, dovar, flags=\flags .globl _\label _\label: - .int \initial .endm .macro defconst name, label, hash, flags=0, value=0 @@ -136,7 +135,6 @@ _\label: defhead "\name", \label, \hash, docon, flags=\flags .globl _\label _\label: - .int \value .endm docol: @@ -163,13 +161,27 @@ defcode "exit", exit, 0xCDED1A85 # constants and variables # ----------------------------------------------------------------------------- -defconst "sp0", sp_top, 0x0C41B8B2, value=__stacktop -defconst "rp0", rp_top, 0x8AD91EDD, value=__stacktop_ret +defconst "sp0", sp_top, 0x0C41B8B2 + .int __stacktop -defvar "state", state, 0x783132F6, initial=state_immediate -defvar "dp", dp, 0x491CB0B9, initial=__here_start -defvar "latest", latest, 0x41704246, initial=name_read_line -defvar "base", base, 0x3DDC94D8, initial=10 +defconst "rp0", rp_top, 0x8AD91EDD + .int __stacktop_ret + +defvar "state", state, 0x783132F6 + .int state_immediate + +defvar "dp", dp, 0x491CB0B9 + .int __here_start + +defvar "latest", latest, 0x41704246 + .int name_read_line + +defvar "base", base, 0x3DDC94D8 + .int 10 + +defvar "'source", tick_source, 0xEB4FEC0B + .int 0 # address + .int 0 # length # ----------------------------------------------------------------------------- # input and output @@ -229,8 +241,7 @@ _refill_tib: .int tib, accept, dup, q_branch, _refill_failed .int tib, drop _refill_success: - .int source_addr, store - .int source_len, store + .int tick_source, two_store .int lit, 0, source_offset, store .int lit, -1 .int exit @@ -238,24 +249,8 @@ _refill_failed: .int drop, lit, 0 .int exit -defcode "source", source, 0x1BCF29D8 - la w, _source - load_cell w, 0(w) - la x, _source_len - load_cell x, 0(x) - push w - push x - next - -defcode "source-addr", source_addr, 0x997F9EE8 - la w, _source - push w - next - -defcode "source-len", source_len, 0x1B513E8E - la w, _source_len - push w - next +defword "source", source, 0x1BCF29D8 + .int tick_source, two_fetch, exit defcode "source-offset", source_offset, 0x7F8C1674 la w, _input_offset @@ -286,10 +281,9 @@ defcode "fib", fib, 0xBCE49236 next defcode "parse-key", parse_key, 0xB78FDA4A - la w, _source - load_cell w, 0(w) - la x, _source_len - load_cell x, 0(x) + la w, _tick_source + load_cell x, cell(w) + load_cell w, 0(w) la y, _input_offset load_cell y, 0(y) add w, w, y @@ -307,10 +301,9 @@ defcode "parse-key", parse_key, 0xB78FDA4A j 1b defcode "parse-char", parse_char, 0xDF4F729B - la w, _source - load_cell w, 0(w) - la x, _source_len - load_cell x, 0(x) + la w, _tick_source + load_cell x, cell(w) + load_cell w, 0(w) la y, _input_offset load_cell y, 0(y) add w, w, y @@ -336,10 +329,9 @@ defcode "parse-char", parse_char, 0xDF4F729B j 2b defcode "parse-word", parse_word, 0xB218226F - la w, _source - load_cell w, 0(w) # buff addr - la x, _source_len - load_cell x, 0(x) # buff len + la w, _tick_source + load_cell x, cell(w) + load_cell w, 0(w) # buff addr # apply input offset la y, _input_offset load_cell y, 0(y) @@ -559,6 +551,22 @@ defcode "c@", char_fetch, 0x37296056 push x next +defcode "2!", two_store, 0x9CF2B11C + pop w + pop x + pop y + store_cell x, 0(w) + store_cell y, cell(w) + next + +defcode "2@", two_fetch, 0x3DF21B8F + pop w + load_cell x, 0(w) + load_cell y, cell(w) + push y + push x + next + defcode "+!", add_store, 0x08DC01D1 pop w # address pop x # value to add @@ -1005,8 +1013,6 @@ _bootstrap: .int __file_start _bootstrap_len: .int __file_len _bootstrap_offset: .int 0 -_source: .int _tib -_source_len: .int 0 _source_id: .int 0 _input_offset: .int 0