Skip to content

Instantly share code, notes, and snippets.

# I happened to be looking at some of Cranelift's code, and I noticed that their constant-time dominates()
# check was using a somewhat more ad-hoc version of a hidden gem from the data structures literature called the
# parenthesis representation for trees. As far as I know, this was invented by Jacobson in his 1989 paper
# Space-Efficient Static Trees and Graphs. I first learned about it from the slightly later paper by Munro and Raman
# called Succinct Representations of Balanced Parentheses and Static Trees. I figured I'd give it an extremely
# quick intro and then show how it leads to a (slightly better) version of Cranelift's algorithm.
#
# This parenthesis representation of trees is surprisingly versatile, but its most striking feature is that
# it lets us query the ancestor relationship between two nodes in a tree in constant time, with a few instructions.
# And the idea is extremely simple and intuitive if you just draw the right kind of picture.
INLINE
u32 index(Ref r) {
return r >> 4;
}
INLINE
u32 tag(Ref r) {
return r & 15;
}
@tekknolagi
tekknolagi / SKILL.md
Last active March 10, 2026 19:53
Minimal PTY server/client for driving interactive CLIs (lldb, gdb, etc.) over a Unix socket
name control-interactive-tool
description This skill should be used when the user asks to "debug with lldb", "attach gdb", "run an interactive CLI", "control lldb/gdb", or needs to drive an interactive terminal tool (debugger, REPL, etc.) programmatically from Claude Code.

Control Interactive Tool

Drive interactive CLI tools (lldb, gdb, python, bash, etc.) via a background PTY server over a Unix socket.

Architecture

@tekknolagi
tekknolagi / scopemap.rs
Created December 28, 2025 17:19 — forked from glaebhoerl/scopemap.rs
Rust hash table with efficient support for nested scopes (save/restore)
// Based on idea: https://twitter.com/pkhuong/status/1287510400372748290
use hashbrown::raw::RawTable;
pub struct ScopeMap<K, V> {
last_scope_id: ScopeId,
scopes: Vec<ScopeId>, // values are zeroed instead of popped to save a check in get() / is_fresh()
current_scope: ScopeDepth, // index of innermost valid scope
values: RawTable<Entry<K, V>>,
shadowed: Vec<Shadowed<K, V>>,
// Compile this with -rdynamic and your emulator .so with -fPIC -fpie -shared
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "dcheck.h"
static char logfile_name[] = "/tmp/gbtracer.log.XXXXXX";
static int logfile_fd = 0;
@tekknolagi
tekknolagi / gensym.cpp
Created June 20, 2024 19:49 — forked from kenpusney/gensym.cpp
A gensym implementation of C/C++ Preprocessor.
#define STRINGIFY(x) #x
#define EXTRACT(...) __VA_ARGS__
#define INVOKE(macro,args...) macro( EXTRACT(args) )
#define FIRST(x,...) x
#define REST(x,...) __VA_ARGS__
#define __sym(cn,ln) _ainini_##c##cn##l##ln
#define sym(cn,ln) __sym(cn,ln)
#define __gensym(cn, ln) sym( cn,ln )
@tekknolagi
tekknolagi / hvm_standalone.cu
Created April 27, 2024 23:53 — forked from VictorTaelin/hvm_standalone.cu
HVM-CUDA - First Prototype - 6.7 billion RPS
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@tekknolagi
tekknolagi / log.hpp
Created March 22, 2024 18:19 — forked from vtta/log.hpp
#ifndef LOG_HPP
#define LOG_HPP
#include <print>
#include <source_location>
template <class... Args>
struct info {
info(std::format_string<Args...> fmt, Args &&...args,
std::source_location const &loc = std::source_location::current()) {
std::print(stderr, "[{}:{}]{}: ", loc.file_name(), loc.line(),
import contextlib
import io
import multiprocessing
import traceback
from multiprocessing.managers import SyncManager
# For demo only
import random
import time
@tekknolagi
tekknolagi / tiny.c
Created January 27, 2024 04:57 — forked from seanjensengrey/tiny.c
Marc Feeley Tiny C compiler
/* file: "tinyc.c" */
/* originally from http://www.iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c */
/* Copyright (C) 2001 by Marc Feeley, All Rights Reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*