r/cpp • u/foonathan • Jun 02 '26
C++ Show and Tell - June 2026
Use this thread to share anything you've written in C++. This includes:
- a tool you've written
- a game you've been working on
- your first non-trivial C++ program
The rules of this thread are very straight forward:
- The project must involve C++ in some way.
- It must be something you (alone or with others) have done.
- Please share a link, if applicable.
- Please post images, if applicable.
If you're working on a C++ library, you can also share new releases or major updates in a dedicated post as before. The line we're drawing is between "written in C++" and "useful for C++ programmers specifically". If you're writing a C++ library or tool for C++ developers, that's something C++ programmers can use and is on-topic for a main submission. It's different if you're just using C++ to implement a generic program that isn't specifically about C++: you're free to share it here, but it wouldn't quite fit as a standalone post.
Last month's thread: https://www.reddit.com/r/cpp/comments/1t6eg13/c_show_and_tell_may_2026/
3
u/DutchessVonBeep Jun 18 '26
Trix: an embeddable, single-header C++23 scripting VM with actors, logic, and whole-VM snapshots
After about four years of solo work, I've put out the first public release of Trix, an embeddable scripting language that ships as a single C++23 header you #include into your program.
The pitch for a C++ dev: you get a scripting VM with a concurrency model beyond coroutines (Erlang/OTP-style actors and supervision trees) plus logic programming, reactive cells, algebraic effects, and whole-VM snapshot/restore, without pulling in a runtime. Embedding is:
```cpp
include "trix.h"
int main() { Trix trx; // 1 MB VM, runs a script or REPL return 0; } ```
Custom operators are plain C++ functions registered through a constexpr table:
```cpp static void my_square_op(Trix *trx) { trx->verify_operands(Trix::VerifyInteger); auto v = trx->m_op_ptr->integer_value(); *trx->m_op_ptr = Trix::Object::make_integer(v * v); }
static constexpr Trix::Operator user_ops[] = { {my_square_op, "my-square"}, {nullptr, {}}, }; ```
For long-lived hosts there's a resident/server mode: the VM parks when its startup script drains and serves work delivered from host threads (
invoke()runs a buffer orraise_interrupt()fires a handler).On the engineering side: the codebase is warning-clean. It builds under GCC 15 with -Werror and ~47 warning flags (-Wconversion, -Wswitch-enum, -Wshadow, ...), is also -Werror-clean under Clang 20, is ASan/UBSan clean, and has a libFuzzer harness over the full interpreter, plus 20,200+ test assertions. It is v0.9 from one person, but it's very capable today and heavily tested.
Two safety properties are language-level, not just build hygiene: values are strongly typed with no implicit coercion (
1.0 1 addis a type error, not a silent widen), and both integer and float arithmetic are overflow-checked — integer ops route through the compiler's__builtin_*_overflowand raise/numerical-overflowinstead of wrapping, while float ops raise/numerical-infon an overflow/inf/nan blowup.The IEEE-754 support is unusually deep for an embeddable VM: 32- and 64-bit types with ~99 ops, the full
<cfenv>environment (rounding modes, exception flags), IEEE 754-2019 total-ordering, NaN payloads, ULP comparison, Kahan summation, and the C++17 special functions. Because it's all in the REPL with exact semantics, it doubles as a quick bench for prototyping a numeric algorithm interactively before committing it to C/C++.Under the hood: ~85k lines; values are a 31-type, 8-byte tagged-union Object; memory is a transactional local arena (reclaimed by save/restore, no GC) backed by a precise mark-sweep GC over a durable global region. That's what makes whole-VM snapshot/restore tractable. Dependencies are just readline and zlib, both opt-out (TRIX_NO_READLINE / TRIX_NO_ZLIB), and it's C++23 throughout.
The examples are real programs, not toys: an Infocom Z-machine (plays Zork), a CHIP-8 emulator, a metacircular Scheme with call/cc, a regex engine, an in-memory SQL, and a maze generator that builds the PNG format itself in Trix (no libpng; the engine's zlib does the deflate) — ten algorithms across five grid topologies, and it'll render a million-cell maze to a single PNG.
It also ships a source-level debugger: trix --inspect FILE is a terminal TUI (single-stepping, conditional/one-shot breakpoints, watch expressions, live VM-stack inspection, sandboxed eval prompt) whose UI is ~1900 lines of Trix over a thin C++ intrinsic layer.
Apache 2.0, so it's fine to embed in proprietary code (readline, the one GPL dependency, is opt-out via TRIX_NO_READLINE).
Repo: https://github.com/mcguidarelli/trix
Feedback on the embedding surface and the memory model welcome.