Skip to content

Instantly share code, notes, and snippets.

@ClarkeRemy
ClarkeRemy / command_language.mm2
Created November 13, 2026 17:25
Command Language MM2
;; ((list ctor) .)
;; ((list ctor) (: $head $tail))
((list head tail) (: $head $tail) $head $tail)
(movement (up $n))
(movement (down $n))
(movement (right $n))
(movement (left $n))
(movement (wait $n))
@ClarkeRemy
ClarkeRemy / generic_ops.mm2
Created November 11, 2026 08:22
MM2 pure generics example
;; require pure_op.mm2
(integer_double_bits (i8 -> i16))
(integer_double_bits (i16 -> i32))
(integer_double_bits (i32 -> i64))
(integer_double_bits (i64 -> i128))
(return_type ($args -> $ret_type) $ret_type)
;; wide_mul
@ClarkeRemy
ClarkeRemy / earley.c
Last active September 23, 2026 18:57
Primitive Earley Parser in C
// https://loup-vaillant.fr/tutorials/earley-parsing/recogniser
//
// with c code cleanup from https://github.com/DogeSSBM
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdalign.h>
#include <string.h>
@ClarkeRemy
ClarkeRemy / vector.h
Last active September 11, 2026 10:51
Basic (untested) C vector
#include <stdint.h>
#include <string.h>
#define VECTOR_ALIGN_CHECK 0
struct vector_t {
uint64_t size;
uint64_t align;
uint64_t stride;
uint64_t len;
@ClarkeRemy
ClarkeRemy / insertion_sort_machine.c
Last active September 10, 2026 08:09
First Order Generic Insertion Sort Machine
#include <stdio.h>
typedef enum {
INIT,
REQUESTED_SAVE,
AWAIT_INNER_LOOP_COND_GT,
REQUESTED_OVERWRITE,
REQUESTED_RESTORE,
PC_OUT_OF_SYNC,
@ClarkeRemy
ClarkeRemy / first_order_generics.rs
Created August 28, 2026 04:31
FirstOrderGenerics
use std::{cmp::Ordering, fmt::Debug};
#[derive(Debug)]
struct Partition {
pivot_pos : usize,
mid_cursor : usize,
end_cursor : usize,
array_length : usize,
state : State,
}
@ClarkeRemy
ClarkeRemy / struct_graph.rs
Created May 4, 2026 16:50
Untested struct style ADT for graphs
#![allow(nonstandard_style)]
#![allow(unused)]
use std::{alloc::Layout, usize};
extern crate alloc;
type Weight = f64;
type Node = usize;
@ClarkeRemy
ClarkeRemy / radix16symtable.rs
Created March 25, 2026 05:56
Radix 16 Trie Symbol Table
// top nibble are flags, bottom nibble is the value
type ParentVaL = u8;
type Trie16Idx = u32;
type ChildIdx = Option<core::num::NonZeroU32>;
// This is a proper tree, the parent pointers are used to represent string as a linked list,
struct Trie16Node {
parent_val : ParentVaL,
parent : Trie16Idx,
children : [ChildIdx; 16],
@ClarkeRemy
ClarkeRemy / unsafe_arena_allocation.rs
Last active January 25, 2026 19:15
Learning about arena allocation.
extern crate alloc;
struct Arena {
start : *mut u8,
pos : *mut u8,
end : *mut u8,
layout : core::alloc::Layout,
}
fn arena_new(layout : core::alloc::Layout) -> Arena {
@ClarkeRemy
ClarkeRemy / str_concat.c
Created December 22, 2025 07:59
Bad String Concat in C
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
struct ByteSlice { uint8_t* ptr; uintptr_t len; };
/* caution this removes the null terminated char! */
struct ByteSlice nullTerminated_slice(uint8_t* str) {
uintptr_t len = 0;