0006211: An unexpected behavior in toplevel: combination of consecutive let bindings and exceptions

Description

An unexpected behavior in consecutive let bindings at toplevel, say, “let x1 = e1 let x2 = e2;;”. If e2 raises an exception, the result of “x;;” afterwards depends on whether x1 had been already bound before the evaluation of the first phrase.

1) generalize the approach taken for modules of using a unique name for toplevel values

or

2) remember old values and backtrack in case of failure

Personally I would prefer (1), as it is looks like the "right" thing.
However, IIRC correctly, the goal of the current approach of using just a string is to avoid memory leaks.
We would probably have to do something about that too.
WIth (2), we get this for free.

A possible fix is attached to this PR. The hashtable that holds values for toplevel-bound names is replaced by a reference to a persistent map, so that it is trivial to snapshot the map before every execution of a phrase, then roll back to the snapshot when an exception escapes. Review & comments welcome.