This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Dynamically resizable array in constant virtual address space. | |
This will require a 64-bit system (or >32-bit system) for most | |
purposes. The idea is to reserve a huge chunk of address | |
space at program startup, but request actual memory backing | |
only when that address space is actually needed. | |
The big advantage of this approach is that we get stable | |
pointers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* We need this to properly get reported a mouse button release outside a window when there was a drag. */ | |
static unsigned win32_mousebuttonMask; /* a mask of 1<<button for each button that is down. */ | |
static int win32_isMouseCaptured; | |
static void win32_process_mouse_event(HWND hwnd, UINT msg) | |
{ | |
/* We capture the mouse using SetCapture() and release the mouse | |
using ReleaseCapture() when the mouse state changes between having | |
any or no depressed mouse buttons. | |
This makes sure that we get notified when the mouse is released |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> // memset() | |
#include <stdlib.h> // malloc(), free() | |
enum { | |
STRINGPOOLCHUNKSIZE_16, | |
STRINGPOOLCHUNKSIZE_32, | |
STRINGPOOLCHUNKSIZE_64, | |
STRINGPOOLCHUNKSIZE_128, | |
STRINGPOOLCHUNKSIZE_256, | |
STRINGPOOLCHUNKSIZE_512, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Dynamic array with an independently allocated count. | |
This is nice for relational and SOA (structure of arrays) programming. | |
We can share a count value across multiple dynamic arrays. | |
This is how it should be! (Except, it's still abstract, and quite a bit of boilerplate) | |
*/ | |
#include <cassert> | |
#include <cstdio> | |
#include <cstdlib> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _POSIX_C_SOURCE 200809L | |
#include <assert.h> | |
#include <stdarg.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define UNUSED __attribute__((unused)) | |
#define NORETURN __attribute__((noreturn)) | |
#define DIE(fmt, ...) _die("FATAL ERROR at line %d: " fmt "\n", __LINE__, ##__VA_ARGS__) | |
#define REALLOC(ptr, nels) _reallocfail((void**)&(ptr), nels, sizeof *(ptr), __FILE__, __LINE__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void _buf_init(void **buf, int *cap, int elsize, const char *file, const int line) | |
{ | |
fprintf(stderr, "_buf_init(%p, %s, %d)\n", buf, file, line); | |
*buf = NULL; | |
*cap = 0; | |
} | |
static void _buf_reserve(void **buf, int *cap, int cnt, int elsize, const char *file, const int line) | |
{ | |
fprintf(stderr, "_buf_reserve(%p, %s, %d)\n", buf, file, line); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f | |
Got KIND_NAME token | |
f f | |
Got KIND_NAME token | |
Got KIND_NAME token | |
f f"ab c" x | |
Got KIND_NAME token | |
Got KIND_NAME token | |
Got KIND_STRING token | |
Got KIND_NAME token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define LENGTH(a) (sizeof (a) / sizeof (a)[0]) | |
enum { | |
OP_NAME, | |
OP_VARDECL, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define PROGRAM_NAME "testwidths" | |
#define MAKE_TEST(type, name) \ | |
int name(int n, int v) \ | |
{ \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
values = [[None for _ in range(9)] for _ in range(9)] | |
taken = [[set() for _ in range(9)] for _ in range(9)] | |
free = set((i, j) for i in range(9) for j in range(9)) | |
def set_val(i, j, val): | |
assert(val not in taken[i][j]) | |
values[i][j] = val | |
free.remove((i,j)) | |
for k in range(9): | |
taken[i][k].add(val) |