Skip to content

Instantly share code, notes, and snippets.

View clflushopt's full-sized avatar
Throwing curveballs that I have to catch back

@clflushopt clflushopt

Throwing curveballs that I have to catch back
View GitHub Profile
@clflushopt
clflushopt / osr.cxx
Created June 15, 2025 19:09
Example of On Stack Replacement
#include <iostream>
#include <variant>
#include <vector>
using Value = std::variant<int, bool>;
std::ostream &operator<<(std::ostream &os, const Value &val) {
std::visit(
[&os](auto &&arg) {
using T = std::decay_t<decltype(arg)>;
@clflushopt
clflushopt / pizlossafull.md
Created May 12, 2025 02:58 — forked from pizlonator/pizlossafull.md
How I implement SSA form

This document explains how I would implement an SSA-based compiler if I was writing one today.

This document is intentionally opinionated. It just tells you how I would do it. This document is intended for anyone who has read about SSA and understands the concept, but is confused about how exactly to put it into practice. If you're that person, then I'm here to show you a way to do it that works well for me. If you're looking for a review of other ways to do it, I recommend this post.

My approach works well when implementing the compiler in any language that easily permits cyclic mutable data structures. I know from experience that it'll work great in C++, C#, or Java. The memory management of this approach is simple (and I'll explain it), so you won't have to stress about use after frees.

I like my approach because it leads to an ergonomic API by minimizing the amount of special cases you have to worry about. Most of the compiler is analyses and transformations ov