diff --git a/main.cpp b/main.cpp index 697f2d2..5921497 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,35 @@ constinit static sforth::forth<8192> forth {sforth::initialize<&forth>()}; +bool sforth_debug_hook() +{ + char c; + + std::cout << "DS: "; + for (auto it = forth.sp; it != forth.dstack.end(); it++) { + std::cout << *it << ' '; + } + std::cout << std::endl; + std::cout << "RS: "; + for (auto it = forth.rp; it != forth.rstack.end(); it++) { + if (auto w = forth.lookup(*it); w) + std::cout << (*w)->name() << '+' << ((sforth::addr)*it - std::bit_cast((*w)->body())) << ' '; + else + std::cout << *it << ' '; + } + std::cout << std::endl; + std::cout << "HERE: " << (sforth::addr)forth.here << std::endl; + std::cout << "IP: "; + if (auto w = forth.lookup(forth.ip); w) + std::cout << (*w)->name() << '+' << ((sforth::addr)forth.ip - std::bit_cast((*w)->body())) << ' '; + else + std::cout << forth.ip << ' '; + + std::cout << std::endl << "> "; + std::cin >> c; + return true; +} + static bool parse_stream(auto&, std::istream&, bool say_okay = false); constinit static sforth::native_word<".", [](auto) {