This refactors the object_h struct to store objects as indexes rather than pointers. This is a prerequisite for making the collection of objects dynamic in the future. See also #6100.
Follow-up to #5800 and #5829.
This maintains the type information which can be used for enforce
const-correctness and also for implementing more advanced ways of
handling the type information.