--help functions & output function print_listing(lst) for ins in all(lst) do print(join(ins, " ")) end end function print_memory(mems) for label, listing in pairs(mems) do print("::"..label.."::") print_listing(listing) end end function export_memory(mems) out = "m = {}" for label, listing in pairs(mems) do out = out.."\n\nm[\""..label.."\"] = {\n" for l in all(listing) do out = out.."{" if l[1] == "jump" then out = out.."\""..l[1].."\", \""..l[2].."\"" else out = out.."\""..l[1].."\"" if (#l > 1) out = out..", "..l[2] if (#l > 2) out = out..", "..l[3] end out = out.."},\n" end out = out.."}" end return out end function join(strings, delimiter) out = "" first = true for s in all(strings) do if (not first) out = out..delimiter first = false out = out..tostr(s) end return out end function list_table(strings) if type(strings) == "string" then return "\""..strings.."\"" elseif type(strings) ~= "table" then return tostr(strings) end out = "{" first = true for k,v in pairs(strings) do if (not first) out = out..", " first = false out = out..tostr(k).."="..list_table(v) end out = out.."}" return out end function deep_eq(this, other) if (tostr(this) ~= tostr(other)) return false if tostr(this) == "[table]" then if (#this ~= #other) return false for i, v in pairs(this) do if (not deep_eq(v, other[i])) return false end end return true end function deep_copy(target) if (type(target) ~= "table") return target local t = {} for k, v in pairs(target) do t[k] = deep_copy(v) end return t end function get_banks(memory) local output = {} local main_idx = 1 for bank, listing in pairs(memory) do add(output,bank) if bank=="main" then main_idx = #output end end output[main_idx] = output[1] output[1] = "main" return output end