aboutsummaryrefslogtreecommitdiffstats
path: root/source/state.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/state.hpp')
-rw-r--r--source/state.hpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/source/state.hpp b/source/state.hpp
index 91ce12f..2a4668e 100644
--- a/source/state.hpp
+++ b/source/state.hpp
@@ -20,8 +20,9 @@
#include "types.hpp"
-constexpr Addr DS = 16;
-constexpr Addr RS = 16;
+constexpr Addr DS = 16; /** Data stack size */
+constexpr Addr RS = 16; /** Return stack size */
+constexpr auto DictSize = 2048u; /** Dictionary size */
constexpr Addr DIdxBase = 0;
constexpr Addr DIdxHere = 1;
@@ -32,16 +33,23 @@ constexpr Addr DIdxSrcLen = 5;
constexpr Addr DIdxInBuf = 6;
constexpr Addr DIdxBegin = DIdxInBuf + 80 * sizeof(char);
-extern std::array<Cell, 2048> DICT;
+/**
+ * Memory chunk used to store the dictoinary and stacks.
+ */
+extern std::array<Cell, DictSize> DICT;
-extern Cell& HERE;
-extern Cell& LATEST;
-extern Cell& STATE;
+extern Cell& HERE; /** Linked to HERE's storage in DICT. */
+extern Cell& LATEST; /** Linked to LATEST's storage in DICT. */
+extern Cell& STATE; /** Linked to STATE's storage in DICT. */
-extern Cell *SP;
-extern Cell *RP;
-extern FuncList IP;
+extern Cell *SP; /** Data stack pointer */
+extern Cell *RP; /** Return stack pointer */
+extern FuncList IP; /** Instruction pointer */
+/**
+ * Initializes the dictionary to default values.
+ * @param wordset The initial WordSet of pre-defined words.
+ */
inline void initialize(const auto& wordset)
{
LATEST = (Cell)wordset.latest;
@@ -49,8 +57,24 @@ inline void initialize(const auto& wordset)
STATE = 0;
}
+/**
+ * Begins execution with the given function pointer list.
+ * @param list Function pointer list to execute
+ */
void executor(FuncList *list);
+
+/**
+ * Executes the given word by calling executor on its definition.
+ * @param word The word to execute
+ */
void execute1(Word *word);
+
+/**
+ * Looks up the definition of the given word.
+ * @param s The name of the word to find
+ * @param len The character count of the word's name
+ * @return Pointer to the word's definition or nullptr if not found
+ */
Word *find(const char *s, int len);
#endif // STATE_HPP