Skip to content

Instantly share code, notes, and snippets.

Avatar
🚴

Max Bernstein tekknolagi

🚴
View GitHub Profile
View pl-things.md
  • Compiling compression algorithms through programs
    • Compiler as f :: (program, compression algo) -> program'
  • Does collapsing towers of interpreters work for programming languages with much bigger architectural differences than the ones in the paper?
  • Abstract abstract interpretation
  • DDCG
  • Minecraft but it's all sending code to run on a shared VM
  • PL where every state change is persisted in a DB
  • SteamDrill (Quinn) but it's layered abstractions that you can expand (Python->C->asm) & custom events
View strace-deps
#!/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
View switch.py
# 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
View run.py
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com)
import shlex
import subprocess
import sys
def with_pty(command):
return [sys.executable, '-c', 'import pty, sys; pty.spawn(sys.argv[1:])'] + command
View hist.sh
#!/bin/sh
sort |
uniq -c |
sort -n |
sed 's/^ *//' |
awk 'BEGIN { OFS="\t"} { sum += $1; print sum, $1, substr($0, 1 + index($0, " ")) }' |
sort -n -r |
awk 'BEGIN { IFS=OFS="\t"; print "cum", "pct", "freq" }$1 > max { max = $1 }{ print int($1/max*100), int($2/max*100), $2, $3 }'
@tekknolagi
tekknolagi / enum_bitmask.hpp
Created May 3, 2022 — forked from StrikerX3/enum_bitmask.hpp
Type-safe enum bitmasks
View enum_bitmask.hpp
/*
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,
View stencil.cpp
// 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>
View code.js
(() => {
////////////////////////////////////////////////////////////////////////////////
// Dragging
const dragTarget = document.getElementById('dragTarget');
const uploadFiles = document.getElementById('uploadFiles');
const loadExample = document.getElementById('loadExample');
let dragging = 0;
let filesInput;
@tekknolagi
tekknolagi / stack_machine.cpp
Created Feb 2, 2021 — forked from glampert/stack_machine.cpp
1-register stack caching test for stack-based interpreters.
View stack_machine.cpp
//
// 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.
//
View icdemo.c
#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,