Skip to content

Instantly share code, notes, and snippets.

View Urquelle's full-sized avatar

Serge Ratke Urquelle

View GitHub Profile
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <windows.h>
typedef struct {
char *start;
char *current;
char *end;
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
void error(const char *str) {
typedef struct {
char *address;
char *reference;
} label_t;
void emit_label_reference(label_t *label) {
if (label->address) {
emit4(label->address - emit_pointer);
} else {
char *reference = emit_pointer;
// Despite appearances to the contrary, this does proper error handling. Any error cascades into a failure of the wglGetProcAddress.
int init_opengl() {
HWND window = CreateWindowA("edit", "", WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
PIXELFORMATDESCRIPTOR format_desc = {
.nSize = sizeof(PIXELFORMATDESCRIPTOR),
.nVersion = 1,
.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL
};
// Two techniques for using C99 variadic macros to provide a nicer interface to variadic functions.
#include <stdarg.h>
#include <stdio.h>
enum { SENTINEL = 0xDEADBEEF };
void vprint_sentinel(void *dummy, ...) {
va_list args;
va_start(args, dummy);
typedef struct { uint64_t b[4]; } uint4x64_t;
// Bitsliced 4-bit adder
uint4x64_t add_sliced(uint4x64_t x, uint4x64_t y) {
uint4x64_t s;
uint64_t c = 0;
for (int i = 0; i < 4; i++) {
uint64_t p = x.b[i] ^ y.b[i]
s.b[i] = p ^ c;
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct ion_type_t ion_type_t;
typedef struct ion_value_t ion_value_t;
typedef struct ion_state_t ion_state_t;
typedef struct ion_instruction_t ion_instruction_t;
typedef void (*ion_operation_t)(ion_state_t *, ion_value_t, ion_value_t, ion_value_t *);
@pervognsen
pervognsen / vex.c
Last active October 23, 2022 11:02
// The stack is 8-byte aligned.
#define ALIGN(p) ((uint64_t *)(((uintptr_t)(p) + 7) & ~7))
#define STACK(stack, size) uint64_t *_stack = ALIGN(stack), *_stack_end = (uint64_t *)((char *)(stack) + size)
#define PUSH(x) do { memcpy(_stack, &x, sizeof(x)); _stack += (sizeof(x) + 7) / 8; } while (0)
#define POP(x) do { _stack -= (sizeof(x) + 7) / 8; memcpy(&x, _stack, sizeof(x)); } while (0)
#if __GNUC__
// Use computed gotos on GCC-compatible compilers (including Clang).
#define JOIN(x, y) x##y
#define LABEL(name) JOIN(label, name)
@pervognsen
pervognsen / gob.h
Last active March 31, 2024 22:42
gob.h
// My investigations on the C standard compliance of Gob and related techniques:
// https://gist.github.com/pervognsen/5249a405fe7d76ded1cf08ed50fa9176
#pragma once
#include <stdint.h>
#pragma pack(push, 8)
#if __cplusplus >= 201103L || (__cplusplus && _MSC_VER >= 1900)
@pervognsen
pervognsen / mu.cpp
Last active February 11, 2026 18:55
Mu as of the second stream
#include "mu.h"
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define _NO_CRT_STDIO_INLINE
#include <stdio.h>
#include <stdarg.h>
#define NO_STRICT