<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>TinyComputers.io (Posts about software-engineering)</title><link>https://tinycomputers.io/</link><description></description><atom:link href="https://tinycomputers.io/categories/cat_software-engineering.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Original site content © 2022–2026 Tiny Machines Workshop, LLC, except where otherwise noted. Some rights reserved.</copyright><lastBuildDate>Sun, 15 Nov 2026 05:37:00 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>From Tree-Walker to Bytecode VM: Compiling Lattice</title><link>https://tinycomputers.io/posts/from-tree-walker-to-bytecode-vm-compiling-lattice.html?utm_source=feed&amp;utm_medium=rss&amp;utm_campaign=rss</link><dc:creator>A.C. Jokela</dc:creator><description>&lt;div class="audio-widget"&gt;
&lt;div class="audio-widget-header"&gt;
&lt;span class="audio-widget-icon"&gt;🎧&lt;/span&gt;
&lt;span class="audio-widget-label"&gt;Listen to this article&lt;/span&gt;
&lt;/div&gt;
&lt;audio controls preload="metadata"&gt;
&lt;source src="https://tinycomputers.io/from-tree-walker-to-bytecode-vm-compiling-lattice_tts.mp3" type="audio/mpeg"&gt;
&lt;/source&gt;&lt;/audio&gt;
&lt;div class="audio-widget-footer"&gt;16 min · AI-generated narration&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Lattice is a programming language built around a &lt;a href="https://tinycomputers.io/posts/introducing-lattice-a-crystallization-based-programming-language.html"&gt;crystallization-based phase system&lt;/a&gt;: values start as mutable "flux" and can be frozen into immutable "fix," with the runtime enforcing the transition and providing &lt;a href="https://tinycomputers.io/posts/mutability-as-a-first-class-concept-the-lattice-phase-system.html"&gt;reactions, bonds, contracts, and temporal tracking&lt;/a&gt; around it. It's implemented in C with no external dependencies.&lt;/p&gt;
&lt;p&gt;When I started building &lt;a href="https://go.tinymachines.io/uqKWe2"&gt;Lattice&lt;/a&gt;, a tree-walking interpreter was the obvious first move. You parse source into an AST, walk the nodes recursively, and evaluate as you go. It's straightforward, easy to debug, and lets you iterate on language semantics quickly without worrying about a second representation. &lt;a href="https://go.tinymachines.io/eKC5Kf"&gt;&lt;em&gt;Crafting Interpreters&lt;/em&gt;&lt;/a&gt; calls this approach "the simplest way to build an interpreter," and it's right.&lt;/p&gt;
&lt;p&gt;But tree-walkers have well-known limitations. Every expression evaluation descends through function calls: &lt;code&gt;eval_expr&lt;/code&gt; calling &lt;code&gt;eval_binary&lt;/code&gt; calling &lt;code&gt;eval_expr&lt;/code&gt; twice more. The overhead compounds. You're chasing pointers through heap-allocated AST nodes with poor cache locality. And the call stack of the host language (C, in Lattice's case) becomes tangled with the call stack of the guest language, making it harder to implement features like error recovery and coroutines cleanly.&lt;/p&gt;
&lt;p&gt;Lattice v0.3.0 shipped a bytecode compiler and stack-based virtual machine alongside the tree-walker. In v0.3.1, the bytecode VM became the default for file execution, the interactive REPL, and the browser-based playground. The tree-walker is still available via &lt;code&gt;--tree-walk&lt;/code&gt;, but the VM now handles everything. This post walks through the architecture of that VM, some design decisions that turned out to matter, and a mutation bug that only surfaces when you combine deep-clone-on-read semantics with in-place method dispatch.&lt;/p&gt;
&lt;h3&gt;Architecture Overview&lt;/h3&gt;
&lt;p&gt;The bytecode pipeline has three stages: lexing and parsing (shared with the tree-walker), compilation from AST to bytecode chunks, and execution on a stack-based VM. The compiler and VM together add about 8,200 lines of C to the codebase, bringing the total to around 33,000 lines.&lt;/p&gt;
&lt;p&gt;A &lt;code&gt;Chunk&lt;/code&gt; is the compilation unit: a dynamic array of bytecode instructions, a constant pool, and debug metadata mapping instructions back to source line numbers. The compiler walks the AST and emits bytes into a chunk. The VM reads bytes from the chunk and executes them against a value stack.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;typedef&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="c1"&gt;// bytecode array&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;cap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c1"&gt;// constant pool&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;const_len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;const_cap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="c1"&gt;// source line per instruction&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;local_names&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c1"&gt;// slot → variable name (debug)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;local_name_cap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Chunk&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The VM itself is a &lt;code&gt;for(;;)&lt;/code&gt; loop with a &lt;code&gt;switch&lt;/code&gt; on the current opcode byte, the textbook approach. No computed gotos, no threaded dispatch, no JIT. Just a switch. On modern hardware with branch prediction, a well-organized switch over 62 opcodes is fast enough that the overhead is negligible compared to the cost of actual operations (string allocation, hash table lookups, deep cloning).&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(;;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;OP_CONSTANT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;OP_ADD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;OP_CALL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// 59 more cases&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The value stack holds 4,096 slots. The call frame stack holds 256 frames. Each &lt;code&gt;CallFrame&lt;/code&gt; tracks its own instruction pointer, a base pointer into the value stack for its local variables, and an array of captured upvalues for closures. When you call a function, the VM pushes a new frame pointing at the callee's chunk. When the function returns, the frame pops and execution resumes in the caller.&lt;/p&gt;
&lt;h3&gt;The Instruction Set&lt;/h3&gt;
&lt;p&gt;Lattice's instruction set has 62 opcodes. Some are standard (&lt;code&gt;OP_ADD&lt;/code&gt;, &lt;code&gt;OP_JUMP_IF_FALSE&lt;/code&gt;, &lt;code&gt;OP_RETURN&lt;/code&gt;). Others exist because of Lattice-specific semantics.&lt;/p&gt;
&lt;p&gt;The phase system needs dedicated opcodes. &lt;code&gt;OP_FREEZE&lt;/code&gt; pops a value, deep-clones it into a crystal region with &lt;code&gt;VTAG_CRYSTAL&lt;/code&gt; tags, and pushes the frozen result. &lt;code&gt;OP_THAW&lt;/code&gt; does the reverse. &lt;code&gt;OP_MARK_FLUID&lt;/code&gt; sets the phase tag to &lt;code&gt;VTAG_FLUID&lt;/code&gt;; this is what &lt;code&gt;flux&lt;/code&gt; bindings emit after their initializer. &lt;code&gt;OP_FREEZE_VAR&lt;/code&gt; and &lt;code&gt;OP_THAW_VAR&lt;/code&gt; handle the case where &lt;code&gt;freeze(x)&lt;/code&gt; targets a named variable and needs to write back the result, carrying extra operands to identify the variable's location (local slot, upvalue, or global name).&lt;/p&gt;
&lt;p&gt;Phase reactions and bonds each have their own opcodes: &lt;code&gt;OP_REACT&lt;/code&gt;, &lt;code&gt;OP_UNREACT&lt;/code&gt;, &lt;code&gt;OP_BOND&lt;/code&gt;, &lt;code&gt;OP_UNBOND&lt;/code&gt;, &lt;code&gt;OP_SEED&lt;/code&gt;, &lt;code&gt;OP_UNSEED&lt;/code&gt;. These could theoretically be implemented as native function calls, but making them opcodes lets the compiler emit the variable name as a constant operand, and the VM needs the name to look up the correct reaction/bond registration in its tracking tables, and encoding it in the bytecode avoids a runtime string lookup.&lt;/p&gt;
&lt;p&gt;Structured concurrency uses an interesting hybrid. &lt;code&gt;OP_SCOPE&lt;/code&gt; and &lt;code&gt;OP_SELECT&lt;/code&gt; each carry a constant-pool index that stores a pointer to the original AST &lt;code&gt;Expr*&lt;/code&gt; node. When the VM hits one of these opcodes, it invokes the tree-walking evaluator on that subtree. This is a deliberate design choice; the concurrency primitives involve spawning threads and managing channels, which requires the evaluator's full environment machinery. Rather than reimplement all of that in the VM, the bytecode compiler punts to the tree-walker for these specific constructs. The rest of the program runs on the VM; only &lt;code&gt;scope&lt;/code&gt; and &lt;code&gt;select&lt;/code&gt; blocks briefly drop into interpretation.&lt;/p&gt;
&lt;h3&gt;Closures and Upvalues&lt;/h3&gt;
&lt;p&gt;Closures are where bytecode VMs get interesting, and Lattice follows the upvalue model that Lua pioneered and Crafting Interpreters popularized.&lt;/p&gt;
&lt;p&gt;When a function is defined inside another function and references variables from the enclosing scope, those variables need to outlive their original stack frame. The solution is upvalues, indirection objects that start pointing into the stack and get "closed over" when the variable goes out of scope.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;typedef&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;ObjUpvalue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// points to stack slot or &amp;amp;closed&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;closed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="c1"&gt;// holds value after scope exit&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;ObjUpvalue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="c1"&gt;// linked list for open upvalues&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ObjUpvalue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;While the enclosing function is still executing, &lt;code&gt;location&lt;/code&gt; points directly at the stack slot. When the enclosing function returns, &lt;code&gt;OP_CLOSE_UPVALUE&lt;/code&gt; copies the stack value into the &lt;code&gt;closed&lt;/code&gt; field and repoints &lt;code&gt;location&lt;/code&gt; to &lt;code&gt;&amp;amp;closed&lt;/code&gt;. The closure doesn't know or care about the switch; it always dereferences &lt;code&gt;location&lt;/code&gt;. This is why upvalues work: they're a level of indirection that transparently survives stack frame destruction.&lt;/p&gt;
&lt;p&gt;The compiler resolves variable references in three stages: first it checks local scope (&lt;code&gt;resolve_local&lt;/code&gt;), then upvalues (&lt;code&gt;resolve_upvalue&lt;/code&gt;, which walks the compiler chain recursively), then falls back to globals via &lt;code&gt;OP_GET_GLOBAL&lt;/code&gt;. The &lt;code&gt;OP_CLOSURE&lt;/code&gt; instruction is followed by a series of &lt;code&gt;(is_local, index)&lt;/code&gt; byte pairs, one per upvalue, telling the VM whether to capture from the current frame's stack or from the parent frame's upvalue array.&lt;/p&gt;
&lt;p&gt;A concrete example makes this clearer. Consider a counter factory:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;fn make_counter() {
    flux count = 0
    return |n| { count += n; count }
}

let c = make_counter()
print(c(5))   // 5
print(c(3))   // 8
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;When &lt;code&gt;make_counter&lt;/code&gt; returns, its stack frame is destroyed, but &lt;code&gt;count&lt;/code&gt; needs to survive, because the returned closure references it. During compilation, the compiler sees that the closure's body references &lt;code&gt;count&lt;/code&gt;, which is local to the enclosing &lt;code&gt;make_counter&lt;/code&gt;. It emits an &lt;code&gt;(is_local=true, index=1)&lt;/code&gt; upvalue descriptor. At runtime, &lt;code&gt;OP_CLOSURE&lt;/code&gt; calls &lt;code&gt;capture_upvalue()&lt;/code&gt;, which either reuses an existing &lt;code&gt;ObjUpvalue&lt;/code&gt; pointing at that stack slot or creates a new one. When &lt;code&gt;make_counter&lt;/code&gt; returns, &lt;code&gt;OP_CLOSE_UPVALUE&lt;/code&gt; copies the stack value of &lt;code&gt;count&lt;/code&gt; into the upvalue's &lt;code&gt;closed&lt;/code&gt; field and repoints &lt;code&gt;location&lt;/code&gt;. The closure keeps working, oblivious to the frame being gone.&lt;/p&gt;
&lt;p&gt;One implementation detail worth noting: Lattice stores the upvalue array by repurposing the closure's &lt;code&gt;captured_env&lt;/code&gt; field (normally an &lt;code&gt;Env*&lt;/code&gt; in the tree-walker) and the upvalue count in the &lt;code&gt;region_id&lt;/code&gt; field. This avoids adding new fields to the &lt;code&gt;LatValue&lt;/code&gt; union, which matters when values are deep-cloned frequently, since every field adds to the clone cost.&lt;/p&gt;
&lt;h3&gt;Compiling for the REPL&lt;/h3&gt;
&lt;p&gt;A REPL that runs on a bytecode VM needs different compilation from file execution. The difference is small but important.&lt;/p&gt;
&lt;p&gt;In file mode, &lt;code&gt;compile_module()&lt;/code&gt; compiles a complete program and terminates with &lt;code&gt;OP_UNIT; OP_RETURN&lt;/code&gt;; the module returns unit, and any expression results along the way are discarded with &lt;code&gt;OP_POP&lt;/code&gt;. This is the right behavior for scripts: you don't want every intermediate expression to accumulate on the stack.&lt;/p&gt;
&lt;p&gt;In REPL mode, &lt;code&gt;compile_repl()&lt;/code&gt; needs the opposite behavior for the last expression. When you type &lt;code&gt;42&lt;/code&gt; at the REPL prompt, you want to see &lt;code&gt;=&amp;gt; 42&lt;/code&gt;. So if the last item in the compiled chunk is a bare expression statement, &lt;code&gt;compile_repl()&lt;/code&gt; compiles the expression but &lt;em&gt;skips the &lt;code&gt;OP_POP&lt;/code&gt;&lt;/em&gt;, leaving the value on the stack. Then it emits &lt;code&gt;OP_RETURN&lt;/code&gt;, and the VM receives the value as the chunk's return value.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;last_is_expr&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;item_count&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;item_count&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ITEM_STMT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;item_count&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;STMT_EXPR&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_is_expr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;emit_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OP_RETURN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;// value already on stack&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;emit_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OP_UNIT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;         &lt;/span&gt;&lt;span class="c1"&gt;// no expression — return unit&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;emit_byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;OP_RETURN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For function definitions, struct declarations, and enum definitions, the result is unit, and the REPL silently suppresses the &lt;code&gt;=&amp;gt;&lt;/code&gt; output. This matches user expectations: defining a function shouldn't print anything. The effect in practice:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;
&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;" world"&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;"hello world"&lt;/span&gt;
&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;flux&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;lattice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;49&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Each line is independently compiled and executed on the persistent VM. Globals defined in one line (&lt;code&gt;flux x = 10&lt;/code&gt;) are visible in subsequent lines because they're stored in the VM's environment, which persists across iterations. The &lt;code&gt;Chunk&lt;/code&gt; for each line is freed after execution; constants that matter (like global variable values) have already been deep-cloned into the environment.&lt;/p&gt;
&lt;p&gt;The other critical difference is enum persistence. &lt;code&gt;compile_module()&lt;/code&gt; frees its known-enum registry after compilation, because the compiler is done. &lt;code&gt;compile_repl()&lt;/code&gt; must not, because enums defined in REPL iteration N need to be visible in iteration N+1. The REPL calls &lt;code&gt;compiler_free_known_enums()&lt;/code&gt; only on exit. The same lifetime concern applies to parsed programs; struct and function declarations store &lt;code&gt;Expr*&lt;/code&gt; pointers that compiled chunks reference at runtime. The REPL accumulates all parsed programs in a dynamic array and frees them only when the session ends.&lt;/p&gt;
&lt;h3&gt;The Global Mutation Bug&lt;/h3&gt;
&lt;p&gt;This is the story I find most instructive, because it reveals a subtle interaction between two independently reasonable design decisions.&lt;/p&gt;
&lt;p&gt;Lattice has &lt;strong&gt;deep-clone-on-read&lt;/strong&gt; semantics. When you access a variable, the environment doesn't hand you a reference to the stored value; it hands you a fresh deep clone. This eliminates aliasing entirely: two variables never share underlying memory, passing a map to a function gives the function its own copy, and there's no way to create spooky action at a distance through shared mutable state.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;env_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Env&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;size_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lat_map_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="mi"&gt;-1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value_deep_clone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;// always a fresh copy&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is expensive but correct. It gives Lattice pure value semantics without needing a borrow checker or persistent data structures.&lt;/p&gt;
&lt;p&gt;The tree-walking evaluator handles in-place mutation (like &lt;code&gt;array.push()&lt;/code&gt;) with a separate &lt;code&gt;resolve_lvalue()&lt;/code&gt; mechanism that obtains a direct mutable pointer into the environment's storage, bypassing the deep clone. Push, pop, index assignment: these all go through &lt;code&gt;resolve_lvalue&lt;/code&gt; and mutate the stored value directly.&lt;/p&gt;
&lt;p&gt;The bytecode VM needed the same distinction. For local variables, this is straightforward: locals live on the value stack, and the VM has a direct pointer to them via &lt;code&gt;frame-&amp;gt;slots[slot]&lt;/code&gt;. I added &lt;code&gt;OP_INVOKE_LOCAL&lt;/code&gt;, which takes a stack slot index as an operand and passes a pointer to &lt;code&gt;vm_invoke_builtin()&lt;/code&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;OP_INVOKE_LOCAL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;method_idx&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;arg_count&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;method_name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;method_idx&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;str_val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;slots&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;// direct pointer&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm_invoke_builtin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;method_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;arg_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;local_var_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// builtin mutated obj in-place — mutation persists&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ... fall through to closure/method dispatch&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;When &lt;code&gt;.push()&lt;/code&gt; grows the array by reallocating &lt;code&gt;obj-&amp;gt;as.array.elems&lt;/code&gt; and incrementing &lt;code&gt;obj-&amp;gt;as.array.len&lt;/code&gt;, it's directly modifying the stack slot. The mutation persists because &lt;code&gt;obj&lt;/code&gt; &lt;em&gt;is&lt;/em&gt; the variable.&lt;/p&gt;
&lt;p&gt;For globals, the situation is different. Globals live in the environment (a scope-chain of hash maps), and &lt;code&gt;env_get()&lt;/code&gt; deep-clones. The generic &lt;code&gt;OP_INVOKE&lt;/code&gt; opcode works by evaluating the receiver expression onto the stack (which, for a global variable, means emitting &lt;code&gt;OP_GET_GLOBAL&lt;/code&gt;, which calls &lt;code&gt;env_get()&lt;/code&gt;, which deep-clones) and then dispatching the method on the cloned value. After the builtin mutates the clone, &lt;code&gt;OP_INVOKE&lt;/code&gt; pops and &lt;em&gt;frees&lt;/em&gt; it. The mutation vanishes.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux nums = [1, 2, 3]
nums.push(4)
print(nums)  // still [1, 2, 3] — the push mutated a clone
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is the kind of bug that's obvious in retrospect but invisible when you're implementing things one piece at a time. &lt;code&gt;env_get()&lt;/code&gt; deep-cloning is correct. &lt;code&gt;OP_INVOKE&lt;/code&gt; popping the receiver after dispatch is correct. Each piece behaves correctly in isolation. The bug emerges from their composition.&lt;/p&gt;
&lt;p&gt;The fix is &lt;code&gt;OP_INVOKE_GLOBAL&lt;/code&gt;, a new opcode that knows the receiver is a global variable and writes back after mutation:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;OP_INVOKE_GLOBAL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name_idx&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;method_idx&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kt"&gt;uint8_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;arg_count&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;READ_BYTE&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;global_name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name_idx&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;str_val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;char&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;method_name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;method_idx&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;str_val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LatValue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;obj_val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;env_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;global_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;obj_val&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;VM_ERROR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"undefined variable '%s'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;global_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm_invoke_builtin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;obj_val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;method_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;arg_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;global_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cm"&gt;/* handle error */&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// Write back the mutated clone to the environment&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;env_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;global_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;obj_val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ... fall through for non-builtin methods&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The compiler emits &lt;code&gt;OP_INVOKE_GLOBAL&lt;/code&gt; when it sees a method call on an identifier that isn't a local variable or an upvalue:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;EXPR_METHOD_CALL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method_call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EXPR_IDENT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;resolve_local&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method_call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;str_val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="c1"&gt;// ... emit OP_INVOKE_LOCAL&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;upvalue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;resolve_upvalue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method_call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;as&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;str_val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;upvalue&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="c1"&gt;// Not local, not upvalue — must be global&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="c1"&gt;// ... emit OP_INVOKE_GLOBAL&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ... fall through to generic OP_INVOKE&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This gives us three tiers of method dispatch: &lt;code&gt;OP_INVOKE_LOCAL&lt;/code&gt; for locals (direct pointer, no clone), &lt;code&gt;OP_INVOKE_GLOBAL&lt;/code&gt; for globals (clone + write-back), and &lt;code&gt;OP_INVOKE&lt;/code&gt; for everything else (computed receivers like &lt;code&gt;get_array().push(x)&lt;/code&gt;, where there's nothing to write back to). With the fix:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux nums = [1, 2, 3]
nums.push(4)
nums.push(5)
print(nums)  // [1, 2, 3, 4, 5] — mutations persist
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;All mutating builtins (&lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, &lt;code&gt;set&lt;/code&gt;, &lt;code&gt;remove&lt;/code&gt;, &lt;code&gt;insert&lt;/code&gt;, &lt;code&gt;remove_at&lt;/code&gt;) now work correctly on global variables. The same pattern applies to maps, sets, and any other type with in-place methods.&lt;/p&gt;
&lt;p&gt;The broader lesson is that deep-clone-on-read semantics create an impedance mismatch with in-place mutation. In a reference-based language, &lt;code&gt;obj.push(x)&lt;/code&gt; just works; &lt;code&gt;obj&lt;/code&gt; is a reference, and the mutation happens wherever the reference points. In a value-based language, you need to explicitly handle the write-back for every level of variable storage. The tree-walker's &lt;code&gt;resolve_lvalue&lt;/code&gt; is one solution. The VM's tiered invoke opcodes are another. Both exist because of the same underlying tension.&lt;/p&gt;
&lt;h3&gt;The WASM Playground&lt;/h3&gt;
&lt;p&gt;Lattice's browser-based &lt;a href="https://go.tinymachines.io/rbMgu6"&gt;playground&lt;/a&gt; compiles the entire VM to WebAssembly via Emscripten. The WASM API exposes four functions: &lt;code&gt;lat_init()&lt;/code&gt;, &lt;code&gt;lat_run_line()&lt;/code&gt;, &lt;code&gt;lat_is_complete()&lt;/code&gt;, and &lt;code&gt;lat_destroy()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The playground runs the same bytecode VM as the native binary. Each line of input goes through the same pipeline: lex, parse, &lt;code&gt;compile_repl()&lt;/code&gt;, &lt;code&gt;vm_run()&lt;/code&gt;. The &lt;code&gt;lat_is_complete()&lt;/code&gt; function checks bracket depth to determine whether the user is mid-expression, enabling multi-line input by waiting for balanced braces before compiling.&lt;/p&gt;
&lt;p&gt;Previously the playground used the tree-walking evaluator, which meant code could behave differently in the browser than on the command line. Switching the WASM build to the bytecode VM eliminates that inconsistency; the playground, the REPL, and file execution all use the same compilation and execution path.&lt;/p&gt;
&lt;h3&gt;What Didn't Change&lt;/h3&gt;
&lt;p&gt;It's worth noting what the bytecode VM &lt;em&gt;doesn't&lt;/em&gt; change about Lattice.&lt;/p&gt;
&lt;p&gt;The value representation is identical. A &lt;code&gt;LatValue&lt;/code&gt; is still a tagged union with a type tag, phase tag, and payload. Phase transitions still deep-clone data across heap regions. The dual-heap architecture (mark-and-sweep for fluid data, arena-based regions for crystal data) is unchanged. Global variables still live in a scope-chain environment.&lt;/p&gt;
&lt;p&gt;The parser and AST are completely shared. The compiler reads the same &lt;code&gt;Program&lt;/code&gt; structure that the tree-walker reads. A single set of test programs validates both execution paths, and all 771 tests pass on both.&lt;/p&gt;
&lt;p&gt;The phase system compiles one-to-one. &lt;code&gt;freeze()&lt;/code&gt; becomes &lt;code&gt;OP_FREEZE&lt;/code&gt;. &lt;code&gt;thaw()&lt;/code&gt; becomes &lt;code&gt;OP_THAW&lt;/code&gt;. Bonds, reactions, seeds, pressure constraints: each has a corresponding opcode that does exactly what the tree-walker's evaluator function did, just driven by bytecode dispatch instead of recursive AST traversal.&lt;/p&gt;
&lt;h3&gt;Performance&lt;/h3&gt;
&lt;p&gt;I haven't done rigorous benchmarking, and I'm deliberately not making performance claims. The motivation for the bytecode VM wasn't speed; it was consistency (one execution path everywhere) and architectural cleanliness (the VM is easier to extend than the tree-walker's deeply nested switch statements).&lt;/p&gt;
&lt;p&gt;That said, bytecode VMs are generally faster than tree-walkers for the structural reasons mentioned earlier: better cache locality (sequential byte array vs. pointer-chasing through AST nodes), less call overhead (one switch dispatch vs. recursive function calls), and a compact representation that fits more of the program in cache. Whether this matters for Lattice programs depends on the workload. For a language whose core runtime cost is dominated by deep cloning, the dispatch overhead is rarely the bottleneck.&lt;/p&gt;
&lt;h3&gt;Looking Forward&lt;/h3&gt;
&lt;p&gt;The VM is feature-complete but not optimized. There's no constant folding, no dead code elimination, no register allocation (it's a pure stack machine). The &lt;code&gt;OP_SCOPE&lt;/code&gt; and &lt;code&gt;OP_SELECT&lt;/code&gt; concurrency opcodes still delegate to the tree-walker. The dispatch loop is a plain switch rather than computed gotos.&lt;/p&gt;
&lt;p&gt;These are all well-understood optimizations with clear implementation paths. The point of v0.3.1 is that the bytecode VM is now the default, passes all tests, and handles the full language surface including the phase system. Optimization is a separate project.&lt;/p&gt;
&lt;p&gt;The source code is at &lt;a href="https://go.tinymachines.io/apVcDX"&gt;github.com/ajokela/lattice&lt;/a&gt;, and you can try it in the browser at &lt;a href="https://go.tinymachines.io/xY5d3X"&gt;lattice-lang.web.app&lt;/a&gt;. The bytecode VM, compiler, REPL, and all 62 opcodes are in four files: &lt;code&gt;compiler.c&lt;/code&gt;, &lt;code&gt;vm.c&lt;/code&gt;, &lt;code&gt;chunk.c&lt;/code&gt;, and &lt;code&gt;opcode.c&lt;/code&gt;.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;git clone https://github.com/ajokela/lattice.git
cd lattice &amp;amp;&amp;amp; make
./clat
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Recommended Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://go.tinymachines.io/eKC5Kf"&gt;&lt;em&gt;Crafting Interpreters&lt;/em&gt;&lt;/a&gt; by Robert Nystrom - The definitive guide to building interpreters and bytecode VMs, and a major influence on Lattice's upvalue implementation&lt;/li&gt;
&lt;li&gt;&lt;a href="https://go.tinymachines.io/mCzqKd"&gt;&lt;em&gt;Writing A Compiler In Go&lt;/em&gt;&lt;/a&gt; by Thorsten Ball - Practical companion covering bytecode compilation and stack-based VMs&lt;/li&gt;
&lt;li&gt;&lt;a href="https://go.tinymachines.io/AqxND7"&gt;&lt;em&gt;Engineering a Compiler&lt;/em&gt;&lt;/a&gt; by Cooper &amp;amp; Torczon - Comprehensive treatment of compiler internals from front-end to optimization&lt;/li&gt;
&lt;li&gt;&lt;a href="https://go.tinymachines.io/xLp4gf"&gt;&lt;em&gt;Compilers: Principles, Techniques, and Tools&lt;/em&gt;&lt;/a&gt; by Aho, Lam, Sethi, Ullman - The classic &lt;em&gt;Dragon Book&lt;/em&gt; covering parsing, code generation, and optimization theory&lt;/li&gt;
&lt;/ul&gt;</description><category>bytecode</category><category>c</category><category>compilers</category><category>interpreters</category><category>language design</category><category>lattice</category><category>programming languages</category><category>virtual machine</category><guid>https://tinycomputers.io/posts/from-tree-walker-to-bytecode-vm-compiling-lattice.html</guid><pubDate>Tue, 17 Feb 2026 18:00:00 GMT</pubDate></item><item><title>Mutability as a First-Class Concept: The Lattice Phase System</title><link>https://tinycomputers.io/posts/mutability-as-a-first-class-concept-the-lattice-phase-system.html?utm_source=feed&amp;utm_medium=rss&amp;utm_campaign=rss</link><dc:creator>A.C. Jokela</dc:creator><description>&lt;div class="audio-widget"&gt;
&lt;div class="audio-widget-header"&gt;
&lt;span class="audio-widget-icon"&gt;🎧&lt;/span&gt;
&lt;span class="audio-widget-label"&gt;Listen to this article&lt;/span&gt;
&lt;/div&gt;
&lt;audio controls preload="metadata"&gt;
&lt;source src="https://tinycomputers.io/mutability-as-a-first-class-concept-the-lattice-phase-system_tts.mp3" type="audio/mpeg"&gt;
&lt;/source&gt;&lt;/audio&gt;
&lt;div class="audio-widget-footer"&gt;20 min · AI-generated narration&lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;Mutability as a First-Class Concept: The Lattice Phase System&lt;/h2&gt;
&lt;p&gt;Most programming languages treat mutability as a binary annotation. You write &lt;code&gt;const&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt;, &lt;code&gt;final&lt;/code&gt; or &lt;code&gt;var&lt;/code&gt;, and the compiler enforces it statically. Rust goes further with its borrow checker, enforcing exclusive mutable access at compile time. JavaScript offers &lt;code&gt;Object.freeze()&lt;/code&gt;, a runtime operation that's shallow by default and provides no mechanism for observation or validation. These are all useful tools, but they share a common limitation: mutability is something you &lt;em&gt;declare&lt;/em&gt;, not something you &lt;em&gt;work with&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In &lt;a href="https://go.tinymachines.io/xY5d3X"&gt;Lattice&lt;/a&gt;, I've been building something different. Mutability (what Lattice calls &lt;em&gt;phase&lt;/em&gt;) is a first-class runtime property that can be queried, constrained, validated, coordinated across variables, observed reactively, and even tracked historically. Over the last several releases (v0.2.3 through v0.2.6), this system has grown from simple freeze/thaw semantics into a full lifecycle framework. This post walks through that progression and the design decisions behind it.&lt;/p&gt;
&lt;h3&gt;The Metaphor: Crystallization&lt;/h3&gt;
&lt;p&gt;Lattice is built around the metaphor of crystallization. Values begin in a &lt;strong&gt;fluid&lt;/strong&gt; state (mutable) and can be &lt;strong&gt;frozen&lt;/strong&gt; into a &lt;strong&gt;crystal&lt;/strong&gt; state (immutable). The &lt;code&gt;thaw()&lt;/code&gt; operation creates a mutable copy of a crystal value, and &lt;code&gt;clone()&lt;/code&gt; performs a deep copy regardless of phase. This vocabulary isn't just cosmetic; it shapes how you think about data lifecycle in a Lattice program.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux temperature = 72.5       // fluid: mutable
temperature = 68.0             // allowed

freeze(temperature)            // now crystal: immutable
// temperature = 70.0          // ERROR: cannot mutate crystal value

flux copy = thaw(temperature)  // new fluid copy
copy = 70.0                    // allowed
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;flux&lt;/code&gt; keyword declares a fluid (mutable) binding. The &lt;code&gt;fix&lt;/code&gt; keyword declares a crystal (immutable) binding. And &lt;code&gt;let&lt;/code&gt; infers phase from context: fluid if the value is fluid, crystal if crystal. This alone isn't novel. What makes Lattice's approach interesting is everything that builds on top of it.&lt;/p&gt;
&lt;h3&gt;Phase Constraints: Mutability in Your Type Signatures&lt;/h3&gt;
&lt;p&gt;The first major addition (v0.2.3) was phase constraints on function parameters. In most languages, a function that receives data has no way to express whether it expects mutable or immutable input. You might document it, or rely on convention, but the language doesn't help. In Lattice, you can annotate parameters with their expected phase:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;fn mutate(data: flux Map) {
    data.set("modified", true)
}

fn inspect(data: fix Map) {
    print(data.get("name"))
}
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The runtime checks phase at call time. Pass a crystal value to &lt;code&gt;mutate()&lt;/code&gt; and you get an error. Pass a fluid value to &lt;code&gt;inspect()&lt;/code&gt; and it works fine. Fluid is compatible with fix because it &lt;em&gt;can&lt;/em&gt; be read. The constraint is about what the function &lt;em&gt;needs&lt;/em&gt;, not what the caller &lt;em&gt;has&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The shorthand syntax uses &lt;code&gt;~&lt;/code&gt; for flux and &lt;code&gt;*&lt;/code&gt; for fix:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;fn process(data: ~Map) { ... }  // needs mutable
fn display(data: *Map) { ... }  // needs immutable
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Phase-Dependent Dispatch&lt;/h4&gt;
&lt;p&gt;Phase constraints enable something more powerful: dispatch based on runtime phase. You can define multiple implementations of the same function with different phase signatures, and the runtime selects the best match:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mutable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;can&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;serializing&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"serialized_at"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;time_now&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;immutable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;directly&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;effects&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json_stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;flux&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;
&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;calls&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;flux&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;overload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;adds&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt;

&lt;span class="n"&gt;freeze&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;calls&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;fix&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;overload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mutation&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The overload resolution uses a scoring system. An exact phase match (fluid argument to flux parameter) scores highest. A compatible match (fluid to unphased) scores lower. An incompatible match (crystal to flux) is rejected entirely. When multiple overloads exist, the best-scoring one wins.&lt;/p&gt;
&lt;p&gt;This is genuinely useful in practice. A caching layer might have one implementation that updates a cache (requires mutable data) and another that reads through (works with immutable data). A serialization function might add metadata to mutable structures but serialize immutable ones directly. The caller doesn't need to know; the runtime dispatches based on what the data actually &lt;em&gt;is&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;Crystallization Contracts: Validation at the Phase Boundary&lt;/h3&gt;
&lt;p&gt;The next question was: when data freezes, how do you ensure it's in a valid state? In real systems, immutable data often represents finalized configuration, committed transactions, or published records. You want to validate before that transition happens.&lt;/p&gt;
&lt;p&gt;Version 0.2.5 introduced crystallization contracts, validation closures attached to &lt;code&gt;freeze()&lt;/code&gt; with the &lt;code&gt;where&lt;/code&gt; keyword:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nv"&gt;flux&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;Map&lt;/span&gt;::&lt;span class="nv"&gt;new&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt;
&lt;span class="nv"&gt;config&lt;/span&gt;[&lt;span class="s2"&gt;"host"&lt;/span&gt;]&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"localhost"&lt;/span&gt;
&lt;span class="nv"&gt;config&lt;/span&gt;[&lt;span class="s2"&gt;"port"&lt;/span&gt;]&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8080&lt;/span&gt;
&lt;span class="nv"&gt;config&lt;/span&gt;[&lt;span class="s2"&gt;"workers"&lt;/span&gt;]&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="nv"&gt;freeze&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;where&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;{
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt;.&lt;span class="nv"&gt;has&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"host"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;{&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"config missing 'host'"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;}
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt;.&lt;span class="nv"&gt;has&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"port"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;{&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"config missing 'port'"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;}
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;v&lt;/span&gt;[&lt;span class="s2"&gt;"workers"&lt;/span&gt;]&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;{&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"need at least 1 worker"&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;}
}
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The contract receives a deep clone of the value (so the validation can't accidentally mutate the original), runs the closure, and if the closure throws, the freeze is aborted and the value remains fluid. If validation passes, the value transitions to crystal.&lt;/p&gt;
&lt;p&gt;This maps cleanly to real-world patterns. Database ORMs validate before persisting. Configuration systems validate before applying. Form submissions validate before accepting. The difference is that in Lattice, this validation is attached to the &lt;em&gt;phase transition itself&lt;/em&gt;, not to a separate method you have to remember to call.&lt;/p&gt;
&lt;p&gt;Contracts compose naturally with the rest of the phase system. You can use them with phase bonds (discussed next) or with phase-dependent dispatch. A function that accepts &lt;code&gt;fix Map&lt;/code&gt; knows its argument passed whatever contract was attached at freeze time.&lt;/p&gt;
&lt;h3&gt;Phase Bonds: Coordinated Freezing&lt;/h3&gt;
&lt;p&gt;Individual freeze/thaw operations work well for isolated values, but real programs have related data that should transition together. A web request's headers, body, and metadata should probably all be immutable before you send it. A transaction's debit and credit entries should freeze atomically.&lt;/p&gt;
&lt;p&gt;Phase bonds (also v0.2.5) let you declare these relationships:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux&lt;span class="w"&gt; &lt;/span&gt;header&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;Map::new()
flux&lt;span class="w"&gt; &lt;/span&gt;body&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;Map::new()
flux&lt;span class="w"&gt; &lt;/span&gt;footer&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;Map::new()

header["content-type"]&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;"text/html"
body["content"]&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;"&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;"
footer["timestamp"]&lt;span class="w"&gt; &lt;/span&gt;=&lt;span class="w"&gt; &lt;/span&gt;time_now()

bond(header,&lt;span class="w"&gt; &lt;/span&gt;body,&lt;span class="w"&gt; &lt;/span&gt;footer)

freeze(header)&lt;span class="w"&gt;              &lt;/span&gt;//&lt;span class="w"&gt; &lt;/span&gt;cascades&lt;span class="w"&gt; &lt;/span&gt;to&lt;span class="w"&gt; &lt;/span&gt;body&lt;span class="w"&gt; &lt;/span&gt;AND&lt;span class="w"&gt; &lt;/span&gt;footer
print(phase_of(body))&lt;span class="w"&gt;       &lt;/span&gt;//&lt;span class="w"&gt; &lt;/span&gt;"crystal"
print(phase_of(footer))&lt;span class="w"&gt;     &lt;/span&gt;//&lt;span class="w"&gt; &lt;/span&gt;"crystal"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;bond(target, ...deps)&lt;/code&gt; call links dependencies to a target. When the target freezes, all its dependencies freeze too. Bonds are also transitive: if A is bonded to B and B is bonded to C, freezing A cascades through B to C.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux a = 1
flux b = 2
flux c = 3

bond(a, b)    // b depends on a
bond(b, c)    // c depends on b

freeze(a)     // freezes a → b → c
print(phase_of(c))  // "crystal"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can remove bonds with &lt;code&gt;unbond()&lt;/code&gt; before the freeze happens:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;bond(header, body, footer)
unbond(header, footer)    // footer no longer cascades

freeze(header)            // freezes header and body, NOT footer
print(phase_of(footer))   // "fluid"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Bonds solve a coordination problem that most languages leave to discipline. In a typical codebase, you'd need to remember to freeze all related values, or wrap them in a container and freeze that. Bonds make the relationship explicit and enforced.&lt;/p&gt;
&lt;h3&gt;Phase Reactions: Observing State Transitions&lt;/h3&gt;
&lt;p&gt;With constraints, contracts, and bonds, you can control &lt;em&gt;how&lt;/em&gt; and &lt;em&gt;when&lt;/em&gt; phase transitions happen. But sometimes you also need to know &lt;em&gt;that&lt;/em&gt; they happened. Logging, cache invalidation, UI updates, audit trails: these are all responses to state changes.&lt;/p&gt;
&lt;p&gt;Version 0.2.6 adds phase reactions: callbacks that fire automatically when a variable's phase changes.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux data = [1, 2, 3]

react(data, |phase, val| {
    print("data is now " + phase + ": " + to_string(val))
})

freeze(data)   // prints: "data is now crystal: [1, 2, 3]"
thaw(data)     // prints: "data is now fluid: [1, 2, 3]"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The callback receives two arguments: the new phase name (as a string, "crystal" or "fluid") and a deep clone of the current value. Multiple callbacks can be registered on the same variable, and they fire in registration order:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux counter = 0

react(counter, |phase, val| {
    print("logger: counter is now " + phase)
})

react(counter, |phase, val| {
    if phase == "crystal" {
        print("audit: counter finalized at " + to_string(val))
    }
})

counter = 42
freeze(counter)
// prints:
//   logger: counter is now crystal
//   audit: counter finalized at 42
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Reactions also fire during bond cascades. If variable B is bonded to A and has a reaction registered, freezing A will cascade to B and trigger B's reaction:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux primary = Map::new()
flux replica = Map::new()

bond(primary, replica)

react(replica, |phase, val| {
    print("replica transitioned to " + phase)
})

freeze(primary)
// prints: "replica transitioned to crystal"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is a powerful combination. Bonds handle the &lt;em&gt;coordination&lt;/em&gt; of transitions, and reactions handle the &lt;em&gt;observation&lt;/em&gt;. Together they let you build systems where phase changes propagate and trigger side effects in a predictable, declarative way.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;unreact()&lt;/code&gt; to remove all reactions from a variable:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;react(data, |phase, val| { print("fired") })
unreact(data)
freeze(data)  // no output — reaction was removed
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If a reaction callback throws an error, it propagates as a reaction error, giving you a clean way to handle failures in the observation chain.&lt;/p&gt;
&lt;h3&gt;Temporal Values: Phase History and Time Travel&lt;/h3&gt;
&lt;p&gt;The last piece of the phase system (also v0.2.5) is temporal values: the ability to track a variable's phase transitions and value changes over time.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux counter = 0
track("counter")

counter = 10
counter = 20
freeze(counter)

let history = phases("counter")
// [{phase: "fluid", value: 0},
//  {phase: "fluid", value: 10},
//  {phase: "fluid", value: 20},
//  {phase: "crystal", value: 20}]
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;track()&lt;/code&gt; function enables recording for a named variable. Every assignment and phase transition creates a snapshot. The &lt;code&gt;phases()&lt;/code&gt; function returns the full history as an array of maps, and &lt;code&gt;rewind()&lt;/code&gt; lets you retrieve past values by offset:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;flux x = 100
track("x")
x = 200
x = 300

print(rewind("x", 0))  // 300 (current)
print(rewind("x", 1))  // 200 (one step back)
print(rewind("x", 2))  // 100 (two steps back)
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Temporal values serve primarily as a debugging and auditing tool. When something goes wrong with a frozen value, you can inspect its history to see what mutations happened before the freeze. When testing phase-dependent dispatch, you can verify that the right transitions occurred. In production systems, you can use temporal tracking for audit logs or undo functionality.&lt;/p&gt;
&lt;h3&gt;The Bigger Picture: Why This Matters&lt;/h3&gt;
&lt;p&gt;Most programming languages treat mutability as a compiler concern, something to check at build time and forget about. Lattice treats it as a runtime property with the same richness as types or values. This opens up patterns that are difficult or impossible in other languages:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Gradual freezing.&lt;/strong&gt; Data starts fluid, accumulates state through a pipeline, and freezes when it's complete. Contracts validate at the boundary. Bonds ensure related data transitions together. This maps naturally to request processing, form building, transaction assembly, and configuration loading.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Observable state transitions.&lt;/strong&gt; Reactions let you attach behavior to phase changes without coupling the code that freezes with the code that responds. A module can register a reaction on shared data without knowing who or when the freeze will happen.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Phase-aware APIs.&lt;/strong&gt; Functions can express their mutability requirements in their signatures and dispatch based on the caller's data. Libraries can offer mutable and immutable code paths transparently.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Auditability.&lt;/strong&gt; Temporal tracking provides a built-in mechanism for understanding how data evolved, without external logging infrastructure.&lt;/p&gt;
&lt;p&gt;None of these features require abandoning the simple mental model. At its core, Lattice still has fluid and crystal, mutable and immutable. Everything else is opt-in machinery for programs that need more control.&lt;/p&gt;
&lt;h3&gt;Comparison with Other Approaches&lt;/h3&gt;
&lt;p&gt;It's worth comparing this to how other languages handle mutability:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Rust&lt;/th&gt;
&lt;th&gt;JavaScript&lt;/th&gt;
&lt;th&gt;Lattice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Mutability declaration&lt;/td&gt;
&lt;td&gt;&lt;code&gt;let&lt;/code&gt; / &lt;code&gt;let mut&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;const&lt;/code&gt; / &lt;code&gt;let&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;fix&lt;/code&gt; / &lt;code&gt;flux&lt;/code&gt; / &lt;code&gt;let&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Enforcement&lt;/td&gt;
&lt;td&gt;Compile-time&lt;/td&gt;
&lt;td&gt;Runtime (shallow)&lt;/td&gt;
&lt;td&gt;Runtime (deep)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Phase transitions&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Object.freeze()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;freeze()&lt;/code&gt; / &lt;code&gt;thaw()&lt;/code&gt; / &lt;code&gt;clone()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Validation on freeze&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Crystallization contracts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Coordinated freezing&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Phase bonds&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transition observation&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Phase reactions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Phase-dependent dispatch&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Overload resolution by phase&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;History tracking&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Temporal values&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Rust's borrow checker is more powerful for preventing data races at compile time; Lattice doesn't attempt that. JavaScript's &lt;code&gt;Object.freeze()&lt;/code&gt; is more pragmatic but also more limited: it's shallow, provides no observation, and offers no coordination. Lattice occupies a different point in the design space: mutability as a &lt;em&gt;domain concept&lt;/em&gt; rather than a &lt;em&gt;compiler constraint&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;Implementation Notes&lt;/h3&gt;
&lt;p&gt;The phase system is implemented in C as part of Lattice's tree-walking interpreter. Phase tags are stored directly on values (&lt;code&gt;VTAG_FLUID&lt;/code&gt;, &lt;code&gt;VTAG_CRYSTAL&lt;/code&gt;, &lt;code&gt;VTAG_UNPHASED&lt;/code&gt;), so phase checks are single comparisons. Bonds are stored as a dynamic array of &lt;code&gt;BondEntry&lt;/code&gt; structs on the evaluator, each mapping a target variable name to its dependencies. Reactions use a similar structure; &lt;code&gt;ReactionEntry&lt;/code&gt; maps a variable name to an array of callback closures. Temporal tracking stores &lt;code&gt;HistorySnapshot&lt;/code&gt; arrays containing phase names and deep-cloned values.&lt;/p&gt;
&lt;p&gt;The deep cloning is important throughout. Contract validation receives a clone so it can't mutate the original. Reaction callbacks receive clones so observers can't interfere with each other. Temporal snapshots are clones so history is independent of current state. This means the phase system has allocation costs proportional to value size, but it also means the invariants are strong, with no spooky action at a distance.&lt;/p&gt;
&lt;p&gt;Freeze cascading through bonds is recursive, and reactions fire during cascading, so a single &lt;code&gt;freeze()&lt;/code&gt; call can trigger an arbitrary chain of transitions and callbacks. Error propagation is straightforward: if any reaction throws, the error surfaces immediately with context about which reaction failed.&lt;/p&gt;
&lt;h3&gt;What's Next&lt;/h3&gt;
&lt;p&gt;The phase system is reaching a natural plateau in terms of core features. There are a few directions I'm considering:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Partial freezing&lt;/strong&gt; already exists in a basic form: you can freeze individual struct fields or map keys while leaving the container mutable. Expanding this to support more granular control (freeze all fields matching a pattern, freeze a subtree) could be useful for large data structures.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Phase-aware pattern matching&lt;/strong&gt; lets you match on phase in &lt;code&gt;match&lt;/code&gt; expressions using &lt;code&gt;~&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt; qualifiers. This is already implemented but could be extended with more complex phase patterns.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Compile-time phase inference&lt;/strong&gt; is a longer-term goal. If the interpreter can prove that a value is always crystal by a certain point, it could skip runtime checks. This would bring some of Rust's static guarantees to Lattice without requiring explicit lifetime annotations.&lt;/p&gt;
&lt;p&gt;For now, the phase system provides a cohesive set of tools for working with mutability as a first-class concept. Whether you're building a configuration loader that validates before committing, a pipeline that coordinates related state transitions, or a reactive system that responds to phase changes, Lattice gives you the vocabulary and the enforcement to do it declaratively.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Lattice is open source and available at &lt;a href="https://go.tinymachines.io/xY5d3X"&gt;lattice-lang.org&lt;/a&gt;. The language compiles and runs on macOS and Linux with no dependencies beyond a C11 compiler. You can try it in your browser via the &lt;a href="https://go.tinymachines.io/rbMgu6"&gt;playground&lt;/a&gt;, or clone the repo and run &lt;code&gt;make &amp;amp;&amp;amp; ./clat&lt;/code&gt; to start the REPL.&lt;/p&gt;</description><category>language design</category><category>lattice</category><category>mutability</category><category>phase system</category><category>programming languages</category><category>type systems</category><guid>https://tinycomputers.io/posts/mutability-as-a-first-class-concept-the-lattice-phase-system.html</guid><pubDate>Sat, 14 Feb 2026 23:00:00 GMT</pubDate></item><item><title>Building Cross-Platform Rust Binaries: A Multi-Architecture Build Orchestration System</title><link>https://tinycomputers.io/posts/multi-operating-system-and-multi-architecture-build-orchestration-system.html?utm_source=feed&amp;utm_medium=rss&amp;utm_campaign=rss</link><dc:creator>A.C. Jokela</dc:creator><description>&lt;p&gt;When developing &lt;a href="https://go.tinymachines.io/UzBxPb"&gt;ballistics-engine&lt;/a&gt;, a high-performance ballistics calculation library written in Rust, I faced a challenge: how do I efficiently build and distribute binaries for multiple operating systems and architectures? The answer led to the creation of an automated build orchestration system that leverages diverse hardware (from single-board computers to powerful x86_64 servers) to build native binaries for macOS, Linux, FreeBSD, NetBSD, and OpenBSD across both ARM64 and x86_64 architectures.  Now, you are probably wondering why I am bothering to show love for the BSD Trilogy; the answer is simple: because I want to.  Sure they are a bit esoteric, but I ran FreeBSD for years as my mail server.  I still like the BSDs.&lt;/p&gt;
&lt;p&gt;This article explores the architecture, implementation, and lessons learned from building a production-grade multi-platform build system that powers &lt;a href="https://go.tinymachines.io/XZwSCQ"&gt;https://ballistics.zip&lt;/a&gt;, where users can download pre-built binaries for their platform with a simple curl command.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;curl --proto '=https' --tlsv1.2 -sSf https://ballistics.zip/install.sh | sh
&lt;/pre&gt;&lt;/div&gt;

&lt;div class="audio-widget"&gt;
&lt;div class="audio-widget-header"&gt;
&lt;span class="audio-widget-icon"&gt;🎧&lt;/span&gt;
&lt;span class="audio-widget-label"&gt;Listen to this article&lt;/span&gt;
&lt;/div&gt;
&lt;audio controls preload="metadata"&gt;
&lt;source src="https://tinycomputers.io/multi-operating-system-and-multi-architecture-build-orchestration-system_tts.mp3" type="audio/mpeg"&gt;
&lt;/source&gt;&lt;/audio&gt;
&lt;div class="audio-widget-footer"&gt;15 min · AI-generated narration&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;The Problem: Cross-Platform Distribution&lt;/h3&gt;
&lt;p&gt;Rust's cross-compilation capabilities are impressive, but they have limitations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cross-compilation complexity: While Rust supports cross-compilation, getting it working reliably for BSD systems (especially with system dependencies) is challenging&lt;/li&gt;
&lt;li&gt;Native testing: You need to test on actual hardware to ensure binaries work correctly&lt;/li&gt;
&lt;li&gt;Binary compatibility: Different BSD versions and configurations require native builds&lt;/li&gt;
&lt;li&gt;Performance verification: Emulated builds may behave differently than native ones&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The solution? Build natively on each target platform using actual hardware or high-performance emulation.&lt;/p&gt;
&lt;h3&gt;Architecture Overview&lt;/h3&gt;
&lt;p&gt;The build orchestration system consists of three main components:&lt;/p&gt;
&lt;h4&gt;1. Build Nodes (Physical and Virtual Machines)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;macOS systems (x86_64 and aarch64) - Local builds&lt;/li&gt;
&lt;li&gt;Linux x86_64 server - Remote build via SSH&lt;/li&gt;
&lt;li&gt;FreeBSD ARM64 - Single-board computer (Raspberry Pi 4)&lt;/li&gt;
&lt;li&gt;OpenBSD ARM64 - QEMU VM emulated on x86_64 (rig.localnet)&lt;/li&gt;
&lt;li&gt;NetBSD x86_64 and ARM64 - QEMU VMs&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;2. Orchestrator (Python-based coordinator)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Reads build node configuration from &lt;code&gt;build-nodes.yaml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Executes builds in parallel across all nodes&lt;/li&gt;
&lt;li&gt;Collects artifacts via SSH/SCP&lt;/li&gt;
&lt;li&gt;Generates SHA256 checksums&lt;/li&gt;
&lt;li&gt;Uploads to Google Cloud Storage&lt;/li&gt;
&lt;li&gt;Updates version metadata&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;3. Distribution (ballistics.zip website)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Serves install script at https://ballistics.zip&lt;/li&gt;
&lt;li&gt;Hosts binaries in GCS bucket (&lt;code&gt;gs://ballistics-releases/&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Provides version detection and automatic downloads&lt;/li&gt;
&lt;li&gt;Supports version fallback for platforms with delayed releases&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Hardware Infrastructure&lt;/h3&gt;
&lt;h4&gt;Single-Board Computers&lt;/h4&gt;
&lt;p&gt;&lt;a href="https://go.tinymachines.io/frXtNx"&gt;Orange Pi 5 Max (ARM64)&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Role: Host for NetBSD ARM64 VM&lt;/li&gt;
&lt;li&gt;CPU: Rockchip RK3588 (8-core ARM Cortex-A76/A55)&lt;/li&gt;
&lt;li&gt;RAM: 16GB&lt;/li&gt;
&lt;li&gt;Why: Native ARM64 hardware for running QEMU VMs&lt;/li&gt;
&lt;li&gt;Host IP: 10.1.1.10&lt;/li&gt;
&lt;li&gt;VM IPs:&lt;/li&gt;
&lt;li&gt;NetBSD ARM64: 10.1.1.15&lt;/li&gt;
&lt;li&gt;OpenBSD ARM64 (native, disabled): 10.1.1.11&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://go.tinymachines.io/REbd4g"&gt;Raspberry Pi 4 (ARM64)&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Role: FreeBSD ARM64 native builds&lt;/li&gt;
&lt;li&gt;CPU: Broadcom BCM2711 (quad-core Cortex-A72)&lt;/li&gt;
&lt;li&gt;RAM: 8GB&lt;/li&gt;
&lt;li&gt;Why: Stable FreeBSD support, reliable ARM64 platform&lt;/li&gt;
&lt;li&gt;IP: 10.1.1.7&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;x86_64 ("rig.localnet")&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Role: Linux builds, BSD VM host, emulated ARM64 builds&lt;/li&gt;
&lt;li&gt;CPU: Intel i9&lt;/li&gt;
&lt;li&gt;RAM: 96GB&lt;/li&gt;
&lt;li&gt;IP: 10.1.1.27 (Linux host), 10.1.1.17 (KVM host)&lt;/li&gt;
&lt;li&gt;VMs Hosted:&lt;/li&gt;
&lt;li&gt;FreeBSD x86_64: 10.1.1.21&lt;/li&gt;
&lt;li&gt;OpenBSD x86_64: 10.1.1.20&lt;/li&gt;
&lt;li&gt;OpenBSD ARM64 (emulated): 10.1.1.23&lt;/li&gt;
&lt;li&gt;NetBSD x86_64: 10.1.1.19&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Local macOS Development Machine&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Role: macOS binary builds (both architectures)&lt;/li&gt;
&lt;li&gt;Build Method: Local cargo builds with target flags&lt;/li&gt;
&lt;li&gt;Architectures:&lt;/li&gt;
&lt;li&gt;&lt;code&gt;aarch64-apple-darwin&lt;/code&gt; (Apple Silicon)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;x86_64-apple-darwin&lt;/code&gt; (Intel Macs)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;A Surprising Discovery: Emulated ARM64 Performance&lt;/h3&gt;
&lt;p&gt;One of the most interesting findings during development was discovering that emulated ARM64 builds on powerful x86_64 hardware are significantly faster than emulated ARM64 on native ARM64 builds on single-board computers.&lt;/p&gt;
&lt;h4&gt;Performance Comparison&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Emulated ARM64 on ARM64: ~99+ minutes per build&lt;/li&gt;
&lt;li&gt;Emulated ARM64 on x86_64: 15m 37s ⚡&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The emulated build on rig.localnet (running QEMU with KVM acceleration) completed in about 6x less time than the native ARM64 hardware. This is because:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The x86_64 server has significantly more powerful CPU cores&lt;/li&gt;
&lt;li&gt;QEMU with KVM provides near-native performance for many workloads&lt;/li&gt;
&lt;li&gt;Rust compilation is primarily CPU-bound and benefits from faster single-core performance&lt;/li&gt;
&lt;li&gt;The x86_64 server has faster storage (NVMe vs eMMC/SD card)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As a result, the native OpenBSD ARM64 node on the Orange Pi is now disabled in favor of the emulated version.&lt;/p&gt;
&lt;h3&gt;Prerequisites&lt;/h3&gt;
&lt;h4&gt;SSH Key-Based Authentication&lt;/h4&gt;
&lt;p&gt;Critical: The orchestration system requires passwordless SSH access to all remote build nodes. Here's how to set it up:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generate SSH key (if you don't have one):&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh-keygen&lt;span class="w"&gt; &lt;/span&gt;-t&lt;span class="w"&gt; &lt;/span&gt;ed25519&lt;span class="w"&gt; &lt;/span&gt;-C&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"build-orchestrator"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Copy public key to each build node:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="c1"&gt;# For each build node&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;user@build-node-ip

&lt;span class="c1"&gt;# Examples:&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;alex@10.1.1.27&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;# Linux x86_64&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;freebsd@10.1.1.7&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="c1"&gt;# FreeBSD ARM64&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.20&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;# OpenBSD x86_64&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.23&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;# OpenBSD ARM64 emulated&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.19&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;# NetBSD x86_64&lt;/span&gt;
ssh-copy-id&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.15&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;# NetBSD ARM64&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Test SSH access:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;user@build-node-ip&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"uname -a"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Software Requirements&lt;/h4&gt;
&lt;p&gt;On Build Orchestrator Machine:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Python 3.8+&lt;/li&gt;
&lt;li&gt;pyyaml (&lt;code&gt;pip install pyyaml&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Google Cloud SDK (&lt;code&gt;gcloud&lt;/code&gt; command) for GCS uploads&lt;/li&gt;
&lt;li&gt;SSH client&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On Each Build Node:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rust toolchain (&lt;code&gt;cargo&lt;/code&gt;, &lt;code&gt;rustc&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Build essentials (compiler, linker)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;wget&lt;/code&gt;, or &lt;code&gt;ftp&lt;/code&gt; (for downloading source)&lt;/li&gt;
&lt;li&gt;Sufficient disk space (~2GB for build artifacts)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;BSD-Specific Requirements&lt;/h4&gt;
&lt;p&gt;NetBSD: Install curl via pkgsrc (native &lt;code&gt;ftp&lt;/code&gt; doesn't support HTTPS)&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="c1"&gt;# Bootstrap pkgsrc&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/usr&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ftp&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;pkgsrc.tar.gz&lt;span class="w"&gt; &lt;/span&gt;http://cdn.netbsd.org/pub/pkgsrc/current/pkgsrc.tar.gz
tar&lt;span class="w"&gt; &lt;/span&gt;-xzf&lt;span class="w"&gt; &lt;/span&gt;pkgsrc.tar.gz
&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/usr/pkgsrc/bootstrap&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;./bootstrap&lt;span class="w"&gt; &lt;/span&gt;--prefix&lt;span class="o"&gt;=&lt;/span&gt;/usr/pkg

&lt;span class="c1"&gt;# Install curl&lt;/span&gt;
/usr/pkg/bin/pkgin&lt;span class="w"&gt; &lt;/span&gt;-y&lt;span class="w"&gt; &lt;/span&gt;update
/usr/pkg/bin/pkgin&lt;span class="w"&gt; &lt;/span&gt;-y&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;curl
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;OpenBSD: Native &lt;code&gt;ftp&lt;/code&gt; supports HTTPS&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;pkg_add&lt;span class="w"&gt; &lt;/span&gt;rust&lt;span class="w"&gt; &lt;/span&gt;git
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;FreeBSD: Use pkg for everything&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;pkg&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;-y&lt;span class="w"&gt; &lt;/span&gt;rust&lt;span class="w"&gt; &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;curl
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;The ballistics.zip Website and Install Script&lt;/h3&gt;
&lt;h4&gt;How It Works&lt;/h4&gt;
&lt;p&gt;&lt;a href="https://go.tinymachines.io/XZwSCQ"&gt;https://ballistics.zip&lt;/a&gt; serves as the primary distribution point for pre-built ballistics-engine binaries. The system uses:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;GCS Bucket:&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;gs://ballistics-releases/&lt;/code&gt; - Binary artifacts&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CDN: Google Cloud CDN provides global distribution&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install Script: Universal installer that:&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Detects OS and architecture&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Downloads appropriate binary&lt;/li&gt;
&lt;li&gt;Verifies SHA256 checksum&lt;/li&gt;
&lt;li&gt;Installs to &lt;code&gt;/usr/local/bin&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;Usage&lt;/h4&gt;
&lt;p&gt;Basic installation:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;curl&lt;span class="w"&gt; &lt;/span&gt;-sSL&lt;span class="w"&gt; &lt;/span&gt;https://ballistics.zip/install.sh&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;bash
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Specific version:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;curl&lt;span class="w"&gt; &lt;/span&gt;-sSL&lt;span class="w"&gt; &lt;/span&gt;https://ballistics.zip/install.sh&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;bash&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;--&lt;span class="w"&gt; &lt;/span&gt;--version&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.13.3
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Different install location:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;curl&lt;span class="w"&gt; &lt;/span&gt;-sSL&lt;span class="w"&gt; &lt;/span&gt;https://ballistics.zip/install.sh&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;bash&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;--&lt;span class="w"&gt; &lt;/span&gt;--prefix&lt;span class="w"&gt; &lt;/span&gt;~/.local
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Install Script Architecture&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;install.sh&lt;/code&gt; script intelligently handles:&lt;/p&gt;
&lt;p&gt;Platform Detection:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nv"&gt;OS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;uname&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;tr&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'[:upper:]'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'[:lower:]'&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;ARCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;uname&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="k"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ARCH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;x86_64&lt;span class="p"&gt;|&lt;/span&gt;amd64&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;ARCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"x86_64"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;aarch64&lt;span class="p"&gt;|&lt;/span&gt;arm64&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;ARCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"aarch64"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;*&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Unsupported architecture: &lt;/span&gt;&lt;span class="nv"&gt;$ARCH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;

&lt;span class="nv"&gt;PLATFORM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;OS&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;ARCH&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# e.g., "openbsd-aarch64"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Version Fallback:
If a requested version isn't available for a platform, the script automatically finds the latest available version:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="c1"&gt;# If openbsd-aarch64 0.13.3 doesn't exist, fall back to 0.13.2&lt;/span&gt;
&lt;span class="nv"&gt;AVAILABLE_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;curl&lt;span class="w"&gt; &lt;/span&gt;-sL&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$BASE_URL&lt;/span&gt;/versions.txt&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;grep&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^&lt;/span&gt;&lt;span class="nv"&gt;$PLATFORM&lt;/span&gt;&lt;span class="s2"&gt;:"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;cut&lt;span class="w"&gt; &lt;/span&gt;-d:&lt;span class="w"&gt; &lt;/span&gt;-f2&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Checksum Verification:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nv"&gt;EXPECTED_SHA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;cat&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BINARY&lt;/span&gt;&lt;span class="s2"&gt;.sha256"&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;ACTUAL_SHA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;sha256sum&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$BINARY&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;awk&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'{print $1}'&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$EXPECTED_SHA&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;!&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ACTUAL_SHA&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;then&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Checksum verification failed!"&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Build Orchestration System Deep Dive&lt;/h3&gt;
&lt;h4&gt;Configuration: build-nodes.yaml&lt;/h4&gt;
&lt;p&gt;The heart of the system is &lt;code&gt;build-nodes.yaml&lt;/code&gt;, which defines all build targets:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nt"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# macOS builds (local machine)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;macos-aarch64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;local&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;aarch64-apple-darwin&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd /tmp &amp;amp;&amp;amp; rm -rf ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;curl -L -o v{version}.tar.gz https://github.com/ajokela/ballistics-engine/archive/refs/tags/v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;tar xzf v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cargo build --release --target {target}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;/tmp/ballistics-engine-{version}/target/{target}/release/ballistics&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# Linux x86_64 (remote via SSH)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;linux-x86_64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;alex@10.1.1.27&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;x86_64-unknown-linux-gnu&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd /tmp &amp;amp;&amp;amp; rm -rf ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;wget -q https://github.com/ajokela/ballistics-engine/archive/refs/tags/v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;tar xzf v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;~/.cargo/bin/cargo build --release --target {target}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;/tmp/ballistics-engine-{version}/target/{target}/release/ballistics&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# OpenBSD ARM64 emulated (FASTEST ARM64 BUILD!)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;openbsd-aarch64-emulated&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;root@10.1.1.23&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;aarch64-unknown-openbsd&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd /tmp &amp;amp;&amp;amp; rm -rf ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;ftp -o v{version}.tar.gz https://github.com/ajokela/ballistics-engine/archive/refs/tags/v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;tar xzf v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cargo build --release&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;/tmp/ballistics-engine-{version}/target/release/ballistics&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;

&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# NetBSD x86_64 (HTTPS support via pkgsrc curl)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;netbsd-x86_64&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;root@10.1.1.19&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;x86_64-unknown-netbsd&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd /tmp &amp;amp;&amp;amp; rm -rf ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;/usr/pkg/bin/curl -L -o v{version}.tar.gz https://github.com/ajokela/ballistics-engine/archive/refs/tags/v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;tar xzf v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;/usr/pkg/bin/cargo build --release&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;/tmp/ballistics-engine-{version}/target/release/ballistics&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Orchestrator Workflow&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;orchestrator.py&lt;/code&gt; script coordinates the entire build process:&lt;/p&gt;
&lt;p&gt;Step 1: Parallel Build Execution&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;build_on_node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'host'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'local'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Local build&lt;/span&gt;
        &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Remote build via SSH&lt;/span&gt;
        &lt;span class="n"&gt;ssh_command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"ssh &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'host'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; '&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;build_command&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;'"&lt;/span&gt;
        &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ssh_command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Step 2: Artifact Collection&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;collect_artifacts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;binary_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"ballistics-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'host'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'local'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;shutil&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'binary_path'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"./&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;binary_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Download via SCP&lt;/span&gt;
        &lt;span class="n"&gt;scp_command&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"scp &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'host'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'binary_path'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ./&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;binary_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scp_command&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Step 3: Checksum Generation&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;generate_checksum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'rb'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;sha256&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;binary_path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.sha256"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'w'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Step 4: Upload to GCS&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;upload_to_gcs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;bucket_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"gs://ballistics-releases/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;

    &lt;span class="c1"&gt;# Upload binaries and checksums&lt;/span&gt;
    &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"gsutil -m cp ballistics-* &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;bucket_path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Set public read permissions&lt;/span&gt;
    &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"gsutil -m acl ch -u AllUsers:R &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;bucket_path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Update latest-version.txt&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'latest-version.txt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'w'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"gsutil cp latest-version.txt gs://ballistics-releases/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Running a Build&lt;/h4&gt;
&lt;p&gt;Dry-run (test without uploading):&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;build-orchestrator
./build.sh&lt;span class="w"&gt; &lt;/span&gt;--version&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.13.4&lt;span class="w"&gt; &lt;/span&gt;--dry-run
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Production build:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;./build.sh&lt;span class="w"&gt; &lt;/span&gt;--version&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.13.4
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;Building&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ballistics&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v0&lt;/span&gt;&lt;span class="mf"&gt;.13.4&lt;/span&gt;
&lt;span class="o"&gt;===========================================&lt;/span&gt;

&lt;span class="n"&gt;Enabled&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;macos&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;macos&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x86_64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;linux&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x86_64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alex&lt;/span&gt;&lt;span class="mf"&gt;@10.1.1.27&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;freebsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freebsd&lt;/span&gt;&lt;span class="mf"&gt;@10.1.1.7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;openbsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;emulated&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="mf"&gt;@10.1.1.23&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;netbsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x86_64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="mf"&gt;@10.1.1.19&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;netbsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="mf"&gt;@10.1.1.15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;Starting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;parallel&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;builds&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;macos&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Building&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PID&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12345&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;linux&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x86_64&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Building&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PID&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12346&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;macos&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;linux&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x86_64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;freebsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;openbsd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aarch64&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;emulated&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;⚡&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FASTEST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ARM64&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;Uploading&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gs&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//ballistics-releases/0.13.4/&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Uploaded&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;binaries&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Uploaded&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;checksums&lt;/span&gt;
&lt;span class="err"&gt;✓&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Updated&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;latest&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;

&lt;span class="n"&gt;Build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;🎉&lt;/span&gt;
&lt;span class="n"&gt;Total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Adding New Build Nodes&lt;/h3&gt;
&lt;h4&gt;Interactive Script&lt;/h4&gt;
&lt;p&gt;The easiest way to add a new node is using the interactive script:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;build-orchestrator
./add-node.sh
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This will prompt you for:
- Node name (e.g., &lt;code&gt;openbsd-aarch64-emulated&lt;/code&gt;)
- SSH host (e.g., &lt;code&gt;root@10.1.1.23&lt;/code&gt; or &lt;code&gt;local&lt;/code&gt;)
- Rust target triple (e.g., &lt;code&gt;aarch64-unknown-openbsd&lt;/code&gt;)
- Build commands (how to download and build)
- Binary location (where the compiled binary is located)&lt;/p&gt;
&lt;h4&gt;Manual Configuration&lt;/h4&gt;
&lt;p&gt;Alternatively, edit &lt;code&gt;build-nodes.yaml&lt;/code&gt; directly:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;your-new-platform&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;user@ip-address&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;# or 'local' for local builds&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;rust-target-triple&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;build_command&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p p-Indicator"&gt;|&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;# Commands to download source and build&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd /tmp &amp;amp;&amp;amp; rm -rf ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;curl -L -o v{version}.tar.gz https://github.com/...&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;tar xzf v{version}.tar.gz&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cd ballistics-engine-{version}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="no"&gt;cargo build --release&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;binary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;/path/to/compiled/binary&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nt"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;true&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Variables:
- &lt;code&gt;{version}&lt;/code&gt;: Replaced with target version (e.g., &lt;code&gt;0.13.4&lt;/code&gt;)
- &lt;code&gt;{target}&lt;/code&gt;: Replaced with Rust target triple&lt;/p&gt;
&lt;h4&gt;Setting Up a New VM&lt;/h4&gt;
&lt;p&gt;Example: OpenBSD ARM64 Emulated&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create VM on host:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;alex@rig.localnet
&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;/opt/bsd-vms/openbsd-arm64-emulated
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Create boot script:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;cat&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;boot.sh&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;lt;&amp;lt; 'EOF'&lt;/span&gt;
&lt;span class="s"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="s"&gt;exec qemu-system-aarch64 \&lt;/span&gt;
&lt;span class="s"&gt;  -M virt,highmem=off \&lt;/span&gt;
&lt;span class="s"&gt;  -cpu cortex-a57 \&lt;/span&gt;
&lt;span class="s"&gt;  -smp 4 \&lt;/span&gt;
&lt;span class="s"&gt;  -m 2G \&lt;/span&gt;
&lt;span class="s"&gt;  -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd \&lt;/span&gt;
&lt;span class="s"&gt;  -drive file=openbsd.qcow2,if=virtio,format=qcow2 \&lt;/span&gt;
&lt;span class="s"&gt;  -netdev bridge,id=net0,br=br0 \&lt;/span&gt;
&lt;span class="s"&gt;  -device virtio-net-pci,netdev=net0,romfile=,mac=52:54:00:12:34:99 \&lt;/span&gt;
&lt;span class="s"&gt;  -nographic&lt;/span&gt;
&lt;span class="s"&gt;EOF&lt;/span&gt;
chmod&lt;span class="w"&gt; &lt;/span&gt;+x&lt;span class="w"&gt; &lt;/span&gt;boot.sh
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Create systemd service:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;sudo&lt;span class="w"&gt; &lt;/span&gt;cat&lt;span class="w"&gt; &lt;/span&gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;/etc/systemd/system/openbsd-arm64-emulated-vm.service&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;lt;&amp;lt; 'EOF'&lt;/span&gt;
&lt;span class="s"&gt;[Unit]&lt;/span&gt;
&lt;span class="s"&gt;Description=OpenBSD ARM64 VM (Emulated on x86_64)&lt;/span&gt;
&lt;span class="s"&gt;After=network.target&lt;/span&gt;

&lt;span class="s"&gt;[Service]&lt;/span&gt;
&lt;span class="s"&gt;Type=simple&lt;/span&gt;
&lt;span class="s"&gt;User=alex&lt;/span&gt;
&lt;span class="s"&gt;WorkingDirectory=/opt/bsd-vms/openbsd-arm64-emulated&lt;/span&gt;
&lt;span class="s"&gt;ExecStart=/opt/bsd-vms/openbsd-arm64-emulated/boot.sh&lt;/span&gt;
&lt;span class="s"&gt;Restart=always&lt;/span&gt;
&lt;span class="s"&gt;RestartSec=10&lt;/span&gt;

&lt;span class="s"&gt;[Install]&lt;/span&gt;
&lt;span class="s"&gt;WantedBy=multi-user.target&lt;/span&gt;
&lt;span class="s"&gt;EOF&lt;/span&gt;

sudo&lt;span class="w"&gt; &lt;/span&gt;systemctl&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;enable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;openbsd-arm64-emulated-vm.service
sudo&lt;span class="w"&gt; &lt;/span&gt;systemctl&lt;span class="w"&gt; &lt;/span&gt;start&lt;span class="w"&gt; &lt;/span&gt;openbsd-arm64-emulated-vm.service
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Configure networking (assign static IP 10.1.1.23)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install build tools inside VM:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.23
pkg_add&lt;span class="w"&gt; &lt;/span&gt;rust&lt;span class="w"&gt; &lt;/span&gt;git
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Test SSH access:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;ssh&lt;span class="w"&gt; &lt;/span&gt;root@10.1.1.23&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cargo --version"&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Add to build-nodes.yaml and test:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;./build.sh&lt;span class="w"&gt; &lt;/span&gt;--version&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.13.3&lt;span class="w"&gt; &lt;/span&gt;--dry-run
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;GitHub Webhook Integration (Optional)&lt;/h3&gt;
&lt;p&gt;For fully automated builds triggered by GitHub releases:&lt;/p&gt;
&lt;h4&gt;1. Deploy Webhook Receiver to Cloud Run&lt;/h4&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;build-orchestrator
gcloud&lt;span class="w"&gt; &lt;/span&gt;run&lt;span class="w"&gt; &lt;/span&gt;deploy&lt;span class="w"&gt; &lt;/span&gt;ballistics-build-webhook&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--source&lt;span class="w"&gt; &lt;/span&gt;.&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--region&lt;span class="w"&gt; &lt;/span&gt;us-central1&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--allow-unauthenticated&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--set-env-vars&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;GITHUB_WEBHOOK_SECRET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-secret-here
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;2. Configure GitHub Webhook&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Go to: https://github.com/yourusername/your-repo/settings/hooks&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add webhook:&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Payload URL: &lt;code&gt;https://ballistics-build-webhook-xxx.run.app/webhook&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Content type: &lt;code&gt;application/json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Secret: Your webhook secret&lt;/li&gt;
&lt;li&gt;Events: Select "Releases" only&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;3. Test&lt;/h4&gt;
&lt;p&gt;Create a new release on GitHub, and the webhook will automatically trigger builds for all platforms!&lt;/p&gt;
&lt;h3&gt;Performance Metrics and Insights&lt;/h3&gt;
&lt;p&gt;From real-world builds of ballistics-engine v0.13.3:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Platform&lt;/th&gt;
&lt;th&gt;Hardware&lt;/th&gt;
&lt;th&gt;Build Time&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;macOS aarch64&lt;/td&gt;
&lt;td&gt;Apple M1/M2&lt;/td&gt;
&lt;td&gt;45s&lt;/td&gt;
&lt;td&gt;Native Apple Silicon&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;macOS x86_64&lt;/td&gt;
&lt;td&gt;Intel i7/i9&lt;/td&gt;
&lt;td&gt;30s&lt;/td&gt;
&lt;td&gt;Cross-compile on Apple Silicon&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linux x86_64&lt;/td&gt;
&lt;td&gt;Xeon/EPYC&lt;/td&gt;
&lt;td&gt;25s&lt;/td&gt;
&lt;td&gt;Fastest overall ⚡&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FreeBSD aarch64&lt;/td&gt;
&lt;td&gt;Raspberry Pi 4&lt;/td&gt;
&lt;td&gt;6m 32s&lt;/td&gt;
&lt;td&gt;Native ARM64 hardware&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenBSD aarch64 (emulated)&lt;/td&gt;
&lt;td&gt;x86_64 QEMU&lt;/td&gt;
&lt;td&gt;15m 37s&lt;/td&gt;
&lt;td&gt;⚡ FASTEST ARM64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenBSD aarch64 (native)&lt;/td&gt;
&lt;td&gt;Orange Pi 5 Max&lt;/td&gt;
&lt;td&gt;99+ min&lt;/td&gt;
&lt;td&gt;Disabled due to slower speed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NetBSD x86_64&lt;/td&gt;
&lt;td&gt;x86_64 VM&lt;/td&gt;
&lt;td&gt;3m 45s&lt;/td&gt;
&lt;td&gt;KVM acceleration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NetBSD aarch64&lt;/td&gt;
&lt;td&gt;Orange Pi VM&lt;/td&gt;
&lt;td&gt;8m 12s&lt;/td&gt;
&lt;td&gt;QEMU on ARM64 host&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Key Insights:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;x86_64 is fastest: Modern x86_64 CPUs dominate for single-threaded compilation&lt;/li&gt;
&lt;li&gt;Emulation wins for ARM64: x86_64 emulating ARM64 beats native ARM64 SBCs&lt;/li&gt;
&lt;li&gt;SBCs are viable: Raspberry Pi and Orange Pi work well for native builds, but slower&lt;/li&gt;
&lt;li&gt;Parallel execution: Running all 7 builds in parallel takes only ~16 minutes (longest pole is FreeBSD ARM64)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Building a custom multi-platform build orchestration system may seem daunting, but the benefits are substantial:&lt;/p&gt;
&lt;p&gt;→ Full control: Own your build infrastructure&lt;/p&gt;
&lt;p&gt;→ Native builds: Real hardware ensures compatibility&lt;/p&gt;
&lt;p&gt;→ Cost-effective: Low operational costs after initial hardware investment&lt;/p&gt;
&lt;p&gt;→ Fast iteration: Parallel builds complete in ~16 minutes&lt;/p&gt;
&lt;p&gt;→ Flexibility: Easy to add new platforms&lt;/p&gt;
&lt;p&gt;→ Learning: Deep understanding of cross-platform development&lt;/p&gt;
&lt;p&gt;The surprising discovery that emulated ARM64 on powerful x86_64 hardware outperforms native ARM64 single-board computers has practical implications: you don't always need native hardware for every architecture. Strategic use of emulation can provide better performance while maintaining compatibility.&lt;/p&gt;
&lt;p&gt;For projects requiring broad platform support (especially BSD systems not well-served by traditional CI/CD), this approach offers a reliable, maintainable, and cost-effective solution.&lt;/p&gt;
&lt;h3&gt;Architecture Diagram&lt;/h3&gt;
&lt;div class="mermaid"&gt;
graph TB
    subgraph "Trigger Sources"
        GH[GitHub Release&lt;br&gt;v0.13.x]
        MANUAL[Manual Execution&lt;br&gt;./build.sh]
    end

    subgraph "Build Orchestrator"
        ORCH[Python Orchestrator&lt;br&gt;orchestrator.py]
        CONFIG[Build Configuration&lt;br&gt;build-nodes.yaml]
    end

    subgraph "Build Nodes - Local"
        MAC_ARM[macOS ARM64&lt;br&gt;Apple Silicon&lt;br&gt;~45s]
        MAC_X86[macOS x86_64&lt;br&gt;Rosetta 2&lt;br&gt;~30s]
    end

    subgraph "Build Nodes - Remote x86_64"
        LINUX_X86[Linux x86_64&lt;br&gt;alex@10.1.1.27&lt;br&gt;~25s]
        FREEBSD_X86[FreeBSD x86_64&lt;br&gt;root@10.1.1.21&lt;br&gt;~4m]
        OPENBSD_X86[OpenBSD x86_64&lt;br&gt;root@10.1.1.20&lt;br&gt;~12m]
        NETBSD_X86[NetBSD x86_64&lt;br&gt;root@10.1.1.19&lt;br&gt;~3m 45s]
    end

    subgraph "Build Nodes - Remote ARM64"
        FREEBSD_ARM[FreeBSD ARM64&lt;br&gt;freebsd@10.1.1.7&lt;br&gt;~6m 32s]
        OPENBSD_ARM_EMU[OpenBSD ARM64&lt;br&gt;root@10.1.1.23&lt;br&gt;Emulated on x86_64&lt;br&gt;~15m 37s ⚡]
        NETBSD_ARM[NetBSD ARM64&lt;br&gt;root@10.1.1.15&lt;br&gt;~8m 12s]
    end

    subgraph "Artifact Collection"
        COLLECT[SCP Collection&lt;br&gt;Pull binaries from nodes]
        CHECKSUM[Generate SHA256&lt;br&gt;checksums]
    end

    subgraph "Distribution"
        GCS[Google Cloud Storage&lt;br&gt;gs://ballistics-releases/]
        WEBSITE[ballistics.zip&lt;br&gt;Install Script]
    end

    GH --&amp;gt;|webhook| ORCH
    MANUAL --&amp;gt;|CLI| ORCH
    CONFIG --&amp;gt;|reads| ORCH

    ORCH --&amp;gt;|SSH parallel builds| MAC_ARM
    ORCH --&amp;gt;|SSH parallel builds| MAC_X86
    ORCH --&amp;gt;|SSH parallel builds| LINUX_X86
    ORCH --&amp;gt;|SSH parallel builds| FREEBSD_X86
    ORCH --&amp;gt;|SSH parallel builds| OPENBSD_X86
    ORCH --&amp;gt;|SSH parallel builds| NETBSD_X86
    ORCH --&amp;gt;|SSH parallel builds| FREEBSD_ARM
    ORCH --&amp;gt;|SSH parallel builds| OPENBSD_ARM_EMU
    ORCH --&amp;gt;|SSH parallel builds| NETBSD_ARM

    MAC_ARM --&amp;gt;|binary| COLLECT
    MAC_X86 --&amp;gt;|binary| COLLECT
    LINUX_X86 --&amp;gt;|binary| COLLECT
    FREEBSD_X86 --&amp;gt;|binary| COLLECT
    OPENBSD_X86 --&amp;gt;|binary| COLLECT
    NETBSD_X86 --&amp;gt;|binary| COLLECT
    FREEBSD_ARM --&amp;gt;|binary| COLLECT
    OPENBSD_ARM_EMU --&amp;gt;|binary| COLLECT
    NETBSD_ARM --&amp;gt;|binary| COLLECT

    COLLECT --&amp;gt; CHECKSUM
    CHECKSUM --&amp;gt; GCS
    GCS --&amp;gt; WEBSITE

    style OPENBSD_ARM_EMU fill:#90EE90
    style LINUX_X86 fill:#87CEEB
    style GCS fill:#FFD700
    style WEBSITE fill:#FFD700
&lt;/div&gt;

&lt;h4&gt;Diagram Legend&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Green: Fastest ARM64 build (emulated on powerful x86_64)&lt;/li&gt;
&lt;li&gt;Blue: Fastest overall build (native Linux x86_64)&lt;/li&gt;
&lt;li&gt;Yellow: Distribution endpoints&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Build Flow&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Trigger: GitHub release webhook or manual execution&lt;/li&gt;
&lt;li&gt;Parallel Execution: All enabled build nodes start simultaneously&lt;/li&gt;
&lt;li&gt;Collection: Orchestrator collects binaries via SCP&lt;/li&gt;
&lt;li&gt;Verification: SHA256 checksums generated for integrity&lt;/li&gt;
&lt;li&gt;Upload: Binaries and checksums uploaded to GCS&lt;/li&gt;
&lt;li&gt;Availability: Install script immediately serves new version&lt;/li&gt;
&lt;/ol&gt;</description><category>aarch64</category><category>arm64</category><category>automation</category><category>binary distribution</category><category>bsd</category><category>build systems</category><category>cargo</category><category>ci cd</category><category>cross platform</category><category>devops</category><category>emulation</category><category>freebsd</category><category>google cloud storage</category><category>kvm</category><category>linux</category><category>macos</category><category>netbsd</category><category>openbsd</category><category>orange pi</category><category>orchestration</category><category>parallel builds</category><category>qemu</category><category>raspberry pi</category><category>rust</category><category>single board computers</category><category>ssh</category><category>x86_64</category><guid>https://tinycomputers.io/posts/multi-operating-system-and-multi-architecture-build-orchestration-system.html</guid><pubDate>Fri, 21 Nov 2025 21:19:35 GMT</pubDate></item><item><title>MCDRAG: Legacy Ballistics from 1974 BASIC to Modern Web</title><link>https://tinycomputers.io/posts/mcdrag-legacy-ballistics-from-1974-basic-to-modern-web.html?utm_source=feed&amp;utm_medium=rss&amp;utm_campaign=rss</link><dc:creator>A.C. Jokela</dc:creator><description>&lt;div class="audio-widget"&gt;
&lt;div class="audio-widget-header"&gt;
&lt;span class="audio-widget-icon"&gt;🎧&lt;/span&gt;
&lt;span class="audio-widget-label"&gt;Listen to this article&lt;/span&gt;
&lt;/div&gt;
&lt;audio controls preload="metadata"&gt;
&lt;source src="https://tinycomputers.io/mcdrag-legacy-ballistics-from-1974-basic-to-modern-web_tts.mp3" type="audio/mpeg"&gt;
&lt;/source&gt;&lt;/audio&gt;
&lt;div class="audio-widget-footer"&gt;19 min · AI-generated narration&lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;MCDRAG: When 1974 BASIC Meets Modern WebAssembly&lt;/h2&gt;
&lt;p&gt;Back in December 1974, R.L. McCoy developed MCDRAG, an algorithm for estimating drag coefficients of axisymmetric projectiles. Originally written in BASIC and designed to run on mainframes and early microcomputers, this pioneering work provided engineers with a way to quickly estimate aerodynamic properties without expensive wind tunnel testing. Today, I'm bringing this piece of ballistics history to your browser through a Rust implementation compiled to WebAssembly.&lt;/p&gt;
&lt;h3&gt;The Original: Computing Ballistics When Memory Was Measured in Kilobytes&lt;/h3&gt;
&lt;p&gt;The original MCDRAG program is a fascinating artifact of 1970s scientific computing. Written in structured BASIC with line numbers, it implements sophisticated aerodynamic calculations using only basic mathematical operations available on computers of that era. The program calculates drag coefficients across Mach numbers from 0.5 to 5.0, breaking down the total drag into components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CD0&lt;/strong&gt;: Total drag coefficient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CDH&lt;/strong&gt;: Head drag coefficient  &lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CDSF&lt;/strong&gt;: Skin friction drag coefficient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CDBND&lt;/strong&gt;: Rotating band drag coefficient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CDBT&lt;/strong&gt;: Boattail drag coefficient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CDB&lt;/strong&gt;: Base drag coefficient&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;PB/PINF&lt;/strong&gt;: Base pressure ratio&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What's remarkable is how McCoy managed to encode complex aerodynamic relationships (including transonic effects, boundary layer transitions, and base pressure corrections) in just 260 lines of BASIC code. The program even includes diagnostic warnings for problematic geometries, alerting users when their projectile design might produce unreliable results.&lt;/p&gt;
&lt;h3&gt;The Algorithm: Physics Encoded in Code&lt;/h3&gt;
&lt;p&gt;MCDRAG uses semi-empirical methods to estimate drag, combining theoretical aerodynamics with experimental correlations. The algorithm accounts for:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Flow Regime Transitions&lt;/strong&gt;: Different calculation methods for subsonic, transonic, and supersonic speeds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Boundary Layer Effects&lt;/strong&gt;: Three models (Laminar/Laminar, Laminar/Turbulent, Turbulent/Turbulent) &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Geometric Complexity&lt;/strong&gt;: Handles nose shapes (via the RT/R parameter), boattails, meplats, and rotating bands&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reynolds Number Effects&lt;/strong&gt;: Calculates skin friction based on flow conditions and projectile scale&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The core innovation was providing reasonable drag estimates across the entire speed range relevant to ballistics, from subsonic artillery shells to hypersonic tank rounds, using a unified computational framework.&lt;/p&gt;
&lt;h3&gt;The Modern Port: Rust + WebAssembly&lt;/h3&gt;
&lt;p&gt;My Rust implementation preserves the original algorithm's mathematical fidelity while bringing modern software engineering practices:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="cp"&gt;#[derive(Debug, Clone, Copy)]&lt;/span&gt;
&lt;span class="k"&gt;enum&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BoundaryLayer&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LaminarLaminar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;LaminarTurbulent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;TurbulentTurbulent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ProjectileInput&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;calculate_drag_coefficients&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DragCoefficients&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// Implementation follows McCoy's original algorithm&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// but with type safety and modern error handling&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The Rust version offers several advantages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;: Enum types for boundary layers prevent invalid inputs&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory Safety&lt;/strong&gt;: No buffer overflows or undefined behavior&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Native performance in browsers via WebAssembly&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Modularity&lt;/strong&gt;: Clean separation between core calculations and UI&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Try It Yourself: Interactive MCDRAG Terminal&lt;/h3&gt;
&lt;p&gt;Below is a fully functional MCDRAG calculator running entirely in your browser. No server required; all calculations happen locally using WebAssembly.&lt;/p&gt;
&lt;div id="mcdrag-terminal-container" style="width: 100%; height: 600px; margin: 20px 0;"&gt;
    &lt;div id="mcdrag-loading" style="text-align: center; padding: 20px; color: #00ff00; font-family: 'Courier New', monospace;"&gt;Loading MCDRAG terminal...&lt;/div&gt;
    &lt;div id="mcdrag-terminal" style="display: none; height: 100%;"&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;style&gt;
#mcdrag-terminal-container {
    background-color: #0a0a0a;
    border: 2px solid #00ff00;
    border-radius: 5px;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
    overflow: hidden;
}

#mcdrag-terminal {
    height: 100%;
    padding: 20px;
    overflow-y: auto;
    background: linear-gradient(180deg, #0a0a0a 0%, #1a1a1a 100%);
    font-family: 'Courier New', monospace;
    color: #00ff00;
}

.mcdrag-terminal-line {
    margin: 2px 0;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.4;
}

.mcdrag-input-line {
    display: flex;
    align-items: center;
}

.mcdrag-prompt {
    color: #00ff00;
    margin-right: 8px;
}

#mcdrag-input-field {
    background: transparent;
    border: none;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    outline: none;
    flex: 1;
    caret-color: #00ff00;
}

.mcdrag-output {
    color: #ffffff;
}

.mcdrag-error {
    color: #ff4444;
}

.mcdrag-warning {
    color: #ffaa00;
}

.mcdrag-header {
    color: #00ffff;
    font-weight: bold;
}

.mcdrag-table-header {
    color: #00ffff;
    border-bottom: 1px solid #00ff00;
    margin-bottom: 5px;
}

.mcdrag-table-row {
    color: #ffffff;
}
&lt;/style&gt;

&lt;script type="module"&gt;
// Dynamically load the MCDRAG WASM module
(async function() {
    try {
        // Import the WASM module from the support directory
        const module = await import('/mcdrag/mcdrag.js');
        await module.default();

        // Create the terminal interface
        class McDragTerminal {
            constructor(element) {
                this.element = element;
                this.calculator = new module.McDragCalculator();
                this.history = [];
                this.historyIndex = 0;
                this.currentState = 'IDLE';
                this.projectileData = {};
                this.fields = [
                    { key: 'ref_diameter', prompt: 'ENTER PROJECTILE REFERENCE DIAMETER (MM):', type: 'float' },
                    { key: 'total_length', prompt: 'ENTER TOTAL PROJECTILE LENGTH (CALIBERS):', type: 'float' },
                    { key: 'nose_length', prompt: 'ENTER NOSE LENGTH (CALIBERS):', type: 'float' },
                    { key: 'rt_r', prompt: 'ENTER RT/R (HEADSHAPE PARAMETER):', type: 'float' },
                    { key: 'boattail_length', prompt: 'ENTER BOATTAIL LENGTH (CALIBERS):', type: 'float' },
                    { key: 'base_diameter', prompt: 'ENTER BASE DIAMETER (CALIBERS):', type: 'float' },
                    { key: 'meplat_diameter', prompt: 'ENTER MEPLAT DIAMETER (CALIBERS):', type: 'float' },
                    { key: 'band_diameter', prompt: 'ENTER ROTATING BAND DIAMETER (CALIBERS):', type: 'float' },
                    { key: 'cg_location', prompt: 'ENTER CENTER OF GRAVITY LOCATION (CALIBERS FROM NOSE):', type: 'float' },
                    { key: 'boundary_layer', prompt: 'ENTER THE BOUNDARY LAYER CODE (L/L, L/T, OR T/T):', type: 'boundary' },
                    { key: 'identification', prompt: 'ENTER PROJECTILE IDENTIFICATION:', type: 'string' }
                ];
                this.fieldIndex = 0;
            }

            init() {
                this.clear();
                this.showWelcome();
                this.createInputLine();
            }

            showWelcome() {
                this.writeLine('MCDRAG WEB TERMINAL', 'mcdrag-header');
                this.writeLine('DECEMBER 1974, R. L. MCCOY', 'mcdrag-header');
                this.writeLine('Rust/WASM Implementation 2025\n');
                this.writeLine('Type "help" for commands or "start" to begin calculation\n');
            }

            clear() {
                this.element.innerHTML = '';
            }

            writeLine(text, className = 'mcdrag-output') {
                const line = document.createElement('div');
                line.className = `mcdrag-terminal-line ${className}`;
                line.textContent = text;
                this.element.appendChild(line);
                this.scrollToBottom();
            }

            createInputLine() {
                const inputLine = document.createElement('div');
                inputLine.className = 'mcdrag-terminal-line mcdrag-input-line';

                const prompt = document.createElement('span');
                prompt.className = 'mcdrag-prompt';
                prompt.textContent = '&gt; ';

                const input = document.createElement('input');
                input.type = 'text';
                input.id = 'mcdrag-input-field';
                input.autocomplete = 'off';

                inputLine.appendChild(prompt);
                inputLine.appendChild(input);
                this.element.appendChild(inputLine);

                // Don't auto-focus to prevent page scrolling on load
                // input.focus();
                this.scrollToBottom();

                input.addEventListener('keydown', (e) =&gt; this.handleKeyPress(e));
            }

            handleKeyPress(e) {
                const input = e.target;

                if (e.key === 'Enter') {
                    const value = input.value.trim();
                    input.parentElement.remove();
                    this.writeLine(`&gt; ${value}`);

                    if (this.currentState === 'INPUT') {
                        this.processInput(value);
                    } else {
                        this.processCommand(value);
                    }

                    this.history.push(value);
                    this.historyIndex = this.history.length;
                    this.createInputLine();
                } else if (e.key === 'ArrowUp') {
                    e.preventDefault();
                    if (this.historyIndex &gt; 0) {
                        this.historyIndex--;
                        input.value = this.history[this.historyIndex];
                    }
                } else if (e.key === 'ArrowDown') {
                    e.preventDefault();
                    if (this.historyIndex &lt; this.history.length - 1) {
                        this.historyIndex++;
                        input.value = this.history[this.historyIndex];
                    } else {
                        this.historyIndex = this.history.length;
                        input.value = '';
                    }
                }
            }

            processCommand(command) {
                switch (command.toLowerCase()) {
                    case 'help':
                        this.showHelp();
                        break;
                    case 'start':
                        this.startInput();
                        break;
                    case 'clear':
                        this.clear();
                        this.showWelcome();
                        break;
                    case 'example':
                        this.loadExample();
                        break;
                    default:
                        if (command) {
                            this.writeLine(`Unknown command: ${command}. Type "help" for available commands.`, 'mcdrag-error');
                        }
                }
            }

            showHelp() {
                this.writeLine('\nAvailable Commands:', 'mcdrag-header');
                this.writeLine('  start   - Begin new projectile calculation');
                this.writeLine('  example - Load example projectile data');
                this.writeLine('  clear   - Clear the terminal');
                this.writeLine('  help    - Show this help message\n');
            }

            loadExample() {
                this.writeLine('\nLoading example: 7.62mm NATO M80 Ball', 'mcdrag-header');
                this.projectileData = {
                    ref_diameter: 7.82,
                    total_length: 3.57,
                    nose_length: 2.12,
                    rt_r: 0.5,
                    boattail_length: 0.33,
                    base_diameter: 0.88,
                    meplat_diameter: 0.08,
                    band_diameter: 1.0,
                    cg_location: 1.7,
                    boundary_layer: 'L/T',
                    identification: '7.62mm NATO M80 Ball Example'
                };
                this.calculateAndDisplay();
            }

            startInput() {
                this.currentState = 'INPUT';
                this.fieldIndex = 0;
                this.projectileData = {};
                this.writeLine('\nENTER THE MCDRAG INPUTS, ONE QUANTITY AT A TIME.\n', 'mcdrag-header');

                if (this.fields[this.fieldIndex].key === 'cg_location') {
                    this.writeLine('[NOTE: CENTER OF GRAVITY LOCATION IS OPTIONAL; IF UNKNOWN, ENTER 0]\n', 'mcdrag-warning');
                }

                if (this.fields[this.fieldIndex].key === 'boundary_layer') {
                    this.writeLine('FOR ALL LAMINAR BOUNDARY LAYER, CODE = L/L');
                    this.writeLine('FOR LAMINAR NOSE, TURBULENT AFTERBODY, CODE = L/T');
                    this.writeLine('FOR ALL TURBULENT BOUNDARY LAYER, CODE = T/T\n');
                }

                this.writeLine(this.fields[this.fieldIndex].prompt);
            }

            processInput(value) {
                const field = this.fields[this.fieldIndex];

                if (field.type === 'float') {
                    const num = parseFloat(value);
                    if (isNaN(num)) {
                        this.writeLine('Invalid number. Please try again.', 'mcdrag-error');
                        this.writeLine(field.prompt);
                        return;
                    }
                    this.projectileData[field.key] = num;
                } else if (field.type === 'boundary') {
                    const upperValue = value.toUpperCase();
                    if (!['L/L', 'L/T', 'T/T'].includes(upperValue)) {
                        this.writeLine('INCORRECT BOUNDARY LAYER CODE. PLEASE TRY AGAIN.', 'mcdrag-error');
                        this.writeLine(field.prompt);
                        return;
                    }
                    this.projectileData[field.key] = upperValue;
                } else {
                    this.projectileData[field.key] = value;
                }

                this.fieldIndex++;

                if (this.fieldIndex &lt; this.fields.length) {
                    this.writeLine('');

                    if (this.fields[this.fieldIndex].key === 'cg_location') {
                        this.writeLine('[NOTE: CENTER OF GRAVITY LOCATION IS OPTIONAL; IF UNKNOWN, ENTER 0]', 'mcdrag-warning');
                    }

                    if (this.fields[this.fieldIndex].key === 'boundary_layer') {
                        this.writeLine('FOR ALL LAMINAR BOUNDARY LAYER, CODE = L/L');
                        this.writeLine('FOR LAMINAR NOSE, TURBULENT AFTERBODY, CODE = L/T');
                        this.writeLine('FOR ALL TURBULENT BOUNDARY LAYER, CODE = T/T');
                    }

                    this.writeLine(this.fields[this.fieldIndex].prompt);
                } else {
                    this.calculateAndDisplay();
                }
            }

            calculateAndDisplay() {
                this.currentState = 'IDLE';

                const boundaryMap = {
                    'L/L': 'LaminarLaminar',
                    'L/T': 'LaminarTurbulent',
                    'T/T': 'TurbulentTurbulent'
                };

                const inputData = {
                    ...this.projectileData,
                    boundary_layer: boundaryMap[this.projectileData.boundary_layer]
                };

                try {
                    this.calculator.set_input(JSON.stringify(inputData));
                    const resultJson = this.calculator.calculate();
                    const result = JSON.parse(resultJson);

                    this.displayResults(result);
                } catch (error) {
                    this.writeLine(`\nError: ${error}`, 'mcdrag-error');
                }
            }

            displayResults(result) {
                this.writeLine('\n=================================================================', 'mcdrag-header');
                this.writeLine('MCDRAG RESULTS', 'mcdrag-header');
                this.writeLine(`PROJECTILE: ${result.input_summary.identification}`, 'mcdrag-header');
                this.writeLine('=================================================================\n', 'mcdrag-header');

                // Results table
                this.writeLine('   M      CD0      CDH     CDSF    CDBND     CDBT     CDB    PB/PINF', 'mcdrag-table-header');

                result.coefficients.forEach(coeff =&gt; {
                    const row = `${coeff.mach.toFixed(3).padStart(6)} ${coeff.cd0.toFixed(3).padStart(7)} ` +
                              `${coeff.cdh.toFixed(3).padStart(7)} ${coeff.cdsf.toFixed(3).padStart(7)} ` +
                              `${coeff.cdbnd.toFixed(3).padStart(7)} ${coeff.cdbt.toFixed(3).padStart(7)} ` +
                              `${coeff.cdb.toFixed(3).padStart(7)} ${coeff.pb_pinf.toFixed(3).padStart(7)}`;
                    this.writeLine(row, 'mcdrag-table-row');
                });

                // Diagnostics
                if (result.diagnostics.length &gt; 0) {
                    this.writeLine('\n');
                    result.diagnostics.forEach(diag =&gt; {
                        this.writeLine(diag, 'mcdrag-warning');
                    });
                }

                this.writeLine('\n');
                this.writeLine('Type "start" for another calculation or "example" to load sample data.');
            }

            scrollToBottom() {
                this.element.scrollTop = this.element.scrollHeight;
            }
        }

        // Initialize the terminal
        const terminalElement = document.getElementById('mcdrag-terminal');
        const loadingElement = document.getElementById('mcdrag-loading');

        loadingElement.style.display = 'none';
        terminalElement.style.display = 'block';

        const terminal = new McDragTerminal(terminalElement);
        terminal.init();

    } catch (error) {
        console.error('Failed to load MCDRAG terminal:', error);
        document.getElementById('mcdrag-loading').innerHTML = 
            'Failed to load MCDRAG terminal. Please ensure JavaScript is enabled and try refreshing the page.';
    }
})();
&lt;/script&gt;

&lt;h3&gt;Using the Terminal&lt;/h3&gt;
&lt;p&gt;The terminal above provides a faithful recreation of the original MCDRAG experience with modern conveniences:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;start&lt;/strong&gt;: Begin entering projectile parameters&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;example&lt;/strong&gt;: Load a pre-configured 7.62mm NATO M80 Ball example&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;clear&lt;/strong&gt;: Clear the terminal display&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;help&lt;/strong&gt;: Show available commands&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The calculator will prompt you for:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reference diameter (in millimeters)&lt;/li&gt;
&lt;li&gt;Total length (in calibers - multiples of diameter)&lt;/li&gt;
&lt;li&gt;Nose length (in calibers)&lt;/li&gt;
&lt;li&gt;RT/R headshape parameter (ratio of tangent radius to actual radius)&lt;/li&gt;
&lt;li&gt;Boattail length (in calibers)&lt;/li&gt;
&lt;li&gt;Base diameter (in calibers)&lt;/li&gt;
&lt;li&gt;Meplat diameter (in calibers)&lt;/li&gt;
&lt;li&gt;Rotating band diameter (in calibers)&lt;/li&gt;
&lt;li&gt;Center of gravity location (optional, in calibers from nose)&lt;/li&gt;
&lt;li&gt;Boundary layer code (L/L, L/T, or T/T)&lt;/li&gt;
&lt;li&gt;Projectile identification name&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;Historical Context: Why MCDRAG Matters&lt;/h3&gt;
&lt;p&gt;MCDRAG represents a pivotal moment in computational ballistics. Before its development, engineers relied on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Expensive wind tunnel testing for each design iteration&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Simplified point-mass models that ignored aerodynamic details&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Interpolation from limited experimental data tables&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;McCoy's work democratized aerodynamic analysis, allowing engineers with access to even modest computing resources to explore design spaces rapidly. The algorithm's influence extends beyond its direct use; it established patterns for semi-empirical modeling that influenced subsequent ballistics software development.&lt;/p&gt;
&lt;h3&gt;Technical Deep Dive: The Implementation&lt;/h3&gt;
&lt;p&gt;The Rust implementation leverages several modern programming techniques while maintaining algorithmic fidelity:&lt;/p&gt;
&lt;h4&gt;Type Safety and Domain Modeling&lt;/h4&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="cp"&gt;#[derive(Debug, Serialize, Deserialize)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;ProjectileInput&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ref_diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;// D1 - Reference diameter (mm)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;total_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;       &lt;/span&gt;&lt;span class="c1"&gt;// L1 - Total length (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nose_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// L2 - Nose length (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;rt_r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;              &lt;/span&gt;&lt;span class="c1"&gt;// R1 - RT/R headshape parameter&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;boattail_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// L3 - Boattail length (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;base_diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;// D2 - Base diameter (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;meplat_diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// D3 - Meplat diameter (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;band_diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;// D4 - Rotating band diameter (calibers)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;cg_location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// X1 - Center of gravity location&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;boundary_layer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BoundaryLayer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;identification&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;WebAssembly Integration&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;wasm-bindgen&lt;/code&gt; crate provides seamless JavaScript interop:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="cp"&gt;#[wasm_bindgen]&lt;/span&gt;
&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;McDragCalculator&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;#[wasm_bindgen(constructor)]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;McDragCalculator&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;McDragCalculator&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;current_input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="cp"&gt;#[wasm_bindgen]&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;calculate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;JsValue&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// Perform calculations and return JSON results&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Performance Optimizations&lt;/h4&gt;
&lt;p&gt;While maintaining mathematical accuracy, the Rust version includes several optimizations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Pre-computed constants replace repeated calculations&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Efficient memory layout reduces cache misses&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SIMD-friendly data structures (when compiled for native targets)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Applications and Extensions&lt;/h3&gt;
&lt;p&gt;Beyond its historical interest, MCDRAG remains useful for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Educational purposes&lt;/strong&gt;: Understanding fundamental aerodynamic concepts&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Initial design estimates&lt;/strong&gt;: Quick sanity checks before detailed CFD analysis&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Embedded systems&lt;/strong&gt;: The algorithm's simplicity suits resource-constrained environments&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Machine learning features&lt;/strong&gt;: MCDRAG outputs can serve as engineered features for ML models&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Open Source and Future Development&lt;/h3&gt;
&lt;p&gt;The complete source code for both the Rust library and web interface is available on &lt;a href="https://go.tinymachines.io/HYzCL9"&gt;GitHub&lt;/a&gt;. The project is structured to support multiple use cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Standalone CLI&lt;/strong&gt;: Native binary for command-line use&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Library&lt;/strong&gt;: Rust crate for integration into larger projects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WebAssembly module&lt;/strong&gt;: Browser-ready calculations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;FFI bindings&lt;/strong&gt;: C-compatible interface for other languages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Future enhancements under consideration:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GPU acceleration for batch calculations&lt;/li&gt;
&lt;li&gt;Integration with modern CFD validation data&lt;/li&gt;
&lt;li&gt;Extended parameter ranges for hypersonic applications&lt;/li&gt;
&lt;li&gt;Machine learning augmentation for uncertainty quantification&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Conclusion: Bridging Eras&lt;/h3&gt;
&lt;p&gt;MCDRAG exemplifies how good engineering transcends its original context. What began as a BASIC program for 1970s mainframes now runs in your browser at speeds McCoy could hardly have imagined. Yet the core algorithm (the physics and mathematics) remains unchanged, a testament to the fundamental soundness of the approach.&lt;/p&gt;
&lt;p&gt;This project demonstrates that preserving and modernizing legacy scientific software isn't just about nostalgia. These programs encode decades of domain expertise and validated methodologies. By bringing them forward with modern tools and platforms, we make this knowledge accessible to new generations of engineers and researchers.&lt;/p&gt;
&lt;p&gt;Whether you're a ballistics engineer needing quick estimates, a student learning about aerodynamics, or a programmer interested in scientific computing history, I hope this implementation of MCDRAG proves both useful and inspiring. The terminal above isn't just a calculator; it's a bridge between computing eras, showing how far we've come while honoring where we started.&lt;/p&gt;
&lt;h3&gt;References and Further Reading&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;McCoy, R.L. (1974). "MCDRAG - A Computer Program for Estimating the Drag Coefficients of Projectiles." Technical Report, U.S. Army Ballistic Research Laboratory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;McCoy, R.L. (1999). "Modern Exterior Ballistics: The Launch and Flight Dynamics of Symmetric Projectiles." Schiffer Military History.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Carlucci, D.E., &amp;amp; Jacobson, S.S. (2018). "Ballistics: Theory and Design of Guns and Ammunition" (3rd ed.). CRC Press.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;The MCDRAG algorithm is in the public domain. The Rust implementation and web interface are released under the BSD 3-Clause License.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;

&lt;/p&gt;&lt;div class="bi-app-promo" style="margin: 2em 0; padding: 1.25em 1.5em; background: var(--color-bg-secondary, rgba(127, 127, 127, 0.08)); border: 1px solid var(--color-border-primary, rgba(127, 127, 127, 0.35)); border-left: 4px solid var(--color-accent, #4FC3A1); border-radius: 6px;"&gt;
  &lt;div class="row"&gt;
    &lt;div class="col-sm-9"&gt;
      &lt;h5 style="margin-top: 0;"&gt;Ballistics Insight&lt;/h5&gt;
      &lt;p&gt;The open-source ballistics engine from these posts, on your phone: drop and wind holds for your own load and the day's conditions, with your saved loads and shooting logs. Calculations run on the device, so they work offline. It's free to install on iPhone, iPad and Android, and Pro is a one-time purchase.&lt;/p&gt;
      &lt;p style="margin-bottom: 0;"&gt;
        &lt;a style="display: inline-block; margin: 0 0.5em 0.5em 0; line-height: 0; vertical-align: middle;" href="https://go.tinymachines.io/ballisticsinsightappstore-tc-mcdrag" data-umami-event="app-click" data-umami-event-store="apple" data-umami-event-placement="tc-post" data-umami-event-post="mcdrag"&gt;&lt;img src="https://tinycomputers.io/ballistics-insight/app-store-badge.svg" alt="Download on the App Store" width="138" height="40" style="height: 40px; width: auto;"&gt;&lt;/a&gt;
        &lt;a style="display: inline-block; margin: 0 0.5em 0.5em 0; line-height: 0; vertical-align: middle;" href="https://go.tinymachines.io/ballisticsinsightplay-tc-mcdrag" data-umami-event="app-click" data-umami-event-store="play" data-umami-event-placement="tc-post" data-umami-event-post="mcdrag"&gt;&lt;img src="https://tinycomputers.io/ballistics-insight/google-play-badge.svg" alt="Get it on Google Play" width="138" height="40" style="height: 40px; width: auto;"&gt;&lt;/a&gt;
      &lt;/p&gt;
      &lt;p style="margin: 0.25em 0 0 0;"&gt;&lt;a href="https://tinycomputers.io/pages/ballistics.html"&gt;All ballistics posts, in order →&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-3 hidden-xs text-center"&gt;
      &lt;img src="https://tinycomputers.io/ballistics-insight/app-qr.svg" alt="QR code that opens Ballistics Insight in your phone's app store" width="112" height="112" style="background: #fff; padding: 6px; border-radius: 4px;"&gt;
      &lt;div&gt;&lt;small style="color: var(--color-text-muted, inherit);"&gt;Scan with your phone&lt;/small&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</description><category>ballistics</category><category>basic</category><category>drag-coefficient</category><category>projectile-design</category><category>retro computing</category><category>rust</category><category>wasm</category><guid>https://tinycomputers.io/posts/mcdrag-legacy-ballistics-from-1974-basic-to-modern-web.html</guid><pubDate>Sun, 24 Aug 2025 23:00:00 GMT</pubDate></item><item><title>Open Sourcing a High Performance Rust-based Ballistics Engine</title><link>https://tinycomputers.io/posts/open-sourcing-a-high-performance-rust-based-ballistics-engine.html?utm_source=feed&amp;utm_medium=rss&amp;utm_campaign=rss</link><dc:creator>A.C. Jokela</dc:creator><description>&lt;div class="audio-widget"&gt;
&lt;div class="audio-widget-header"&gt;
&lt;span class="audio-widget-icon"&gt;🎧&lt;/span&gt;
&lt;span class="audio-widget-label"&gt;Listen to this article&lt;/span&gt;
&lt;/div&gt;
&lt;audio controls preload="metadata"&gt;
&lt;source src="https://tinycomputers.io/open-sourcing-a-high-performance-rust-based-ballistics-engine_tts.mp3" type="audio/mpeg"&gt;
&lt;/source&gt;&lt;/audio&gt;
&lt;div class="audio-widget-footer"&gt;12 min · AI-generated narration&lt;/div&gt;
&lt;/div&gt;

&lt;h2&gt;From SaaS to Open Source: The Evolution of a Ballistics Engine&lt;/h2&gt;
&lt;p&gt;When I first built &lt;a href="https://go.tinymachines.io/PTLb7m"&gt;Ballistics Insight&lt;/a&gt;, my ML-augmented ballistics calculation platform, I faced a classic engineering dilemma: how to balance performance, accuracy, and maintainability across multiple platforms. The solution came in the form of a high-performance Rust core that became the beating heart of the system. Today, I'm excited to share that journey and announce the open-sourcing of this engine as a standalone library with full FFI bindings for iOS and Android.&lt;/p&gt;
&lt;h3&gt;The Genesis: A Python Problem&lt;/h3&gt;
&lt;p&gt;The story begins with a Python Flask application serving ballistics calculations through a REST API. The initial implementation worked well enough for proof-of-concept, but as I added more sophisticated physics models (Magnus effect, Coriolis force, transonic drag corrections, gyroscopic precession) the performance limitations became apparent. A single trajectory calculation that should take milliseconds was stretching into seconds. Monte Carlo simulations with thousands of iterations were becoming impractical.&lt;/p&gt;
&lt;p&gt;The Python implementation had another challenge: code duplication. I maintained separate implementations for atmospheric calculations, drag computations, and trajectory integration. Each time I fixed a bug or improved an algorithm, I had to ensure consistency across multiple code paths. The maintenance burden was growing exponentially with the feature set.&lt;/p&gt;
&lt;h3&gt;The Rust Revolution&lt;/h3&gt;
&lt;p&gt;The decision to rewrite the core physics engine in Rust wasn't taken lightly. I evaluated several options: optimizing the Python code with NumPy vectorization, using Cython for critical paths, or even moving to C++. Rust won for several compelling reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Memory Safety Without Garbage Collection&lt;/strong&gt;: Ballistics calculations involve extensive numerical computation with predictable memory patterns. Rust's ownership system eliminated entire categories of bugs while maintaining deterministic performance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Zero-Cost Abstractions&lt;/strong&gt;: I could write high-level, maintainable code that compiled down to assembly as efficient as hand-optimized C.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Excellent FFI Story&lt;/strong&gt;: Rust's ability to expose C-compatible interfaces meant I could integrate with any platform: Python, iOS, Android, or web via WebAssembly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Modern Tooling&lt;/strong&gt;: Cargo, Rust's build system and package manager, made dependency management and cross-compilation straightforward.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The results were dramatic. Atmospheric calculations went from 4.5ms in Python to 0.8ms in Rust, a 5.6x improvement. Complete trajectory calculations saw 15-20x performance gains. Monte Carlo simulations that previously took minutes now completed in seconds.&lt;/p&gt;
&lt;h3&gt;Architecture: From Monolith to Modular&lt;/h3&gt;
&lt;p&gt;The closed-source Ballistics Insight platform is a sophisticated system with ML augmentations, weather integration, and a comprehensive ammunition database. It includes features like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Neural network-based BC (Ballistic Coefficient) prediction&lt;/li&gt;
&lt;li&gt;Regional weather model integration with ERA5, OpenWeather, and NOAA data&lt;/li&gt;
&lt;li&gt;Magnus effect auto-calibration based on bullet classification&lt;/li&gt;
&lt;li&gt;Yaw damping prediction using gyroscopic stability factors&lt;/li&gt;
&lt;li&gt;A database of 2,000+ bullets with manufacturer specifications&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the open-source release, I took a different approach. Rather than trying to extract everything, I focused on the core physics engine, the foundation that makes everything else possible. This meant:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Extracting Pure Physics&lt;/strong&gt;: I separated the deterministic physics calculations from the ML augmentations. The open-source engine provides the fundamental ballistics math, while the SaaS platform layers intelligent corrections on top.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Creating Clean Interfaces&lt;/strong&gt;: I designed a new FFI layer from scratch, ensuring that iOS and Android developers could easily integrate the engine without understanding Rust or ballistics physics.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Building Standalone Tools&lt;/strong&gt;: The engine includes a full-featured command-line interface, making it useful for researchers, enthusiasts, and developers who need quick calculations without writing code.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The FFI Challenge: Making Rust Speak Every Language&lt;/h3&gt;
&lt;p&gt;One of my primary goals was to make the engine accessible from any platform. This meant creating robust Foreign Function Interface (FFI) bindings that could be consumed by Swift, Kotlin, Java, Python, or any language that can call C functions.&lt;/p&gt;
&lt;p&gt;The FFI layer presented unique challenges:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="cp"&gt;#[repr(C)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;FFIBallisticInputs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;muzzle_velocity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="c1"&gt;// m/s&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ballistic_coefficient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;                   &lt;/span&gt;&lt;span class="c1"&gt;// kg&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="c1"&gt;// meters&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;drag_model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="c1"&gt;// 0=G1, 1=G7&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sight_height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;c_double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;           &lt;/span&gt;&lt;span class="c1"&gt;// meters&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ... many more fields&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I had to ensure:
- &lt;strong&gt;C-compatible memory layouts&lt;/strong&gt; using &lt;code&gt;#[repr(C)]&lt;/code&gt;
- &lt;strong&gt;Safe memory management&lt;/strong&gt; across language boundaries
- &lt;strong&gt;Graceful error handling&lt;/strong&gt; without exceptions
- &lt;strong&gt;Zero-copy data transfer&lt;/strong&gt; where possible&lt;/p&gt;
&lt;p&gt;The result is a library that can be dropped into an iOS app as a static library, integrated into Android via JNI, or called from Python using ctypes. Each platform sees a native interface while the Rust engine handles the heavy lifting.&lt;/p&gt;
&lt;h3&gt;The Mobile Story: Binary Libraries for iOS and Android&lt;/h3&gt;
&lt;p&gt;Creating mobile bindings required careful consideration of each platform's requirements:&lt;/p&gt;
&lt;h4&gt;iOS Integration&lt;/h4&gt;
&lt;p&gt;For iOS, I compile the Rust library to a universal static library supporting both ARM64 (devices) and x86_64 (simulator). Swift developers interact with the engine through a bridging header:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;inputs&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;FFIBallisticInputs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;muzzle_velocity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;823.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;ballistic_coefficient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.475&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;mass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0109&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.00782&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ballistics_calculate_trajectory&lt;/span&gt;&lt;span class="p"&gt;(&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;inputs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1000.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ballistics_free_trajectory_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="bp"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Max range: &lt;/span&gt;&lt;span class="si"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pointee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max_range&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s"&gt; meters"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Android Integration&lt;/h4&gt;
&lt;p&gt;For Android, I provide pre-compiled libraries for multiple architectures (armeabi-v7a, arm64-v8a, x86, x86_64). The engine integrates seamlessly through JNI:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BallisticsEngine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;external&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;fun&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;calculateTrajectory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;muzzleVelocity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;ballisticCoefficient&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;mass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;diameter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;maxRange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;Double&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;TrajectoryResult&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;companion&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;object&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;init&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;loadLibrary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"ballistics_engine"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h3&gt;Performance: The Numbers That Matter&lt;/h3&gt;
&lt;p&gt;The open-source engine achieves remarkable performance across all platforms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Single Trajectory (1000m)&lt;/strong&gt;: ~5ms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Monte Carlo Simulation (1000 runs)&lt;/strong&gt;: ~500ms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BC Estimation&lt;/strong&gt;: ~50ms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero Calculation&lt;/strong&gt;: ~10ms&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These numbers represent pure computation time on modern hardware. The engine uses RK4 (4th-order Runge-Kutta) integration by default for maximum accuracy, with an option to switch to Euler's method for even faster computation when precision requirements are relaxed.&lt;/p&gt;
&lt;h3&gt;Advanced Physics: More Than Just Parabolas&lt;/h3&gt;
&lt;p&gt;While the basic trajectory of a projectile follows a parabolic path in a vacuum, real-world ballistics is far more complex. The engine models:&lt;/p&gt;
&lt;h4&gt;Aerodynamic Effects&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Velocity-dependent drag&lt;/strong&gt; using standard drag functions (G1, G7) or custom curves&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transonic drag rise&lt;/strong&gt; as projectiles approach the speed of sound&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Reynolds number corrections&lt;/strong&gt; for viscous effects at low velocities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Form factor adjustments&lt;/strong&gt; based on projectile shape&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Gyroscopic Phenomena&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Spin drift&lt;/strong&gt; from the Magnus effect on spinning projectiles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Precession and nutation&lt;/strong&gt; of the projectile's axis&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spin decay&lt;/strong&gt; over the flight path&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Yaw of repose&lt;/strong&gt; in crosswinds&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Environmental Factors&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Coriolis effect&lt;/strong&gt; from Earth's rotation (critical for long-range shots)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Wind shear&lt;/strong&gt; modeling with altitude-dependent wind variations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Atmospheric stratification&lt;/strong&gt; using ICAO standard atmosphere&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Humidity effects&lt;/strong&gt; on air density&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Stability Analysis&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Dynamic stability&lt;/strong&gt; calculations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pitch damping&lt;/strong&gt; coefficients through transonic regions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gyroscopic stability&lt;/strong&gt; factors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transonic instability&lt;/strong&gt; warnings&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;The Command Line Interface: Power at Your Fingertips&lt;/h3&gt;
&lt;p&gt;The engine includes a comprehensive CLI that rivals commercial ballistics software:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="c1"&gt;# Basic trajectory with auto-zeroing&lt;/span&gt;
./ballistics&lt;span class="w"&gt; &lt;/span&gt;trajectory&lt;span class="w"&gt; &lt;/span&gt;-v&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;2700&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-b&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.475&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;168&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.308&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--auto-zero&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--max-range&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1000&lt;/span&gt;

&lt;span class="c1"&gt;# Monte Carlo simulation for load development&lt;/span&gt;
./ballistics&lt;span class="w"&gt; &lt;/span&gt;monte-carlo&lt;span class="w"&gt; &lt;/span&gt;-v&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;2700&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-b&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.475&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;168&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.308&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;-n&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;1000&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--velocity-std&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--bc-std&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.01&lt;span class="w"&gt; &lt;/span&gt;--target-distance&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;600&lt;/span&gt;

&lt;span class="c1"&gt;# Estimate BC from observed drops&lt;/span&gt;
./ballistics&lt;span class="w"&gt; &lt;/span&gt;estimate-bc&lt;span class="w"&gt; &lt;/span&gt;-v&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;2700&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;168&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.308&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;--distance1&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--drop1&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.0&lt;span class="w"&gt; &lt;/span&gt;--distance2&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;300&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;--drop2&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;.075
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The CLI supports both imperial (default) and metric units, multiple output formats (table, JSON, CSV), and can enable individual physics models as needed.&lt;/p&gt;
&lt;h3&gt;Lessons Learned: The Open Source Journey&lt;/h3&gt;
&lt;p&gt;Extracting and open-sourcing a core component from a larger system taught me valuable lessons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clear Boundaries Matter&lt;/strong&gt;: Separating deterministic physics from ML augmentations made the extraction cleaner and the resulting library more focused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Documentation is Code&lt;/strong&gt;: I invested heavily in documentation, from inline Rust docs to comprehensive README examples. Good documentation dramatically increases adoption.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Performance Benchmarks Build Trust&lt;/strong&gt;: Publishing concrete performance numbers helps users understand what they're getting and sets realistic expectations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;FFI Design is Critical&lt;/strong&gt;: A well-designed FFI layer makes the difference between a library that's theoretically cross-platform and one that's actually used across platforms.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Community Feedback is Gold&lt;/strong&gt;: Early users found edge cases I never considered and suggested features that made the engine more valuable.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The Website: ballistics.rs&lt;/h3&gt;
&lt;p&gt;To support the open-source project, I created &lt;a href="https://go.tinymachines.io/LaZ2mx"&gt;ballistics.rs&lt;/a&gt;, a dedicated website that serves as the central hub for documentation, downloads, and community engagement. Built as a static site hosted on Google Cloud Platform with global CDN distribution, it provides fast access to resources from anywhere in the world.&lt;/p&gt;
&lt;p&gt;The website showcases:
- Comprehensive documentation and API references
- Platform-specific integration guides
- Performance benchmarks and comparisons
- Example code and use cases
- Links to the GitHub repository and issue tracker&lt;/p&gt;
&lt;h3&gt;Looking Forward: The Future of Open Ballistics&lt;/h3&gt;
&lt;p&gt;Open-sourcing the ballistics engine is just the beginning. I'm excited about several upcoming developments:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;WebAssembly Support&lt;/strong&gt;: Bringing high-performance ballistics calculations directly to web browsers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;GPU Acceleration&lt;/strong&gt;: For massive Monte Carlo simulations and trajectory optimization.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Extended Drag Models&lt;/strong&gt;: Supporting more specialized drag functions for specific projectile types.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Community Contributions&lt;/strong&gt;: I'm already seeing pull requests for new features and improvements.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Educational Resources&lt;/strong&gt;: Creating interactive visualizations and tutorials to help people understand ballistics physics.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;The Business Model: Open Core Done Right&lt;/h3&gt;
&lt;p&gt;My approach follows the "open core" model. The fundamental physics engine is open source and will always remain so. The value-added features in Ballistics Insight (ML augmentations, weather integration, ammunition databases, and the web API) constitute our commercial offering.&lt;/p&gt;
&lt;p&gt;This model benefits everyone:
- Developers get a production-ready ballistics engine for their applications
- Researchers have a reference implementation for ballistics algorithms
- The community can contribute improvements that benefit all users
- I maintain a sustainable business while giving back to the open-source ecosystem&lt;/p&gt;
&lt;h3&gt;Conclusion: Precision Through Open Collaboration&lt;/h3&gt;
&lt;p&gt;The journey from a closed-source SaaS platform to an open-source library with mobile bindings represents more than just a code release. It's a commitment to the principle that fundamental scientific calculations should be open, verifiable, and accessible to all.&lt;/p&gt;
&lt;p&gt;By open-sourcing the ballistics engine, I'm not just sharing code; I'm inviting collaboration from developers, researchers, and enthusiasts worldwide. Whether you're building a mobile app for hunters, creating educational software for physics students, or conducting research on projectile dynamics, you now have access to a battle-tested, high-performance engine that handles the complex mathematics of ballistics.&lt;/p&gt;
&lt;p&gt;The combination of Rust's performance and safety, comprehensive physics modeling, and carefully designed FFI bindings creates a unique resource in the ballistics software ecosystem. I'm excited to see what the community builds with it.&lt;/p&gt;
&lt;p&gt;Visit &lt;a href="https://go.tinymachines.io/LaZ2mx"&gt;ballistics.rs&lt;/a&gt; to get started, browse the documentation, or contribute to the project. The repository is available on &lt;a href="https://go.tinymachines.io/UzBxPb"&gt;GitHub&lt;/a&gt;, and I welcome issues, pull requests, and feedback.&lt;/p&gt;
&lt;p&gt;In the world of ballistics, precision is everything. With this open-source release, I'm putting that precision in your hands.&lt;/p&gt;
&lt;p&gt;

&lt;/p&gt;&lt;div class="bi-app-promo" style="margin: 2em 0; padding: 1.25em 1.5em; background: var(--color-bg-secondary, rgba(127, 127, 127, 0.08)); border: 1px solid var(--color-border-primary, rgba(127, 127, 127, 0.35)); border-left: 4px solid var(--color-accent, #4FC3A1); border-radius: 6px;"&gt;
  &lt;div class="row"&gt;
    &lt;div class="col-sm-9"&gt;
      &lt;h5 style="margin-top: 0;"&gt;Ballistics Insight&lt;/h5&gt;
      &lt;p&gt;The open-source ballistics engine from these posts, on your phone: drop and wind holds for your own load and the day's conditions, with your saved loads and shooting logs. Calculations run on the device, so they work offline. It's free to install on iPhone, iPad and Android, and Pro is a one-time purchase.&lt;/p&gt;
      &lt;p style="margin-bottom: 0;"&gt;
        &lt;a style="display: inline-block; margin: 0 0.5em 0.5em 0; line-height: 0; vertical-align: middle;" href="https://go.tinymachines.io/ballisticsinsightappstore-tc-open-source" data-umami-event="app-click" data-umami-event-store="apple" data-umami-event-placement="tc-post" data-umami-event-post="open-source"&gt;&lt;img src="https://tinycomputers.io/ballistics-insight/app-store-badge.svg" alt="Download on the App Store" width="138" height="40" style="height: 40px; width: auto;"&gt;&lt;/a&gt;
        &lt;a style="display: inline-block; margin: 0 0.5em 0.5em 0; line-height: 0; vertical-align: middle;" href="https://go.tinymachines.io/ballisticsinsightplay-tc-open-source" data-umami-event="app-click" data-umami-event-store="play" data-umami-event-placement="tc-post" data-umami-event-post="open-source"&gt;&lt;img src="https://tinycomputers.io/ballistics-insight/google-play-badge.svg" alt="Get it on Google Play" width="138" height="40" style="height: 40px; width: auto;"&gt;&lt;/a&gt;
      &lt;/p&gt;
      &lt;p style="margin: 0.25em 0 0 0;"&gt;&lt;a href="https://tinycomputers.io/pages/ballistics.html"&gt;All ballistics posts, in order →&lt;/a&gt;&lt;/p&gt;
    &lt;/div&gt;
    &lt;div class="col-sm-3 hidden-xs text-center"&gt;
      &lt;img src="https://tinycomputers.io/ballistics-insight/app-qr.svg" alt="QR code that opens Ballistics Insight in your phone's app store" width="112" height="112" style="background: #fff; padding: 6px; border-radius: 4px;"&gt;
      &lt;div&gt;&lt;small style="color: var(--color-text-muted, inherit);"&gt;Scan with your phone&lt;/small&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;</description><category>android</category><category>ballistics</category><category>ffi</category><category>ios</category><category>open-source</category><category>physics</category><category>rust</category><category>simulation</category><guid>https://tinycomputers.io/posts/open-sourcing-a-high-performance-rust-based-ballistics-engine.html</guid><pubDate>Sat, 16 Aug 2025 21:11:16 GMT</pubDate></item></channel></rss>