CXXFLAGS += -std=c++17 -g3 -ggdb -O0 \
- -Wall -Wextra -pedantic -Werror \
- -fno-exceptions -fno-rtti #-fstack-usage
+ -pedantic -Wall -Wextra -Werror -Weffc++ \
+ -fno-exceptions -fno-threadsafe-statics -fno-rtti #-fstack-usage
CXXFILES := $(wildcard libalee/*.cpp)
OBJFILES := $(subst .cpp,.o,$(CXXFILES))
*ptr++ = c;
}
}
-
}
-
- return 0;
}
static void readchar(State& state)
}
}
+extern "C" int atexit(void (*)()) { return 0; }
+void operator delete(void *) {}
+void operator delete(void *, std::size_t) {}
dict.initialize();
- std::vector args (argv + 1, argv + argc);
- for (const auto& a : args) {
- std::ifstream file (a);
- parseFile(parser, state, file);
+ {
+ std::vector args (argv + 1, argv + argc);
+ for (const auto& a : args) {
+ std::ifstream file (a);
+ parseFile(parser, state, file);
+ }
}
okay = true;
bool equal(Word, const char *, unsigned) const noexcept;
bool equal(Word, Word) const noexcept;
+
+ virtual ~Dictionary() = default;
};
#endif // ALEEFORTH_DICTIONARY_HPP
std::size_t State::size() const noexcept
{
- return std::distance(dstack, static_cast<const Cell *>(dsp)) + 1;
+ return std::distance(dstack, static_cast<const Cell *>(dsp));
}
std::size_t State::rsize() const noexcept
{
- return std::distance(rstack, static_cast<const Cell *>(rsp)) + 1;
+ return std::distance(rstack, static_cast<const Cell *>(rsp));
}
constexpr unsigned DataStackSize = 16;
constexpr unsigned ReturnStackSize = 16;
-struct State
+class State
{
+public:
enum class Error : int {
none = 0,
push,
Dictionary& dict;
void (*input)(State&);
- Cell dstack[DataStackSize] = {};
- Cell rstack[ReturnStackSize] = {};
- Cell *dsp = dstack - 1;
- Cell *rsp = rstack - 1;
-
std::jmp_buf jmpbuf = {};
constexpr State(Dictionary& d, void (*i)(State&)):
std::size_t rsize() const noexcept;
inline void push(Cell value) {
- if (dsp == dstack + DataStackSize - 1)
+ if (dsp == dstack + DataStackSize)
std::longjmp(jmpbuf, static_cast<int>(Error::push));
- *++dsp = value;
+ *dsp++ = value;
}
inline Cell pop() {
- if (dsp < dstack)
+ if (dsp == dstack)
std::longjmp(jmpbuf, static_cast<int>(Error::pop));
- return *dsp--;
+ return *--dsp;
}
inline Cell beyondip() {
}
inline void pushr(Cell value) {
- if (rsp == rstack + ReturnStackSize - 1)
+ if (rsp == rstack + ReturnStackSize)
std::longjmp(jmpbuf, static_cast<int>(Error::pushr));
- *++rsp = value;
+ *rsp++ = value;
}
inline Cell popr() {
- if (rsp < rstack)
+ if (rsp == rstack)
std::longjmp(jmpbuf, static_cast<int>(Error::popr));
- return *rsp--;
+ return *--rsp;
}
inline Cell& top() {
- if (dsp < dstack)
+ if (dsp == dstack)
std::longjmp(jmpbuf, static_cast<int>(Error::top));
- return *dsp;
+ return *(dsp - 1);
}
inline Cell& pick(std::size_t i) {
- if (dsp - i < dstack)
+ if (dsp - i == dstack)
std::longjmp(jmpbuf, static_cast<int>(Error::pick));
- return *(dsp - i);
+ return *(dsp - i - 1);
}
+
+private:
+ Cell dstack[DataStackSize] = {};
+ Cell rstack[ReturnStackSize] = {};
+ Cell *dsp = dstack;
+ Cell *rsp = rstack;
+
};
#endif // ALEEFORTH_STATE_HPP
class MemDict : public Dictionary
{
- uint8_t dict[MemDictSize];
+ uint8_t dict[MemDictSize] = {0};
public:
virtual Cell read(Addr addr) const noexcept final {
#include "alee.hpp"
-#include <cstring>
+#include <algorithm>
#ifndef MEMDICTSIZE
#define MEMDICTSIZE (65536)
class SplitMemDict : public Dictionary
{
const uint8_t *rodict;
- uint8_t rwdict[MemDictSize];
+ uint8_t rwdict[MemDictSize - Dictionary::Begin] = {0};
uint8_t extra[Dictionary::Begin];
public:
- constexpr SplitMemDict(const uint8_t *rod):
+ constexpr explicit SplitMemDict(const uint8_t *rod):
rodict(rod)
{
- std::memcpy(extra, rodict, sizeof(extra));
+ std::copy(rodict, rodict + sizeof(extra), extra);
+ }
+
+ constexpr SplitMemDict(const SplitMemDict<RON>& spd):
+ SplitMemDict(spd.rodict) {}
+ constexpr auto& operator=(const SplitMemDict<RON>& spd) {
+ *this = SplitMemDict(spd.rodict);
+ return *this;
}
virtual Cell read(Addr addr) const noexcept final {