From d36bb13f52b3899fd0f57e38f00d97e2c3a0f627 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 18 Mar 2023 12:40:46 -0400 Subject: -Wconversion --- splitmemdict.hpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'splitmemdict.hpp') diff --git a/splitmemdict.hpp b/splitmemdict.hpp index 45a9ee1..730d103 100644 --- a/splitmemdict.hpp +++ b/splitmemdict.hpp @@ -35,6 +35,10 @@ class SplitMemDict : public Dictionary uint8_t rwdict[MemDictSize - Dictionary::Begin] = {0}; uint8_t extra[Dictionary::Begin]; + Addr convertAddress(Addr addr) const noexcept { + return addr < RON ? addr : static_cast(addr - RON); + } + public: constexpr explicit SplitMemDict(const uint8_t *rod): rodict(rod) @@ -51,14 +55,12 @@ public: virtual Cell read(Addr addr) const noexcept final { const uint8_t *dict; - if (addr < RON) { + if (addr < RON) dict = addr < Dictionary::Begin ? extra : rodict; - } else { + else dict = rwdict; - addr -= RON; - } - return *reinterpret_cast(dict + addr); + return *reinterpret_cast(dict + convertAddress(addr)); } virtual void write(Addr addr, Cell value) noexcept final { @@ -70,14 +72,12 @@ public: virtual uint8_t readbyte(Addr addr) const noexcept final { const uint8_t *dict; - if (addr < RON) { + if (addr < RON) dict = addr < Dictionary::Begin ? extra : rodict; - } else { + else dict = rwdict; - addr -= RON; - } - return dict[addr]; + return dict[convertAddress(addr)]; } virtual void writebyte(Addr addr, uint8_t value) noexcept final { @@ -86,6 +86,10 @@ public: else if (addr < Dictionary::Begin) extra[addr] = value; } + + virtual unsigned long int capacity() const noexcept final { + return RON + sizeof(extra) + sizeof(rwdict); + } }; #endif // ALEEFORTH_SPLITMEMDICT_HPP -- cgit v1.2.3