aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2024-12-19 17:18:08 -0500
committerClyne Sullivan <clyne@bitgloo.com>2024-12-19 17:18:08 -0500
commit3246deb437054ff67e600a95d05535251642ad76 (patch)
tree03f5eab13e74ce112ad612073442854840f56f91
parentb5ec68178067372c267831d64cf6e515435c9bef (diff)
include, test.fth
-rw-r--r--main.cpp12
-rw-r--r--test.fth5
2 files changed, 14 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 83c3a81..ec2e02c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -25,6 +25,8 @@
constinit static sforth::forth<4096> forth {sforth::initialize<&forth>()};
+static bool parse_stream(auto&, std::istream&, bool say_okay = false);
+
constinit static sforth::native_word<".", [](auto) {
char buf[8 * sizeof(sforth::cell) + 1] = {};
std::to_chars(buf, buf + sizeof(buf), forth.pop(), forth.base);
@@ -43,14 +45,18 @@ constinit static sforth::native_word<"TYPE", [](auto) {
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);
+constinit static sforth::native_word<"INCLUDE", [](auto) {
+ const auto w = forth.parse();
+ std::string s {w.begin(), w.end()};
+ std::ifstream file {s};
+ parse_stream(forth, file);
+}, &type> incl;
int main(int argc, const char *argv[])
{
std::span args (argv + 1, argc - 1);
- dot.next = std::exchange(forth.next, &type);
+ dot.next = std::exchange(forth.next, &incl);
for (auto arg : args) {
if (std::ifstream file {arg}; parse_stream(forth, file))
diff --git a/test.fth b/test.fth
new file mode 100644
index 0000000..0a3bc1a
--- /dev/null
+++ b/test.fth
@@ -0,0 +1,5 @@
+include core.fth
+include forth2012-test-suite/src/tester.fr
+include forth2012-test-suite/src/core.fr
+cr
+bye