From 3226cb7a6911a3001e1509f091fdf1f165d9c5f8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 3 Dec 2024 18:03:37 -0500 Subject: [PATCH] begin double-cell words --- sforth/forth.hpp | 9 +++++++++ sforth/types.hpp | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/sforth/forth.hpp b/sforth/forth.hpp index de87154..6f29be4 100644 --- a/sforth/forth.hpp +++ b/sforth/forth.hpp @@ -221,6 +221,14 @@ constexpr auto initialize() , S{"+" }, [](auto) { fthp->top() += fthp->pop(); }, 0 , S{"-" }, [](auto) { fthp->top() -= fthp->pop(); }, 0 , S{"*" }, [](auto) { fthp->top() *= fthp->pop(); }, 0 + , S{"M*" }, [](auto) { + dcell a = fthp->pop(); + a *= fthp->pop(); + fthp->push(a, a >> 8 * sizeof(cell)); }, 0 + , S{"UM*" }, [](auto) { + daddr a = std::bit_cast(fthp->pop()); + a *= std::bit_cast(fthp->pop()); + fthp->push(a, a >> 8 * sizeof(addr)); }, 0 , S{"/" }, [](auto) { fthp->top() /= fthp->pop(); }, 0 , S{"MOD" }, [](auto) { fthp->top() %= fthp->pop(); }, 0 , S{"AND" }, [](auto) { fthp->top() &= fthp->pop(); }, 0 @@ -322,6 +330,7 @@ constexpr auto initialize() , S{"CHAR+" }, S{"1 +" }, 0 , S{"-ROT" }, S{"ROT ROT"}, 0 , S{"2DROP" }, S{"DROP DROP"}, 0 + , S{"S>D" }, S{"DUP 0<"}, 0 , S{"0<" }, S{"0 <"}, 0 , S{"0<>" }, S{"0 <>"}, 0 , S{"<>" }, S{"= 0="}, 0 diff --git a/sforth/types.hpp b/sforth/types.hpp index 57c37c5..ade5d4b 100644 --- a/sforth/types.hpp +++ b/sforth/types.hpp @@ -29,6 +29,26 @@ using cell = std::intptr_t; using addr = std::uintptr_t; using func = void (*)(const void *); +#if UINTPTR_MAX == 0xFFFF +using dcell = std::int32_t; +#elif UINTPTR_MAX == 0xFFFFFFFF +using dcell = std::int64_t; +#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF +using dcell = __int128; +#else +#error "Cannot figure out size of double-cell integer" +#endif + +#if UINTPTR_MAX == 0xFFFF +using daddr = std::uint32_t; +#elif UINTPTR_MAX == 0xFFFFFFFF +using daddr = std::uint64_t; +#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF +using daddr = __uint128; +#else +#error "Cannot figure out size of double-address integer" +#endif + struct word_base; template