Skip to content

Instantly share code, notes, and snippets.

View apparentlymart's full-sized avatar
⌨️
I may be slow to respond.

Martin Atkins apparentlymart

⌨️
I may be slow to respond.
View GitHub Profile
@apparentlymart
apparentlymart / blink.ala
Last active December 22, 2015 03:18
Alamatic Examples
@apparentlymart
apparentlymart / gist:7283209
Created November 2, 2013 20:36
Prototype circuit definition language. Just brainstorming so far.
import max1234
part MAX1 is max1234
interface I2C:
pin DATA
pin CLOCK
interface SPIBus:
@apparentlymart
apparentlymart / clock.ala
Created November 11, 2013 01:49
Alamatic Clock Example
import time
import coll
enum HourType:
#: A 12-hour time in the morning.
AM
#: A 12-hour time in the afternoon/evening.
PM
#: A 24-hour time
@apparentlymart
apparentlymart / closures.c
Created January 4, 2014 04:07
Fat function pointers in C, to implement closures and object-bound methods
#include <stdio.h>
// we'd generate one of these for each distinct function signature
typedef struct {
void (*func)();
void *env;
} Callable;
// we'd generate an environment struct for each function that needs one
@apparentlymart
apparentlymart / Makefile
Last active August 29, 2015 14:03
mbed LPC1768 LLVM GPIO Example
all: blink.bin
blink.bc: blink.ll
opt-3.4 blink.ll -o blink.bc -basiccg -domtree -reg2mem -inline -constprop -die -adce -mem2reg
blink.s: blink.bc
llc-3.4 -march=thumb blink.bc -o blink.s
%.o: %.s
arm-none-eabi-as $< -o $@
@apparentlymart
apparentlymart / Makefile
Created July 20, 2014 16:36
mbed LPC1768 pyLLVM GPIO
all: blink.bin
blink.ll: genblink.py
python genblink.py >blink.ll
blink.bc: blink.ll
opt-3.4 blink.ll -o blink.bc
blink.s: blink.bc
llc-3.4 -march=thumb blink.bc -o blink.s
@apparentlymart
apparentlymart / aggregate.go
Last active August 29, 2015 14:05
Channel item aggregation in Go
// Example of aggregating channel values into sets based on a key.
// In this case, we aggregate strings by their first letter.
// Aggregated groups are emitted as slices when one of the following is true:
// - the buffer capacity is reached (set to 2 in this demo so we can hit it easily with the test data)
// - no new items have shown up for that group for two seconds
// - the source channel is closed
//
// The primary use case for this sort of thing is in forming higher-level transactions from an event stream,
// such as aggregating a log of actions by userid into a set of events that represents a session.
@apparentlymart
apparentlymart / pack.py
Last active August 29, 2015 14:05
Compact radix tree as a set of strings in C
# This generates tree.h by packing a set of strings into a Radix Tree structure.
words = [
"martin",
"martina",
"mark",
"matthew",
"adriana",
"adrian",
@apparentlymart
apparentlymart / Makefile
Created September 7, 2014 06:30
Python C API from LLVM IR
libfoo.so: foo.o
gcc foo.o -shared -o libfoo.so
foo.o: foo.ll
llc-3.3 -filetype=obj -relocation-model=pic foo.ll
@apparentlymart
apparentlymart / Makefile
Created September 14, 2014 02:16
LLVM Protothreads Implementation
protothread: protothread.o
gcc protothread.o -o protothread
protothread.o: protothread.s
as protothread.s -o protothread.o
protothread.s: protothread.ll
llc-3.4 protothread.ll