From 3dfa3094cdf52910abeadc23556df20e37f6cac8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 1 Dec 2024 15:04:17 -0500 Subject: [PATCH] case insensitivity; type --- main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9453531..f5c93a7 100644 --- a/main.cpp +++ b/main.cpp @@ -37,6 +37,11 @@ constinit static sforth::native_word<".", [](auto) { constinit static sforth::native_word<"emit", [](auto) { std::cout << static_cast(forth.pop()); }, &dot> emit; +constinit static sforth::native_word<"type", [](auto) { + const unsigned u = forth.pop(); + const auto caddr = reinterpret_cast(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) {