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 <cxxabi.h> | |
#include <link.h> | |
#include <string> | |
#include <vector> | |
#include <iostream> | |
using namespace std; |
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
#!/bin/bash | |
if [[ $# -lt 2 ]]; then | |
echo "Usage: $0 <depfile> <command...>" >&2 | |
exit 1 | |
fi | |
# The .d file we're going to write. | |
DEPSFILE=$1 | |
shift |
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
import ast | |
import sys | |
import json | |
NoSemicolon = True | |
class CompileError(Exception): | |
pass |
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
# Copyright Andy Chu | |
class switch(object): | |
"""A ContextManager that translates to a C switch statement.""" | |
def __init__(self, value): | |
# type: (int) -> None | |
self.value = value | |
def __enter__(self): | |
# type: () -> switch |
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
/* | |
Type-safe enum class bitmasks. | |
Based on work by Andre Haupt from his blog at | |
http://blog.bitwigglers.org/using-enum-classes-as-type-safe-bitmasks/ | |
To enable enum classes to be used as bitmasks, use the ENABLE_BITMASK_OPERATORS | |
macro: | |
enum class MyBitmask { | |
None = 0b0000, | |
One = 0b0001, | |
Two = 0b0010, |
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
// Need Clang 13 for __attribute__((musttail)) | |
// clang++-13 -std=c++11 -g -O0 stencil.cpp | |
#include <cassert> | |
#include <cstdint> | |
#include <cstdio> | |
#include <cstring> | |
#include <vector> | |
#include <sys/mman.h> |
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
(() => { | |
//////////////////////////////////////////////////////////////////////////////// | |
// Dragging | |
const dragTarget = document.getElementById('dragTarget'); | |
const uploadFiles = document.getElementById('uploadFiles'); | |
const loadExample = document.getElementById('loadExample'); | |
let dragging = 0; | |
let filesInput; |
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
// | |
// Simple stack-based virtual machine tests. | |
// | |
// I use two slightly different strategies to manage the | |
// interpreter stack: First is using the "naive" approach | |
// of keeping a stack pointer that is bumped/decremented | |
// for every instruction that has stack operands. The second | |
// approach uses a "stack cache" register to cache the | |
// Top-of-Stack (TOS) value. | |
// |
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 <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
// TODO(max): Consider writing this in Rust or Nim for some extra reader | |
// appeal. | |
typedef enum { | |
kInt, |
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
import sys | |
def compile(prog): | |
result = ( | |
"#include <stdbool.h>\n" | |
"#include <stdio.h>\n" | |
"#include <string.h>\n" | |
"int execute() {\n" | |
"int acc = 0;\n" |