Skip to content

Instantly share code, notes, and snippets.

View seanjensengrey's full-sized avatar

Sean Jensen-Grey seanjensengrey

View GitHub Profile
Bootstrapping a simple compiler from nothing
============================================
This document describes how I implemented a tiny compiler for a toy
programming language somewhat reminiscent of C and Forth. The funny
bit is that I implemented the compiler in the language itself without
directly using any previously existing software. So I started by
writing raw machine code in hexadecimal and then, through a series of
bootstrapping steps, gradually made programming easier for myself
while implementing better and better "languages".
/*
* Copyright (C) 2006 Edmund GRIMLEY EVANS <edmundo@rano.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
polygon(points=[
[0,0],
[0,-1.64],
[2.66,-4.3],
[8.26,-4.3],
[11,-1.64],
[11,0]
]);
@seanjensengrey
seanjensengrey / avro.txt
Created November 2, 2017 16:05
avro tests
{
"type" : "record",
"name" : "twitter_schema",
"namespace" : "com.miguno.avro",
"fields" : [ {
"name" : "username",
"type" : "string",
"doc" : "Name of the user account on Twitter.com"
}, {
"name" : "tweet",
@seanjensengrey
seanjensengrey / buzz.rs
Last active July 28, 2017 08:12
rust fizz buzz
use std::collections::HashMap;
type BuzzFn<'a> = Box<(Fn(i32) -> String) + 'a>;
fn mbfn<'a, F>(f: F) -> BuzzFn<'a>
where F: Fn(i32) -> String + 'a {
Box::new(f) as BuzzFn
}
fn do_buzz() {
@seanjensengrey
seanjensengrey / tiny.c
Last active March 25, 2024 16:46
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>
/*
/** Apache Licensed **/
function t2() {
aref = document.getElementsByTagName("a");
var result = [];
for(i = 0; i < aref.length; i++) {
var t = aref[i];
if (t.href.includes("forum")) {
result.push(t.href);
}
}
def do(cmd):
try:
return (True, cmd())
except Exception as e:
return (False, e)
do(lambda x: os.access(".",123123123123))