Skip to content

Instantly share code, notes, and snippets.

Per Vognsen pervognsen

Block or report user

Report or block pervognsen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Xeno.cpp
// Xeno
enum Xeno_Kind {
XENO_POINTER,
XENO_AGGREGATE,
XENO_FIRST_PRIMITIVE_TYPE,
XENO_UINT8 = XENO_FIRST_PRIMITIVE_TYPE,
XENO_UINT16,
XENO_UINT32,
XENO_UINT64,
View rad.py
# Reverse-mode automatic differentiation
import math
# d(-x) = -dx
def func_neg(x):
return -x, [-1]
# d(x + y) = dx + dy
def func_add(x, y):
@pervognsen
pervognsen / mu.cpp
Last active Oct 28, 2019
Mu as of the second stream
View mu.cpp
#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
View asan_clang_cl.md

I was told by @mmozeiko that Address Sanitizer (ASAN) works on Windows now. I'd tried it a few years ago with no luck, so this was exciting news to hear.

It was a pretty smooth experience, but with a few gotchas I wanted to document.

First, download and run the LLVM installer for Windows: https://llvm.org/builds/

Then download and install the VS extension if you're a Visual Studio 2017 user like I am.

It's now very easy to use Clang to build your existing MSVC projects since there's a cl compatible frontend:

View str.ion
import libc {...}
struct StrLinesIter {
next: char const*;
start: char const*;
end: char const*;
}
func str_lines(str: char const*): StrLinesIter {
return {next = str};
View input_bindings.md

Every emulator should have most of these input-related features but I haven't found anything with more than a small fraction:

Default and custom input profiles. Custom profiles can have game-specific input bindings. Bindings in custom profiles set to the 'default' value defer to the binding in the default profile; it's important that custom profiles aren't just initialized as a copy of the then-current default profile as this makes it impossible to later change some non-overridden binding in the default profile and have it automatically propagate to existing custom profiles.

The emulator should remember which custom profile was last used for which game, based on the ROM hash or filename. (The emulator should also automatically save any relevant per-game emulator settings, but I think you want that separate from input profiles. As an example of what not to do, if I set the CPU overclocking for Metal Slug in MAME to 200% to

View dotgen.py
class DotGenerator(Visitor):
def __init__(self):
super().__init__()
self.lines = []
self.next_id = 0
def make_name(self, node, name=None):
if name is None:
name = "n%d" % self.next_id
self.next_id += 1
View onepass_abstraction.c
// frontend with abstract backend
void parse_expr(expr_t *expr);
void parse_base_expr(expr_t *expr) {
if (token == NUMBER) {
do_number_expr(expr, token_value);
next_token();
} else if (match_token('(')) {
parse_expr(expr);
View multidimensional_array_views.md

Multi-dimensional array views for systems programmers

As C programmers, most of us think of pointer arithmetic for multi-dimensional arrays in a nested way:

The address for a 1-dimensional array is base + x. The address for a 2-dimensional array is base + x + y*x_size for row-major layout and base + y + x*y_size for column-major layout. The address for a 3-dimensional array is base + x + (y + z*y_size)*x_size for row-column-major layout. And so on.

@pervognsen
pervognsen / wm.el
Last active Aug 22, 2019
Dynamic tiling window manager for Emacs (inspired by dwm/awesome/xmonad for Linux)
View wm.el
(require 'cl)
(defstruct wm-window buffer (point 0) (start 0) (hscroll 0) dedicated)
(defvar wm-windows)
(defvar wm-windows-alist)
(defvar wm-focus)
(defvar wm-workspace 0)
(defvar wm-workspaces nil)
(defvar wm-layout 0)
You can’t perform that action at this time.