SRC := $(wildcard source/*.cpp)
OBJ := $(subst .cpp,.o,$(SRC))
-CXXFLAGS += -std=c++20 -ggdb -g3 -Os \
+CXXFLAGS += -std=c++20 -ggdb -g3 -O0 \
-Wall -Wextra -pedantic \
-Isource
HERE = aligned(HERE);
}
-static void word(int ch)
+static void readword(int ch)
{
int k;
do {
k = key();
} while (k != ch);
- addkey(k);
// Add a null terminator.
ptr = reinterpret_cast<char *>(HERE);
++HERE;
}
-void wordword()
+void word()
{
auto here = (char *)HERE;
++HERE;
- word(*SP);
+ readword(*SP);
here[0] = strlen(here + 1);
HERE = (Cell)here;
// Collect (and store) the word's name.
align();
auto name = HERE;
- word(' ');
+ readword(' ');
align();
// Build the Word structure.
{
// Get the name to look up.
auto name = (char *)HERE;
- word(' ');
+ readword(' ');
// Look up the name and push the result.
int len = HERE - (Cell)name - 1;
Cell *comma(Cell n); /** Stores `n` to HERE++, returns `n`'s storage. */
Addr aligned(Addr addr); /** Aligns the given address and returns it. */
-void align(); /** Aligns HERE to the next Cell boundary. */
-void wordword(); /** Definition of WORD. */
+void align(); /** Aligns HERE to the next Cell boundary. */
+void word(); /** Definition of WORD. */
void colon(); /** Begins definition of a new word. */
void semic(); /** Ends the current word definition which becomes new LATEST. */
void tick(); /** Gets the execution token for the source buffer's next word. */
void parseSource()
{
- auto start = (char *)DICT[DIdxSource];
- auto end = start;
+ char *start = nullptr;
+ char *end;
+ char *s;
- // Try to build words while we have input available.
while (haskey()) {
- end = (char *)++DICT[DIdxSource];
+ s = (char *)DICT[DIdxSource];
+
+ ++DICT[DIdxSource];
--DICT[DIdxSrcLen];
- if (isspace(*end)) {
- // May have collected a word.
- // parseword() will check if start != end.
- parseword(start, end);
- start = (char *)(DICT[DIdxSource] + 1);
+ if (isspace(*s)) {
+ if (start) {
+ parseword(start, end + 1);
+ start = nullptr;
+ }
+ } else {
+ if (!start) {
+ start = s;
+ end = start;
+ } else {
+ ++end;
+ }
}
}
// Parse the final word if it is non-empty.
- if (start != end)
- parseword(start, end);
+ if (start)
+ parseword(start, s + 1);
}
void parse()
Word("_i", WordWrap<[] { *SP = ((Word *)*SP)->immediate(); }, tobool>()),
Word("[']", WordWrap<tick, compileliteral>()).markImmediate(),
Word("compile,", WordWrap<peek, commaSP>()),
- Word("word", WordWrap<wordword>()),
+ Word("word", WordWrap<word>()),
Word("_b", WordWrap<[] {
std::putchar('#'); // Gives a good breakpoint spot for gdb
}>()),