Skip to content

Instantly share code, notes, and snippets.

View vanaur's full-sized avatar
🐿️
I enjoy squirrels

Aurélien Vandeweyer vanaur

🐿️
I enjoy squirrels
View GitHub Profile
@vanaur
vanaur / UnionFind.fs
Created April 9, 2024 12:48
This module implements a generic union-find data structure in F# (for .NET)
/// This module implements a generic [union-find](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) data structure.
/// This structure is used to manage disjoint sets, often used in partitioning or clustering problems.
///
/// Here is a summary of the features and members of this data structure:
///
/// 1. **Constructor**: The `UnionFind` constructor initializes a new instance of the Union-Find data structure with
/// default elements of the original set specified as a sequence. This set can be extended.
///
/// 2. **Public Members** :
/// - `UnionFind.AddElement` Adds a new element to the set.
@rafaelrc7
rafaelrc7 / Makefile
Last active December 1, 2025 16:04
Generic Makefile for c/cxx/asm
######################### Preamble ###########################################
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.SECONDEXPANSION:
.EXTRA_PREREQS := $(MAKEFILE_LIST)
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += -j$(shell nproc)
@o11c
o11c / every-vm-tutorial-you-ever-studied-is-wrong.md
Last active December 9, 2025 22:55
Every VM tutorial you ever studied is wrong (and other compiler/interpreter-related knowledge)

Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.


URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.

There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)

  • a pure stack VM can only access the top elemen
@hirrolot
hirrolot / CoC.ml
Last active November 19, 2025 22:54
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@vanaur
vanaur / ColumnParser.fsx
Created June 29, 2022 14:33
Parse a file of spaced columns
#r "nuget: FParsec, 1.1.1"
open FParsec
let ws = skipMany (pchar ' ' <|> pchar '\t')
let ws1 = skipMany1 (pchar ' ' <|> pchar '\t')
let parseComment =
pstring "#" >>. skipRestOfLine true >>% []
from dataclasses import dataclass
from typing import List, Tuple, Union, Dict, Iterator, Optional
import sys
import itertools
Id = int
class UnionFind:
parents: List[Id]
@Mesabloo
Mesabloo / Test.hs
Last active July 7, 2022 18:26
A simple exercise with Haskell and genericity
{-| Exercise:
- Step 1:
Write a program simulating an iterating machine: we for example feed a range
@[0..4]@ and an action @print@ and it must execute this action on all the
elements of the range.
Writing @iterate1 [4..9] print@ must output:
> 4
@mikesmullin
mikesmullin / x86-assembly-notes.md
Last active December 12, 2025 17:25
Notes on x86-64 Assembly and Machine Code

Mike's x86-64 Assembly (ASM) Notes

Assembling Binary Machine Code

Operating Modes:

These determine the assumed/default size of instruction operands, and restricts which opcodes are available, and how they are used.

Modern operating systems, booted inside Real mode,