Lesson 3.6
References & Further Reading
C runtime design, tagged unions, value semantics, and setjmp/longjmp resources.
The essential reads.
C Interfaces and Implementations
by David R. Hanson
The definitive book on building reusable C components. Covers tagged unions, memory management, exception handling with setjmp/longjmp, and arena allocation. Chapters 4 (Exceptions and Assertions) and 5 (Memory Management) map directly to what Monk's runtime does.
Crafting Interpreters -- Chapters 7-11
by Robert Nystrom
Nystrom builds a tree-walking evaluator with a tagged value type in Java, then a bytecode VM with a C value representation. Monk skips the tree-walking step and goes straight to C, but the value representation concepts are the same. Good for comparison.
craftinginterpreters.com/evaluating-expressions.htmlWhy these two? Hanson teaches the C techniques (tagged unions, setjmp). Nystrom teaches how those techniques apply to language runtimes. Together they cover the theory and the practice behind Monk's runtime.
setjmp/longjmp deep dives.
C Standard Library: setjmp.h
The official specification. Dry but precise. Understand the rules: what state is saved, what happens to local variables, when the behavior is undefined. Essential reading before using setjmp in production.
cppreference.com/w/c/program/setjmpExceptions in C with setjmp/longjmp
Various blog posts and tutorials walk through building a try/catch mechanism in C using setjmp. Search for "exceptions in C setjmp" -- the patterns are well-documented and Monk's implementation follows the standard approach.
Value semantics and memory models.
Sean Parent -- "Value Semantics and Concepts-Based Polymorphism"
A C++ talk, but the core idea transcends languages: values are independent, references create coupling. Parent makes the case for value semantics as the default, which is exactly what Monk does. The talk clarifies why "no shared mutable state" simplifies everything.
Swift's Value Types
Swift uses value semantics for structs and copy-on-write for collections. Monk's approach is simpler (always deep copy, no COW yet), but Swift's documentation explains the motivation well. Good for understanding where Monk might optimize in the future.
developer.apple.com/swift/blog/?id=10Runtime design inspiration.
Go's runtime package
Go's runtime is much larger than Monk's (goroutines, GC, reflection), but the built-in functions (len, append, copy, make) show how a language exposes runtime capabilities as built-ins. Monk's approach is structurally similar, just in C.
musl libc source
A clean, readable implementation of the C standard library. If you want to see how production C libraries implement string functions, math functions, or setjmp -- musl is the best starting point. Much more readable than glibc.
musl.libc.orgSuggested reading order.
Crafting Interpreters Ch. 7-11 -- understand how a language runtime represents values and evaluates expressions. Even though Monk compiles instead of interprets, the value representation is the same.
C Interfaces and Implementations Ch. 4-5 -- the C techniques behind Monk's runtime: exceptions and memory management.
setjmp.h reference -- know the rules before you use the tool.
Sean Parent's talk -- for the philosophical grounding on why value semantics is worth the cost.
musl source -- only if you're curious how professional C libraries are built. Not required for Monk.