diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-12-03 18:03:37 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-12-03 18:03:37 -0500 |
commit | 3226cb7a6911a3001e1509f091fdf1f165d9c5f8 (patch) | |
tree | 132598c8866e05b5879b2fe3d28de3260f6c2bda | |
parent | 599e15e9e4cab7f2f7d4e13120ff02ed6cdf5bd7 (diff) |
begin double-cell words
-rw-r--r-- | sforth/forth.hpp | 9 | ||||
-rw-r--r-- | sforth/types.hpp | 20 |
2 files changed, 29 insertions, 0 deletions
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<addr>(fthp->pop()); + a *= std::bit_cast<addr>(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<typename T> |