diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-12-01 15:04:17 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-12-01 15:04:17 -0500 |
commit | 3dfa3094cdf52910abeadc23556df20e37f6cac8 (patch) | |
tree | 39c86d85b64cd223d894bae05e933acef7e96c9b | |
parent | d8b279b7709410112002828199b0261508a9dda4 (diff) |
case insensitivity; type
-rw-r--r-- | main.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -37,6 +37,11 @@ constinit static sforth::native_word<".", [](auto) { constinit static sforth::native_word<"emit", [](auto) { std::cout << static_cast<char>(forth.pop()); }, &dot> emit; +constinit static sforth::native_word<"type", [](auto) { + const unsigned u = forth.pop(); + const auto caddr = reinterpret_cast<const char *>(forth.pop()); + std::cout << std::string_view{caddr, u}; +}, &emit> type; static bool parse_stream(auto&, std::istream&, bool say_okay = false); @@ -44,7 +49,7 @@ int main(int argc, const char *argv[]) { std::span args (argv + 1, argc - 1); - dot.next = std::exchange(forth.next, &emit); + dot.next = std::exchange(forth.next, &type); for (auto arg : args) { if (std::ifstream file {arg}; parse_stream(forth, file)) @@ -64,6 +69,11 @@ bool parse_stream(auto &fth, std::istream& str, bool say_okay) if (line == "bye") return true; + for (auto& ch : line) { + if (ch >= 'A' && ch <= 'Z') + ch = ch - 'A' + 'a'; + } + try { fth.parse_line(line); } catch (sforth::error e) { |