aboutsummaryrefslogtreecommitdiffstats
path: root/libalee/dictionary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libalee/dictionary.cpp')
-rw-r--r--libalee/dictionary.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/libalee/dictionary.cpp b/libalee/dictionary.cpp
index e4f6761..e946c59 100644
--- a/libalee/dictionary.cpp
+++ b/libalee/dictionary.cpp
@@ -29,6 +29,22 @@ void Dictionary::initialize()
}
LIBALEE_SECTION
+void Dictionary::addNativeWord(const char *s, void (*func)(State&))
+{
+ const Addr h = read(Here);
+ Addr n = h + sizeof(Cell);
+ for (; *s; ++s, ++n)
+ writebyte(n, *s);
+ addDefinition(Word(h + sizeof(Cell), n));
+ add(CoreWords::token("_nx"));
+ add((Cell)func);
+
+ const auto dcell = h - latest();
+ write(h, (read(h) & 0x1F) | Native | static_cast<Cell>(dcell << DistancePos));
+ latest(h);
+}
+
+LIBALEE_SECTION
Addr Dictionary::allot(Cell amount) noexcept
{
Addr old = here();