aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2024-11-30 10:21:59 -0500
committerClyne Sullivan <clyne@bitgloo.com>2024-11-30 10:21:59 -0500
commit860cdb7b387723eddea9bd110c85ebeaaa6c5b70 (patch)
treef7b79d337421815b6c8c864e7a49ee9fed43a394 /main.cpp
parentcb04555442286affb56a95a54c428f8f643b3503 (diff)
compile time initialize
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index 99f5ecc..60653dc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -23,7 +23,12 @@
#include <string>
static std::array<sforth::cell, 1024> dict;
-static auto fth = new (dict.data()) sforth::forth;
+static sforth::forth *fth =
+ [] constexpr {
+ fth = new (dict.data()) sforth::forth;
+ sforth::initialize<&fth>(dict.end());
+ return fth;
+ }();
static bool parse_stream(sforth::forth *, std::istream&, bool say_okay = false);
@@ -31,7 +36,6 @@ int main(int argc, const char *argv[])
{
std::span args (argv + 1, argc - 1);
- sforth::initialize<&fth>(dict.end());
fth->add(".", [](auto) {
char buf[32] = {};
std::to_chars(buf, buf + sizeof(buf), fth->pop(), fth->base);