From ff4e488ca0fd012a4b632bf2f9a775a601c09f67 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 19 Dec 2024 17:29:23 -0500 Subject: [PATCH] define type in forth --- core.fth | 22 ++++++++++++---------- main.cpp | 7 +------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/core.fth b/core.fth index 8d4789b..768f195 100644 --- a/core.fth +++ b/core.fth @@ -65,18 +65,20 @@ dup cell+ allot rot here swap ! swap postpone literal postpone literal then ; immediate -: ." postpone s" state @ if postpone type else type then ; immediate +: type ?dup if 0 do dup c@ emit 1+ loop then drop ; +: ." postpone s" state @ if postpone type else type then ; immediate : ( begin [char] ) key = until ; immediate : execute [ here 3 cells + ] literal ! [ ' _jmp , 0 , ] ; -: move dup 0 <= if drop 2drop exit then - >r 2dup < r> swap if - 1- 0 swap do over i + c@ over i + c! -1 +loop - else - 0 do over i + c@ over i + c! loop - then 2drop ; -: fill -rot begin dup 0 > while - >r 2dup c! char+ r> 1- repeat - 2drop drop ; +: move dup 0 <= if drop 2drop exit then + >r 2dup < r> swap if + 1- 0 swap do over i + c@ over i + c! -1 +loop + else + 0 do over i + c@ over i + c! loop + then 2drop ; +: fill -rot begin dup 0 > while + >r 2dup c! char+ r> 1- repeat + 2drop drop ; + diff --git a/main.cpp b/main.cpp index ec2e02c..e51f702 100644 --- a/main.cpp +++ b/main.cpp @@ -40,17 +40,12 @@ constinit static sforth::native_word<"U.", [](auto) { constinit static sforth::native_word<"EMIT", [](auto) { std::cout << static_cast(forth.pop()); }, &udot> emit; -constinit static sforth::native_word<"TYPE", [](auto) { - const unsigned u = forth.pop(); - const auto caddr = reinterpret_cast(forth.pop()); - std::cout << std::string_view{caddr, u}; -}, &emit> type; constinit static sforth::native_word<"INCLUDE", [](auto) { const auto w = forth.parse(); std::string s {w.begin(), w.end()}; std::ifstream file {s}; parse_stream(forth, file); -}, &type> incl; +}, &emit> incl; int main(int argc, const char *argv[]) {