add cppcheck and test targets; some code size reductions

llvm
Clyne 2 years ago
parent 970bbb473c
commit 967775313d

@ -9,10 +9,10 @@ LIBFILE := libalee/libalee.a
all: alee
msp430: CXX := msp430-elf32-g++
msp430: AR := msp430-elf32-ar
msp430: AR := msp430-elf32-gcc-ar
msp430: CXXFLAGS += -Os -mmcu=msp430g2553 -ffunction-sections -fdata-sections
msp430: CXXFLAGS += -DMEMDICTSIZE=200
msp430: LDFLAGS += -L/opt/msp430-elf32/include -Wl,-gc-sections
msp430: CXXFLAGS += -DMEMDICTSIZE=200 -flto
msp430: LDFLAGS += -L/opt/msp430-elf32/include -Tmsp430g2553.ld -Wl,-gc-sections
msp430: clean-lib alee-msp430
small: CXXFLAGS += -Os
@ -27,8 +27,15 @@ alee: $(LIBFILE)
alee-msp430: $(LIBFILE)
alee-standalone: $(LIBFILE)
cppcheck:
cppcheck --enable=warning,style,information --disable=missingInclude \
libalee alee*.cpp *dict.hpp
test: standalone
echo "\nbye\n" | ./alee-standalone test/tester.fr test/core.fr
$(LIBFILE): $(OBJFILES)
$(AR) cr $@ $(OBJFILES)
$(AR) crs $@ $(OBJFILES)
core.fth.h: alee.dat
xxd -i $< > $@
@ -44,5 +51,5 @@ clean: clean-lib
clean-lib:
rm -f $(LIBFILE) $(OBJFILES)
.PHONY: all msp430 small fast standalone clean clean-lib
.PHONY: all clean clean-lib cppcheck fast msp430 small standalone test

@ -19,6 +19,7 @@
#include "alee.hpp"
#include "splitmemdict.hpp"
#include <cctype>
#include <msp430.h>
#include "core.fth.h"
@ -95,16 +96,14 @@ int main()
static void readchar(State& state)
{
auto len = state.dict.read(Dictionary::Input);
Addr addr = Dictionary::Input + sizeof(Cell) +
Dictionary::InputCells - len - 1;
for (Cell i = 0; i < len; ++i, ++addr)
state.dict.writebyte(addr, state.dict.readbyte(addr + 1));
auto idx = state.dict.read(Dictionary::Input);
Addr addr = Dictionary::Input + sizeof(Cell) + idx;
while (!(IFG2 & UCA0RXIFG));
state.dict.writebyte(addr, UCA0RXBUF);
state.dict.write(Dictionary::Input, len + 1);
auto c = UCA0RXBUF;
if (isupper(c))
c += 32;
state.dict.writebyte(addr, c ? c : ' ');
}
void serput(int c)

@ -95,38 +95,33 @@ Addr Dictionary::getexec(Addr addr) noexcept
Word Dictionary::input() noexcept
{
auto src = read(Dictionary::Source);
auto end = read(Dictionary::SourceLen);
const auto src = read(Dictionary::Source);
const auto end = read(Dictionary::SourceLen);
auto idx = read(Dictionary::Input);
Addr wordstart = src + idx;
Addr wordend = wordstart;
Word word {
static_cast<Addr>(src + idx),
static_cast<Addr>(src + idx)
};
while (idx < end) {
auto ch = readbyte(wordend);
if (ch == '\0')
break;
auto ch = readbyte(word.end);
if (isspace(ch)) {
if (wordstart != wordend) {
writebyte(Dictionary::Input, idx + 1);
return {wordstart, wordend};
}
if (word.size() > 0)
break;
++wordstart;
++word.start;
} else if (ch == '\0') {
break;
}
++wordend;
++word.end;
++idx;
}
if (wordstart != wordend) {
writebyte(Dictionary::Input, idx + 1);
return {wordstart, wordend};
}
return {};
return word;
}
bool Dictionary::equal(Word word, const char *str, unsigned len) const noexcept

@ -19,7 +19,7 @@
#include "corewords.hpp"
#include "parser.hpp"
#include <charconv>
#include <cctype>
#include <cstring>
int Parser::parse(State& state, const char *str)
@ -79,18 +79,35 @@ int Parser::parseWord(State& state, Word word)
int Parser::parseNumber(State& state, Word word)
{
char buf[MaxCellNumberChars + 1];
unsigned i;
for (i = 0; i < std::min(MaxCellNumberChars, word.size()); ++i)
buf[i] = state.dict.readbyte(word.start + i);
buf[i] = '\0';
auto base = state.dict.read(0);
DoubleCell dl;
auto [ptr, ec] = std::from_chars(buf, buf + i, dl, base);
Cell l = static_cast<Cell>(dl);
if (ec == std::errc() && ptr == buf + i) {
const auto base = state.dict.read(Dictionary::Base);
DoubleCell result = 0;
auto i = word.start;
bool inv;
char c;
c = state.dict.readbyte(i);
if (inv = c == '-'; inv)
c = state.dict.readbyte(++i);
do {
if (isdigit(c)) {
result *= base;
result += c - '0';
} else if (isalpha(c) && base > 10) {
result *= base;
result += 10 + (c > 'a' ? c - 'a' : c - 'A');
} else {
return UnknownWord;
}
if (++i < word.end)
c = state.dict.readbyte(i);
} while (i < word.end);
if (inv)
result *= -1;
Cell value = static_cast<Cell>(result);
if (state.compiling()) {
auto ins = CoreWords::findi("_lit");
@ -98,15 +115,12 @@ int Parser::parseNumber(State& state, Word word)
// state.dict.add(ins | ((l + 1) << 8));
//} else {
state.dict.add(ins);
state.dict.add(l);
state.dict.add(value);
//}
} else {
state.push(l);
state.push(value);
}
return 0;
} else {
return UnknownWord;
}
}

Loading…
Cancel
Save