aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/main.cpp b/main.cpp
index 06dad34..b14d9e4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -22,24 +22,31 @@
#include <span>
#include <string>
-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<char>(forth.pop());
-}, &dot> emit;
+}, &udot> emit;
constinit static sforth::native_word<"TYPE", [](auto) {
const unsigned u = forth.pop();
const auto caddr = reinterpret_cast<const char *>(forth.pop());