aboutsummaryrefslogtreecommitdiffstats
path: root/source/types.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/types.hpp')
-rw-r--r--source/types.hpp49
1 files changed, 12 insertions, 37 deletions
diff --git a/source/types.hpp b/source/types.hpp
index 0552135..aedc0d3 100644
--- a/source/types.hpp
+++ b/source/types.hpp
@@ -1,5 +1,5 @@
// sprit-forth: A portable subroutine-threaded Forth.
-// Copyright (C) 2023 Clyne Sullivan <clyne@bitgloo.com>
+// Copyright (C) 2024 Clyne Sullivan <clyne@bitgloo.com>
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Library General Public License as published by
@@ -21,6 +21,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
+#include <memory>
using Cell = intptr_t; /** Type of a dictionary's cell. */
using Addr = uintptr_t; /** Type of a dictionary address. */
@@ -34,6 +35,16 @@ static_assert(sizeof(Cell) == sizeof(Addr));
static_assert(sizeof(Cell) == sizeof(Func));
/**
+ * Wraps the given functions so that a function pointer list can be created
+ * and used for a word's definition.
+ */
+template<auto... funcs>
+constexpr auto WordWrap = []() noexcept {
+ constexpr static auto wrapper = +[] { (funcs(), ...); };
+ return &wrapper;
+}();
+
+/**
* @struct Word
* @brief Structure of a word's definition.
* A word has a name, a body (list of functions), a link to the next word
@@ -69,42 +80,6 @@ static_assert(offsetof(Word, link) == 2 * sizeof(Cell));
static_assert(offsetof(Word, imm) == 3 * sizeof(Cell));
static_assert(sizeof(Word) == 4 * sizeof(Cell));
-/**
- * @struct WordSet
- * @brief Groups a set of pre-defined words and links them.
- */
-template<typename... Words>
-struct WordSet
-{
- std::array<Word, sizeof...(Words)> words;
- Word *latest;
-
- /**
- * Stores the given pre-defined words into the `words` array and links
- * their definitions together. The resulting `latest` value can be used
- * to set the global LATEST.
- */
- constexpr WordSet(Words... ws):
- words {ws...}
- {
- auto it = words.begin();
- while (++it != words.end())
- it->link = it - 1;
-
- latest = &*words.rbegin();
- }
-};
-
-/**
- * Wraps the given functions so that a function pointer list can be created
- * and used for a word's definition.
- */
-template<auto... funcs>
-constexpr auto WordWrap = []() noexcept {
- constexpr static auto wrapper = +[] { (funcs(), ...); };
- return &wrapper;
-}();
-
enum class Error : int {
none = 1,
push,