forth-riscv

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

commit 502266a55c00d8e56637f58e990c030a0158d110
parent fd2034c2bb35c5a237c1b9ac1763daa9b8a89363
Author: Christian Ermann <christianermann@gmail.com>
Date:   Fri,  1 Nov 2024 12:17:28 -0700

Add 'postpone', 'if', and 'while'

Diffstat:
Mforth.f | 12++++++++++++
Mforth.s | 27+++++++++++++++++++++++++--
2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/forth.f b/forth.f @@ -1,3 +1,15 @@ : test type ; +: ahead here 0 , ; +: if postpone ?branch ahead ; immediate +: then here swap ! ; immediate +: else postpone branch ahead swap postpone then ; immediate + +: begin here ; immediate +: while postpone if swap ; immediate +: again postpone branch comma ; immediate +: repeat postpone again postpone then ; immediate + +: test-if if type then exit ; + diff --git a/forth.s b/forth.s @@ -575,7 +575,13 @@ defcode "+", 1, 0, 0xC4ADC675, plus, two_dup push w next -defcode "aligned", 7, 0, 0xC73174DF, aligned, plus +defcode "or", 2, 0, 0x5D342984, or_, plus + pop w + pop x + or w, w, x + push w + +defcode "aligned", 7, 0, 0xC73174DF, aligned, or_ pop w addi w, w, 3 andi w, w, 0xFFFFFFFC @@ -686,6 +692,23 @@ defcode "immediate?", 10, 0, 0x89F23E9F, immediate_q, compiling_q push w next +defword "postpone", 8, flag_immediate, 0x933F531F, postpone, immediate_q + .int parse_word, find # TODO: was word actually found? + .int to_cfa, dup + .int immediate_q, q_branch, _postpone_compile +_postpone_execute: + # stores "<xt>" into the current definition + .int comma, exit +_postpone_compile: + # stores "lit <xt> ," into the current definition + .int lit, lit, comma, comma, lit, comma, comma, exit + +defword "immediate", 9, 0, 0xF232267A, immediate, postpone + .int latest, fetch, lit, flag_offset, plus, dup + .int fetch, lit, flag_immediate, or_ + .int swap, store + .int exit + .section ".text" file_get_char: la w, _bootstrap @@ -723,7 +746,7 @@ version_string: word_buffer: .space 255 .balign cell -_latest: .int name_immediate_q +_latest: .int name_immediate _here: .int __here_start _meta: .int __meta_start