Skip to content

Instantly share code, notes, and snippets.

@chanchalg
chanchalg / mrisc.rb
Created July 8, 2011 01:42 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
@chanchalg
chanchalg / unflattentree.js
Created January 20, 2011 12:19
normalize an object tree, graph
function ksplit(name, lookupspace){
var parts = name.split('.');
var current = lookupspace;
for (var i in parts) {
print(i + " " + parts[i]);
if (!current[parts[i]]) {
print(" not there: " + parts[i]);
current[parts[i]] = {};
}
current = current[parts[i]];