Skip to content

Instantly share code, notes, and snippets.

View tekknolagi's full-sized avatar
🚴

Max Bernstein tekknolagi

🚴
View GitHub Profile
@tekknolagi
tekknolagi / log.hpp
Created March 22, 2024 18:19 — forked from vtta/log.hpp
#ifndef LOG_HPP
#define LOG_HPP
#include <print>
#include <source_location>
template <class... Args>
struct info {
info(std::format_string<Args...> fmt, Args &&...args,
std::source_location const &loc = std::source_location::current()) {
std::print(stderr, "[{}:{}]{}: ", loc.file_name(), loc.line(),
@tekknolagi
tekknolagi / tiny.c
Created January 27, 2024 04:57 — forked from seanjensengrey/tiny.c
Marc Feeley Tiny C compiler
/* file: "tinyc.c" */
/* originally from http://www.iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c */
/* Copyright (C) 2001 by Marc Feeley, All Rights Reserved. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
@tekknolagi
tekknolagi / fb_get_token.py
Created December 12, 2023 20:46 — forked from kflu/fb_get_token.py
Obtain a Facebook Access Token
#!/usr/bin/env python3
"""Obtain a Facebook Access Token
From: https://github.com/dequis/purple-facebook/issues/445#issuecomment-967542766
Changes:
- Ported to Python3
- Auto generate the MACHINE_ID UUID
- Can set EMAIL from environment variable
@tekknolagi
tekknolagi / auto_treebuilder_test.py
Created December 11, 2023 23:22 — forked from uniphil/auto_treebuilder_test.py
pygit2 auto treebuilder
"""
Defines a function `auto_insert` to help with
`pygit2.Repository.TreeBuilder`s.
Just create the top-level `TreeBuilder`, and it will handle all subtree
creation if you give it paths.
"""
import shutil
from tempfile import mkdtemp
@tekknolagi
tekknolagi / every-vm-tutorial-you-ever-studied-is-wrong.md
Created August 28, 2023 03:13 — forked from o11c/every-vm-tutorial-you-ever-studied-is-wrong.md
Every VM tutorial you ever studied is wrong (and other compiler/interpreter-related knowledge)

Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.


URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.

There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)

  • a pure stack VM can only access the top elemen
@tekknolagi
tekknolagi / ssa-interp2.c
Created March 28, 2023 23:17 — forked from alpha123/ssa-interp2.c
Minimal Interpreter for SSA Bytecode — Explicitly Track CFG Paths
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <assert.h>
typedef int64_t value_t;
typedef uint64_t instr_t;
@tekknolagi
tekknolagi / ssa-interp.c
Created March 28, 2023 23:15 — forked from alpha123/ssa-interp.c
Primitive SSA Bytecode Interpreter
#include <stdlib.h>
#include <stdbool.h>
#include <stddef.h>
#define _WITH_GETLINE
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <assert.h>
@tekknolagi
tekknolagi / processify.py
Created October 31, 2022 22:36 — forked from schlamar/processify.py
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
#include <stdio.h>
#define IS_DIG(x) (((x)|1)=='1')
#define SLEN(s) ((sizeof s)-1)
#define RIDX(s,x) ((x)<SLEN(s)?s[SLEN(s)-1-(x)]:0)
#define CNT(s,x,n) ((x)<n?IS_DIG(RIDX(s,(x))):0)
#define CNT4(s,x,n) (CNT(s,x+0,n)+CNT(s,x+1,n)+CNT(s,x+2,n)+CNT(s,x+3,n))
#define CNT16(s,x,n) (CNT4(s,x+0,n)+CNT4(s,x+4,n)+CNT4(s,x+8,n)+CNT4(s,x+12,n))
#define CNT64(s,x,n) (CNT16(s,x+0,n)+CNT16(s,x+16,n)+CNT16(s,x+32,n)+CNT16(s,x+48,n))
#define VAL(s,x) ((RIDX(s,x)=='1')<<(CNT64(s,0,x)))
#define VAL4(s,x) (VAL(s,x+0)+VAL(s,x+1)+VAL(s,x+2)+VAL(s,x+3))
@tekknolagi
tekknolagi / python_make_github_issues.py
Created October 11, 2022 23:11 — forked from nqthqn/python_make_github_issues.py
Creates GitHub Issues from a CSV file.
import json
import requests
import csv
# Authentication for user filing issue (must have read/write access to
# repository to add issue to)
USERNAME = 'username'
PASSWORD = 'password'
# The repository to add this issue to