|
|
|
@ -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) {
|
|
|
|
|