]> code.bitgloo.com Git - clyne/sforth.git/commitdiff
case insensitivity; type
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Dec 2024 20:04:17 +0000 (15:04 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 1 Dec 2024 20:04:17 +0000 (15:04 -0500)
main.cpp

index 9453531bf7567d88dba1d2dac1d428db039ac7c2..f5c93a7969690d214edce018e9854eebfd32e437 100644 (file)
--- 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<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) {