Skip to content

Instantly share code, notes, and snippets.

View lasagnaphil's full-sized avatar

Phil Chang lasagnaphil

View GitHub Profile
@o11c
o11c / every-vm-tutorial-you-ever-studied-is-wrong.md
Last active June 15, 2024 02:12
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
@markfink
markfink / opengl_tutorial.py
Last active December 19, 2022 13:14
PySide2 & OpenGL sample
"""PySide2 & OpenGL sample"""
import sys
from PySide2 import QtCore, QtWidgets, QtOpenGL
try:
from OpenGL.GL import *
except ImportError:
app = QtWidgets.QApplication(sys.argv)
@viperscape
viperscape / font.c
Created April 14, 2018 17:39
bmfont rendering with sdl
#include "font.h"
#include "../SDL/SDL.h"
#include <stdio.h>
#include <string.h>
struct font font_init (SDL_Renderer* renderer, char *filename) {
char filename_[256] = {'\0'};
strcat(filename_, filename);
strcat(filename_, ".fnt");
@alexsr
alexsr / svd_glsl.glsl
Last active April 3, 2023 18:47
SVD and other matrix decompositions on 3x3 matrices written in GLSL
// This is a GLSL implementation of
// "Computing the Singular Value Decomposition of 3 x 3 matrices with
// minimal branching and elementary floating point operations"
// by Aleka McAdams et.al.
// http://pages.cs.wisc.edu/~sifakis/papers/SVD_TR1690.pdf
// This should also work on the CPU using glm
// Then you probably should use glm::quat instead of vec4
// and mat3_cast to convert to mat3.
@evilactually
evilactually / CMakeLists.txt
Created August 8, 2016 21:00
Compiling GLSL to SPIR-V from CMake
if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64")
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin/glslangValidator.exe")
else()
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin32/glslangValidator.exe")
endif()
file(GLOB_RECURSE GLSL_SOURCE_FILES
"shaders/*.frag"
"shaders/*.vert"
)
@joshuashaffer
joshuashaffer / pointTriangleDistance.py
Created July 1, 2015 22:28
Computes the distance between a point an triangle. Python.
#!/usr/bin/env python
#
# Tests distance between point and triangle in 3D. Aligns and uses 2D technique.
#
# Was originally some code on mathworks
import numpy
from numpy import dot
from math import sqrt