local result = "" local function compile_and_run(source) source = string.format([[ #include #include int main(int argc, const char** argv) { %s } ]],source) print(source.."\n") local file = io.open("main.c","w") file:write(source) file:close() os.execute("gcc main.c") os.execute("./a.out") end local instructions = { ["add (%d+) (%d+) (%d+)"] = function(l,d,a,b) end, ["sub (%d+) (%d+) (%d+)"] = function(l,d,a,b) end, ["mul (%d+) (%d+) (%d+)"] = function(l,d,a,b) end, ["shl (%d+) (%d+)"] = function(l,d,a,b) end, ["shr (%d+) (%d+)"] = function(l,d,a,b) end, ["bor (%d+) (%d+) (%d+)"] = function(l,d,a,b) end, ["band (%d+) (%d+) (%d+)"] = function(l,d,a,b) end, ["li (%d+) (%d+)"] = function(l,d,a,b) end, ["li (%d+) (%d+)"] = function(l,d,a,b) end, ["li (%d+) (%d+)"] = function(l,d,a,b) end } local source = {string.format("int32_t registers = {%s}",string.rep("0",0,","))} local input = io.open("main.funny") local index = 1 for line in input:read("a"):gmatch("[^\n\r]") do table.insert(string.format("instruction%i:",index)) -- add the goto label for the line instruction = instruction + 1 local target for pattern,callback in pairs(instructions) do line:match(pattern) end end compile_and_run(table.concat(source,"\n"))