diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2025-01-04 06:21:34 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2025-01-04 06:21:34 -0500 |
commit | b29adddef9659ebce1bdde2d595fd6a7009dcb98 (patch) | |
tree | d455b71ce46122b3cafea7d2616da570a30279d2 | |
parent | f8fdc3746ca3f4a3b4e913b0bf34ce475eca0bf5 (diff) |
mediocre debugger
-rw-r--r-- | main.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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<sforth::addr>((*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<sforth::addr>((*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) { |