linting; reduce msp430 binary size

llvm
Clyne 2 years ago
parent dcd5e792b1
commit 970bbb473c

@ -1,6 +1,6 @@
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))

@ -90,10 +90,7 @@ int main()
*ptr++ = c;
}
}
}
return 0;
}
static void readchar(State& state)
@ -157,3 +154,6 @@ void user_sys(State& state)
}
}
extern "C" int atexit(void (*)()) { return 0; }
void operator delete(void *) {}
void operator delete(void *, std::size_t) {}

@ -39,11 +39,13 @@ int main(int argc, char *argv[])
dict.initialize();
{
std::vector args (argv + 1, argv + argc);
for (const auto& a : args) {
std::ifstream file (a);
parseFile(parser, state, file);
}
}
okay = true;
parseFile(parser, state, std::cin);

@ -73,6 +73,8 @@ public:
bool equal(Word, const char *, unsigned) const noexcept;
bool equal(Word, Word) const noexcept;
virtual ~Dictionary() = default;
};
#endif // ALEEFORTH_DICTIONARY_HPP

@ -55,11 +55,11 @@ State::Error State::execute(Addr addr)
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));
}

@ -28,8 +28,9 @@
constexpr unsigned DataStackSize = 16;
constexpr unsigned ReturnStackSize = 16;
struct State
class State
{
public:
enum class Error : int {
none = 0,
push,
@ -45,11 +46,6 @@ struct State
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&)):
@ -64,15 +60,15 @@ struct 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() {
@ -81,28 +77,35 @@ struct State
}
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

@ -28,7 +28,7 @@ constexpr unsigned long int MemDictSize = MEMDICTSIZE;
class MemDict : public Dictionary
{
uint8_t dict[MemDictSize];
uint8_t dict[MemDictSize] = {0};
public:
virtual Cell read(Addr addr) const noexcept final {

@ -21,7 +21,7 @@
#include "alee.hpp"
#include <cstring>
#include <algorithm>
#ifndef MEMDICTSIZE
#define MEMDICTSIZE (65536)
@ -32,14 +32,21 @@ template<unsigned long int RON>
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 {

Loading…
Cancel
Save