stab = {} stab.stack = {} stab.pc = 1 stab.cins = 0 mem = {} t408 = require "t408" while true do io.write("*> ") i=io.read() it = {} for s in i:gmatch("%S+") do it[#it+1] = s end if it[1] == "quit" then break elseif it[1] == "peek" then print(mem[tonumber(it[2])]) elseif it[1] == "poke" then mem[tonumber(it[2])] = tonumber(it[3]) elseif it[1] == "push" then stab.stack[#stab.stack+1] = tonumber(it[2]) elseif it[1] == "dumpstack" then for k,v in ipairs(stab.stack) do print(k,v) end elseif it[1] == "ppc" then print(stab.pc) elseif it[1] == "spc" then stab.pc=tonumber(it[2]) elseif it[1] == "step" then local scount = tonumber(it[2]) or 1 for i = 1, scount do stab.cins = mem[stab.pc] stab,rw,addr,val=t408.run(stab) --print(rw,addr,val) if rw == "halt" then print("Halted at "..tostring(stab.pc) )break end if rw == "read" then stab.stack[#stab.stack+1] = mem[addr] elseif rw == "write" then mem[addr] = val if addr == 0 then io.write(string.char(val)) end end end elseif it[1] == "debug" then print(not t408.debug) t408.debug = not t408.debug elseif it[1] == "load" then local f,e = io.open(it[2]) if f == nil then print("Error: "..e) else local n = tonumber(it[3]) or 0 local c = f:read("*a") f:close() for v in c:gmatch("%d+") do mem[n] = tonumber(v) or 0 n = n + 1 end end end end