From c4ec3bea1962ae16284a6a2fb9b91e7f7ed1e136 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 27 Nov 2024 20:53:16 -0500 Subject: [PATCH] add postpone --- forth.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/forth.hpp b/forth.hpp index cc6c679..af6ecc9 100644 --- a/forth.hpp +++ b/forth.hpp @@ -300,6 +300,16 @@ struct forth if (fth.pop() == 0) fth.ip = *reinterpret_cast(ptr) - 1; }; + auto f_postpone = [](auto) { + assert(fth.compiling); + + auto w = fth.parse(); + auto g = fth.get(w); + + assert(g.has_value()); + + *fth.here++ = reinterpret_cast((*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; }