state and prove new repl_exp_val with reference store

this is as far as the end-to-end result currently goes, so this ends the
merge with 5075284 (apart from tidying up).
some minor tidying (moving things around)