From 6e4c0430de5ade2c8375ddcdeec93d4df3b163b1 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 18 Nov 2023 08:13:19 -0500 Subject: add _nx word, use for most of core not seeing performance improvement yet --- libalee/dictionary.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libalee/dictionary.cpp') diff --git a/libalee/dictionary.cpp b/libalee/dictionary.cpp index e4f6761..e946c59 100644 --- a/libalee/dictionary.cpp +++ b/libalee/dictionary.cpp @@ -28,6 +28,22 @@ void Dictionary::initialize() write(Source, Input + sizeof(Cell)); } +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(dcell << DistancePos)); + latest(h); +} + LIBALEE_SECTION Addr Dictionary::allot(Cell amount) noexcept { -- cgit v1.2.3