lib/virtual_machine.rb
# Exceptions that can be raised by a program
Exceptions that can be raised by a program
Exceptions that can be raised by a program
def run
    while eip < @buffer.size
      opcode = @buffer[eip]
      operation = ByteCode.opcodes_inverted[ opcode & ByteCode.op_mask ]
      if @actions[ operation ].nil?
        puts "An Error: operation: \"#{operation}\", opcode: \"#{opcode}\""
        raise VirtualMachine::InvalidProgram, "Don't understand the opcode %b" % opcode
      else
        @actions[ operation ].run() 
      end
      @op_count += 1
    end
  end
def run while eip < @buffer . size opcode = @buffer [ eip ] operation = ByteCode . opcodes_inverted [ opcode & ByteCode . op_mask ] if @actions [ operation ] . nil? puts "An Error: operation: \"#{operation}\", opcode: \"#{opcode}\"" raise VirtualMachine :: InvalidProgram , "Don't understand the opcode %b" % opcode else @actions [ operation ] . run ( ) end @op_count += 1 end end
Exceptions that can be raised by a program
Exceptions that can be raised by a program
# Keep track of how many operations we've done