Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
@milesrout
milesrout / 1.intro.md
Last active May 29, 2016 05:20
Alvin, a language similar to Haskell

In Haskell the trivial type is written as () and has kind ∗. The list type is written as [] and has kind ∗→∗, which means that it is sort of a 'metafunction' from type to type. Applying [] (kind ∗→∗) to Int (kind ∗) gives [] Int i.e. [Int] (kind ∗). The function type is written as (->) and has kind ∗→∗→∗ i.e. ∗→(∗→∗) which means it's a sort of metafunction from type to a function from type to type. Applying (->) (kind ∗→∗→∗) to Int (kind ∗) gives (->) Int (kind ∗→∗), and applying that to Float (kind ∗) gives (->) Int Float i.e. Int -> Float (kind ∗).

In Alvin the trivial type is written as Trivial. The list type is written as List. It is a template, taking a type and 'returning' a type. Applying List to Int gives List::value<Int>. The function type is written as Function. (->) Int is written as Function::value<Int> and Int -> Float is written as Function::value<Int>::value<Float>.

Haskell:

  • 1 is a value of type Int.
  • 1.0 is a value of typ
I: location of cursor
initial state
+-------+-------+
| | |
+-------+ |
| I | |
+-------+ |
| | |
+-------+-------+
#include <stdatomic.h>
int count()
{
static atomic_flag mutex = ATOMIC_FLAG_INIT;
static unsigned volatile counter = 0;
unsigned volatile retval;
while (atomic_flag_test_and_set_explicit(&mutex, memory_order_acquire));
retval = ++counter;
#include <stdatomic.h>
static atomic_int counter = ATOMIC_VAR_INIT(0);
void increment_counter() {
atomic_fetch_add_explicit(&counter, 1, memory_order_relaxed);
}
int get_counter() {
return atomic_load_explicit(&counter, memory_order_relaxed);
@milesrout
milesrout / adhoc_mutex.c
Last active August 29, 2015 14:18
mutexes
#include <stdatomic.h>
int main()
{
static atomic_flag mutex = ATOMIC_FLAG_INIT;
static unsigned volatile counter = 0;
while (atomic_flag_test_and_set(&mutex));
++counter;
atomic_flag_clear(&mutex);
}
@milesrout
milesrout / iterators.md
Last active August 29, 2015 14:18
Understanding C++ Iterators

C++'s iterators are a generalisation of pointers-into-arrays. So you can write this:

void sort_array() {
    int arr[10] = {4, 5, 1, 7, 6, 3, 9, 2, 8, 0};
    std::sort(arr, arr + 10); // std::sort<int*>
}

just as you can write

void sort_vector() {

class renderer {
public:
enum class action {
view_add, view_remove, view_activate,
model_matrix_add, model_matrix_remove,
vb_add, vb_remove,
};
private:
static std::atomic<std::queue<std::pair<action, entity_id>>*> global_queue;
BIS: the Better Instruction Set
REGISTERS
---------
sixteen 32-bit general-purpose registers, numbered 0-15
one 16-bit status register
four 16-bit arithmetic condition registers, numbered 0-3
INSTRUCTION FORMAT LEGEND
@milesrout
milesrout / gist:c705e1502907358ea856
Created March 23, 2015 12:09
BIS: the Better Instruction Set
BIS: the Better Instruction Set
REGISTERS
---------
sixteen 32-bit general-purpose registers, numbered 0-15
one 16-bit status register
four 16-bit arithmetic condition registers, numbered 0-3
INSTRUCTION FORMAT LEGEND
@milesrout
milesrout / tinyleaders.py
Last active August 29, 2015 14:15
Find all legendary creatures with a particular colour identity
from itertools import *
colours = 'WUR'
def f(c):
return 'o:{' + str(c) + '}'
def g(c):
return c.lower()