]> code.bitgloo.com Git - clyne/sforth.git/commitdiff
more words, aiming to run tests
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Dec 2024 20:04:35 +0000 (15:04 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Dec 2024 20:04:35 +0000 (15:04 -0500)
sforth/forth.hpp

index 9e0a59edac04eff5cc6ef812a5da4976b380ab5d..52d0585a0ebec7ccc0be7373565872bd7824edcd 100644 (file)
@@ -208,6 +208,7 @@ constexpr auto initialize()
         , S{"dp"   }, [](auto) { fthp->push(std::bit_cast<cell>(fthp) + 4 * sizeof(cell)); }, 0
         , S{"state"}, [](auto) { fthp->push(std::bit_cast<cell>(fthp) + 7 * sizeof(cell)); }, 0
         , S{"base" }, [](auto) { fthp->push(std::bit_cast<cell>(fthp) + 8 * sizeof(cell)); }, 0
+        , S{"depth"}, [](auto) { fthp->push(std::distance(fthp->sp, fthp->dstack.end())); }, 0
         , S{"unused"}, [](auto) { fthp->push(sizeof(cell) * std::distance(fthp->here, fthp->dict.end())); }, 0
         , S{"_lit" }, lit_impl, 0
         , S{"swap" }, [](auto) { auto a = fthp->pop(); auto b = fthp->pop(); fthp->push(a, b); }, 0
@@ -264,6 +265,13 @@ constexpr auto initialize()
             auto g = fthp->get(w);
             assert<error::word_not_found>(g.has_value());
             *fthp->here++ = std::bit_cast<cell>((*g)->body()); }, word_base::immediate
+        , S{"source"}, [](auto) {
+            auto len = 0u;
+            while (fthp->source[len])
+                len++;
+            fthp->push(std::bit_cast<cell>(fthp->source));
+            fthp->push(len); }, 0
+        , S{">in"}, [](auto) { fthp->push(std::bit_cast<cell>(&fthp->sourcei)); }, 0
     >::word;
     constexpr static auto& dict2 = comp_dict<prologue, &dict1
         , S{"align"  }, S{"here dup aligned swap - allot"}, 0
@@ -303,6 +311,8 @@ constexpr auto initialize()
         , S{"negate"}, S{"-1 *"}, 0
         , S{"2*"    }, S{"2 *"}, 0
         , S{"bl"    }, S{"32"}, 0
+        , S{"false" }, S{"0"}, 0
+        , S{"true"  }, S{"-1"}, 0
     >::word;
 
     return &dict2;