From 8df11ef268f050461390d7070cb84d0d72dbfec6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 4 Dec 2024 19:10:39 -0500 Subject: more words, nearing forth2012 conformance --- main.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 06dad34..b14d9e4 100644 --- a/main.cpp +++ b/main.cpp @@ -22,24 +22,31 @@ #include #include -constinit static sforth::forth<2048> forth {sforth::initialize<&forth>()}; +constinit static sforth::forth<4096> forth {sforth::initialize<&forth>()}; -constinit static sforth::native_word<".", [](auto) { +static void putu(sforth::addr v) +{ char buf[32] = {}; auto ptr = buf + sizeof(buf); - auto v = forth.pop(); - bool neg = v < 0; - if (neg) v = -v; *--ptr = '\0'; do { *--ptr = "0123456789abcdefghijklmnopqrstuvwxyz"[v % forth.base]; } while (v /= forth.base); - if (neg) *--ptr = '-'; std::cout << ptr << ' '; +} + +constinit static sforth::native_word<".", [](auto) { + sforth::addr v = forth.pop(); + if (v & (1 << (8 * sizeof(sforth::cell) - 1))) + std::cout << '-'; + putu(v); }> dot; +constinit static sforth::native_word<"U.", [](auto) { + putu(forth.pop()); +}, &dot> udot; constinit static sforth::native_word<"EMIT", [](auto) { std::cout << static_cast(forth.pop()); -}, &dot> emit; +}, &udot> emit; constinit static sforth::native_word<"TYPE", [](auto) { const unsigned u = forth.pop(); const auto caddr = reinterpret_cast(forth.pop()); -- cgit v1.2.3