diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-11-30 10:21:59 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-11-30 10:21:59 -0500 |
commit | 860cdb7b387723eddea9bd110c85ebeaaa6c5b70 (patch) | |
tree | f7b79d337421815b6c8c864e7a49ee9fed43a394 /main.cpp | |
parent | cb04555442286affb56a95a54c428f8f643b3503 (diff) |
compile time initialize
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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); |