A topos theory foundation for quantum mechanics