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 <stdlib.h> | |
| #include <stdio.h> | |
| #include <assert.h> | |
| #include <string.h> | |
| #include <windows.h> | |
| typedef struct { | |
| char *start; | |
| char *current; | |
| char *end; |
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 <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) { |
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
| 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; |
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
| // 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 | |
| }; |
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
| // 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); |
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
| 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; |
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 <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 *); |
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
| // 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) |
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
| // 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) |
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 "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 |
NewerOlder