]> code.bitgloo.com Git - clyne/sforth.git/commitdiff
add postpone
authorClyne Sullivan <clyne@bitgloo.com>
Thu, 28 Nov 2024 01:53:16 +0000 (20:53 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Thu, 28 Nov 2024 01:53:16 +0000 (20:53 -0500)
forth.hpp

index cc6c67958b2da002b3fc0a4f324ab6bca056c7d9..af6ecc9aa146b2969549454ade8d1b25283401b4 100644 (file)
--- a/forth.hpp
+++ b/forth.hpp
@@ -300,6 +300,16 @@ struct forth
             if (fth.pop() == 0)
                 fth.ip = *reinterpret_cast<func **>(ptr) - 1;
         };
+        auto f_postpone = [](auto) {
+            assert<error::compile_only_word>(fth.compiling);
+
+            auto w = fth.parse();
+            auto g = fth.get(w);
+
+            assert<error::word_not_found>(g.has_value());
+
+            *fth.here++ = reinterpret_cast<cell>((*g)->body());
+        };
 
         constexpr static word w_dict {"_d", f_dict};
         constexpr static word w_add {"+", f_add, &w_dict};
@@ -333,8 +343,9 @@ struct forth
         constexpr static word w_cell {"cell", f_cell, &w_comm};
         constexpr static word w_jmp {"_jmp", f_jmp, &w_cell};
         constexpr static word w_jmp0 {"_jmp0", f_jmp0, &w_jmp};
+        constexpr static word w_postp {"postpone", f_postpone, &w_jmp0, word_base::immediate};
 
-        fth.latest = &w_jmp0;
+        fth.latest = &w_postp;
         fth.end = end_value;
     }