Skip to content

Instantly share code, notes, and snippets.

View haileys's full-sized avatar

Hailey Somerville haileys

View GitHub Profile
#include <cstdlib>
#include <queue>
#include "gc.hh"
GC::GC()
: mark_flag(false), auto_collect(true), reclaim_threshold(16), allocations_since_reclaim(reclaim_threshold)
{ }
GC::Allocation::Allocation(size_t size, bool mark)
: size(size), mark(mark)
// Foo is conceptually a class, but there's nothing special about it from the interpreter's point of view
function Foo(someParam) {
this.someField = someParam;
}
// when you create a new object, the object has a hidden reference (called [[Prototype]] in the ECMAScript spec) to its constructor's prototype property
Foo.prototype.someMethod = function() {
// do shit
}
for(var i = 0; i < 10; i++) {
var something = getSomeObject(i);
foo(function() {
// try to do shit with something inside the callback
});
}
"IF\x9F\x00AEm \x00\x00\x00\x00\x1F\x00>\x00\x00\x00IT\x00\x00NONM\x00\x00nnO\x00AT\x00\x00utc\x00CD\x00\x0001\x00aa\x9F\x00\x03\a\n\r\x06\x06\x0F\v\x05\b\v\v\x02\xFC\xFC\x02\r\a\xFF\a\v\xFA\xF4\xFD\x04\x04\x03\b\x06\v\f\xFD\xFE\a\x04\x05\f\x0E\x0E\n\x02\x03\x05\x01\xF7\xEA\xE8\xE6\xEC\xF6\xF9\x01\x05\xF9\xEA\xE7\xEA\xEA\xF0\xFF\x0E\x13\x0E\x05\xFB\xFF\xFA\xF2\xF5\xF8\xFC\x01\x01\x04\x0E\f\x05\xFA\xF3\xE6\xD7\xDD\xEA\xFC\x0F\r\x02\a\x10\n\n\x11\e \x12\a\xF7\xF7\x04\x04\x12\x17\x04\xFF\x02\x11\x1F\x13\x01\xFD\xFC\xFC\xFB\xEF\xEA\xED\xF6\r\x15\v\x02\xF5\xEC\xF8\x03\n\x00\xF4\x00\v\v\t\x01\xFC\xF9\xF1\xED\xEE\xFC\x04\x04\x05\v\n\xF6\xED\xF7\xFD\x01\x00\xF1\xEE\xEA\xE8\xED\xF7\x06\x0F\x0E\x05\x00\xF9\xF5\xF0\xF0\xF5\xFC\xFB\xFD\x05\x05\b\xFD\xF8\xFF\v\x0E\v\x14\x1E\"%$\x13\xFD\xF0\xF4\x10!\x1D\x0F\x01\xFE\v\r\x02\xF9\xF7\xF1\xDE\xE3\xEC\xF5\xFD\x05\n\x13\x03\xEA\xDA\xDE\xF0\xEF\xFF\x15\x1C\x12\v\xFB\xFA\xFD\xFB\x03\x02\xF5\xE3\xDE\xE6\xF6\xF5\xFC\x04\f\x17\x12\v\xF7\xEE\xED\xE7\xE6\xE3\xE8\xFD\r\b\b\x0E\xFF\xF3\x
LOL = "IF\x9F\x00AEm \x00\x00\x00\x00\x1F\x00>\x00\x00\x00IT\x00\x00NONM\x00\x00nnO\x00AT\x00\x00utc\x00CD\x00\x0001\x00aa\x9F\x00\x03\a\n\r\x06\x06\x0F\v\x05\b\v\v\x02\xFC\xFC\x02\r\a\xFF\a\v\xFA\xF4\xFD\x04\x04\x03\b\x06\v\f\xFD\xFE\a\x04\x05\f\x0E\x0E\n\x02\x03\x05\x01\xF7\xEA\xE8\xE6\xEC\xF6\xF9\x01\x05\xF9\xEA\xE7\xEA\xEA\xF0\xFF\x0E\x13\x0E\x05\xFB\xFF\xFA\xF2\xF5\xF8\xFC\x01\x01\x04\x0E\f\x05\xFA\xF3\xE6\xD7\xDD\xEA\xFC\x0F\r\x02\a\x10\n\n\x11\e \x12\a\xF7\xF7\x04\x04\x12\x17\x04\xFF\x02\x11\x1F\x13\x01\xFD\xFC\xFC\xFB\xEF\xEA\xED\xF6\r\x15\v\x02\xF5\xEC\xF8\x03\n\x00\xF4\x00\v\v\t\x01\xFC\xF9\xF1\xED\xEE\xFC\x04\x04\x05\v\n\xF6\xED\xF7\xFD\x01\x00\xF1\xEE\xEA\xE8\xED\xF7\x06\x0F\x0E\x05\x00\xF9\xF5\xF0\xF0\xF5\xFC\xFB\xFD\x05\x05\b\xFD\xF8\xFF\v\x0E\v\x14\x1E\"%$\x13\xFD\xF0\xF4\x10!\x1D\x0F\x01\xFE\v\r\x02\xF9\xF7\xF1\xDE\xE3\xEC\xF5\xFD\x05\n\x13\x03\xEA\xDA\xDE\xF0\xEF\xFF\x15\x1C\x12\v\xFB\xFA\xFD\xFB\x03\x02\xF5\xE3\xDE\xE6\xF6\xF5\xFC\x04\f\x17\x12\v\xF7\xEE\xED\xE7\xE6\xE3\xE8\xFD\r\b\b\x0E\xFF
before do
if request.path_info =~ %r{\A/(api|app)/}
# do shit
end
end
get "/api/...." do
# do shit
end
VAL js_value_make_double(double num)
{
VAL val;
val.d = num;
return val;
}
@haileys
haileys / gc.c
Created February 18, 2012 05:48
simple, self-contained garbage collector for C
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "gc.h"
static uint16_t pointer_hash(void* ptr)
{
return (2654435761ul * (intptr_t)ptr) >> 16;
}
@haileys
haileys / st.c
Created February 18, 2012 08:55
/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
/* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "st.h"
/* js modification, add include gc.h */
VAL foo(js_vm_t* vm, void* state, VAL this, uint32_t argc, VAL* argv)
{
VAL retn = js_call(argv[0], this, 0, NULL);
retn = js_to_number(retn);
return js_value_make_double(js_value_get_double(retn) * 2);
}