--vectorator printh("\n\n\n\n\n\n\n\n\n") instructions = { "return", "jump", "scale", "rotate", "draw", "draw_abs", "move", "place" } function empty_state() return { stack={{"main", 1}}, scale=1, position={0,0}, rotation=0 } end state = nil function vectorate(mem, callbacks) state = empty_state() while true do height = #state.stack bank = state.stack[height][1] index = state.stack[height][2] state.stack[height][2] += 1 instruction = mem[bank][index] perform(state, instruction, callbacks) //printh(list_table(state)) if (#state.stack == 0) break end end function perform(s, op, cb) if cb == nil then cb = {pre=nil, post=nil} end if cb.pre ~= nil then cb.pre(s, op) end if op[1] == "return" then s.stack[#s.stack] = nil elseif op[1] == "jump" then if m[op[2]] ~= nil then add(s.stack, {op[2], 1}) end elseif op[1] == "scale" then s.scale = s.scale * op[2] elseif op[1] == "rotate" then s.rotation += op[2] else x = s.scale * ( op[2]*cos(s.rotation) - op[3]*sin(s.rotation)) y = s.scale * ( op[2]*sin(s.rotation) + op[3]*cos(s.rotation)) if op[1] == "move" then s.position[1] = s.position[1] + x s.position[2] = s.position[2] + y end if op[1] == "place" then s.position[1] = x s.position[2] = y end if op[1] == "draw" then line(s.position[1], s.position[2], s.position[1]+x, s.position[2]+y, 10) s.position[1] += x s.position[2] += y end if op[1] == "draw_abs" then line(s.position[1], s.position[2], x, y, 10) s.position[1] = x s.position[2] = y end end if cb.post ~= nil then cb.post(s, op) end end