aboutsummaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2023-11-24 19:58:11 -0500
committerClyne Sullivan <clyne@bitgloo.com>2023-11-24 19:58:11 -0500
commit649785d46603182132209b64791f6c996497110e (patch)
treed8df15aca9e95fa75ab59772feeee7a8b69c2897 /source
parent6e6b6841ec509549dcb5ed621342cbf21ae1ec94 (diff)
add text processing words
Diffstat (limited to 'source')
-rw-r--r--source/core.cpp24
-rw-r--r--source/core.hpp4
-rw-r--r--source/state.hpp16
3 files changed, 29 insertions, 15 deletions
diff --git a/source/core.cpp b/source/core.cpp
index c97203e..0b520e8 100644
--- a/source/core.cpp
+++ b/source/core.cpp
@@ -19,6 +19,7 @@
#include "state.hpp"
#include <cctype>
+#include <cstring>
void jump(FuncList ip)
{
@@ -82,13 +83,12 @@ void align()
HERE = aligned(HERE);
}
-void word()
+static void word(int ch)
{
- // Skip leading whitespace.
int k;
do {
k = key();
- } while (isspace(k));
+ } while (k == ch);
// Collect the word's text.
char *ptr;
@@ -101,7 +101,7 @@ void word()
break;
k = key();
- } while (!isspace(k));
+ } while (k != ch);
addkey(k);
// Add a null terminator.
@@ -110,12 +110,24 @@ void word()
++HERE;
}
+void wordword()
+{
+ auto here = (char *)HERE;
+ ++HERE;
+
+ word(*SP);
+
+ here[0] = strlen(here + 1);
+ HERE = (Cell)here;
+ *SP = HERE;
+}
+
void colon()
{
// Collect (and store) the word's name.
align();
auto name = HERE;
- word();
+ word(' ');
align();
// Build the Word structure.
@@ -159,7 +171,7 @@ void tick()
{
// Get the name to look up.
auto name = (char *)HERE;
- word();
+ word(' ');
// Look up the name and push the result.
int len = HERE - (Cell)name - 1;
diff --git a/source/core.hpp b/source/core.hpp
index d85cccc..914c39b 100644
--- a/source/core.hpp
+++ b/source/core.hpp
@@ -44,8 +44,8 @@ int key(); /** Gets the next key available from the source buffer. */
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 word(); /** Gets word from source buffer, stores and allots from HERE. */
+void align(); /** Aligns HERE to the next Cell boundary. */
+void wordword(); /** 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. */
diff --git a/source/state.hpp b/source/state.hpp
index 2a4668e..17d8e69 100644
--- a/source/state.hpp
+++ b/source/state.hpp
@@ -22,15 +22,16 @@
constexpr Addr DS = 16; /** Data stack size */
constexpr Addr RS = 16; /** Return stack size */
-constexpr auto DictSize = 2048u; /** Dictionary size */
+constexpr auto DictSize = 4096u; /** Dictionary size */
constexpr Addr DIdxBase = 0;
constexpr Addr DIdxHere = 1;
constexpr Addr DIdxLatest = 2;
constexpr Addr DIdxState = 3;
-constexpr Addr DIdxSource = 4;
-constexpr Addr DIdxSrcLen = 5;
-constexpr Addr DIdxInBuf = 6;
+constexpr Addr DIdxCompXt = 4;
+constexpr Addr DIdxSource = 5;
+constexpr Addr DIdxSrcLen = 6;
+constexpr Addr DIdxInBuf = 7;
constexpr Addr DIdxBegin = DIdxInBuf + 80 * sizeof(char);
/**
@@ -52,9 +53,10 @@ extern FuncList IP; /** Instruction pointer */
*/
inline void initialize(const auto& wordset)
{
- LATEST = (Cell)wordset.latest;
- HERE = (Cell)&DICT[DIdxBegin];
- STATE = 0;
+ DICT[DIdxBase] = 10;
+ DICT[DIdxHere] = (Cell)&DICT[DIdxBegin];
+ DICT[DIdxLatest] = (Cell)wordset.latest;
+ DICT[DIdxState] = 0;
}
/**