This file contains 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
#ifndef good_assert /* Better assert() for Windows - public domain */ | |
#ifdef _WIN32 | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#ifndef _WINDOWS_ | |
__declspec(dllimport) int __stdcall ExitProcess(unsigned int a); | |
__declspec(dllimport) int __stdcall MessageBoxA(void *a, const char *b, | |
const char *c, unsigned int d); | |
#endif /* _WINDOWS_ */ |
This file contains 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
#ifndef defer | |
struct defer_dummy {}; | |
template <class F> struct deferrer { F f; ~deferrer() { f(); } }; | |
template <class F> deferrer<F> operator*(defer_dummy, F f) { return {f}; } | |
#define DEFER_(LINE) zz_defer##LINE | |
#define DEFER(LINE) DEFER_(LINE) | |
#define defer auto DEFER(__LINE__) = defer_dummy{} *[&]() | |
#endif // defer |
This file contains 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
Play this game by pasting the script in http://www.puzzlescript.net/editor.html |
This file contains 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
// libs: Kernel32.lib User32.lib DbgHelp.lib msvcrt.lib (unless you have your own printf) | |
// includes: Windows.h (LEAN_AND_MEAN is ok) WinUser.h DbgHelp.h stdio.h | |
// call SymInitialize() at startup and debug_check_leaks at shutdown | |
#ifndef NDEBUG | |
static void print_stack_trace(void **stack, u64 stack_count, const char *indent) { | |
struct { | |
SYMBOL_INFO si; |
This file contains 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
__pragma(comment(linker, "/entry:main")); | |
__pragma(comment(linker, "/subsystem:console")); | |
void *(*GetProcAddress)(void *module, const char *name); | |
void *(*LoadLibraryA)(const char *name); | |
void (*ExitProcess)(unsigned int return_code); | |
int (*MessageBoxA)(void *hWnd, const char *lpText, const char *lpCaption, unsigned int uType); | |
static inline void load_proc(void *lib, void *fn, char *name) { | |
*(void **)fn = GetProcAddress(lib, name); |
This file contains 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
// Whatever, just example instructions. | |
#define INSTRUCTION_TYPE_LIST(instruction_type) \ | |
instruction_type(push, sizeof(u32)) \ | |
instruction_type(pop, sizeof(u32)) \ | |
instruction_type(move, sizeof(u32 *) + sizeof(u32 *)) | |
// Examples of usage (I didn't quite catch what the real usage was): | |
#define instruction_enum_name(name, size) Instruction_Type_ ## name, | |
#define instr_size(name, size) (size_t)size, |
This file contains 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 <stdlib.h> | |
#include <assert.h> | |
#define WIN32_LEAN_AND_MEAN | |
#define VC_EXTRALEAN | |
#include <windows.h> | |
template <class T> struct Virtual_Array { | |
This file contains 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 const char *const GL_funcnames[] = { | |
"wglDeleteContext", | |
"wglUseFontBitmapsA", | |
"wglSwapIntervalEXT", | |
"glGetError", | |
"glBlendFunc", | |
"glEnable", | |
"glDisable", | |
"glViewport", | |
"glVertex3f", |
This file contains 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> // for strcmp | |
#define Enum_Member(Name, Value) Name = Value, | |
#define Enum_To_String(Name, Value) if (e == Name) return # Name; | |
#define Enum_From_String(Name, Value) if (strcmp(str, # Name) == 0) return Name; | |
#define Define_Enum(EnumName) \ | |
\ |
This file contains 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
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
typedef struct Memory_Block { | |
uint8_t *data; | |
size_t num_bytes; | |
} Memory_Block; | |
typedef enum Allocator_Mode { |
OlderNewer