1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556(******************************************************************************)(* *)(* Monolith *)(* *)(* François Pottier *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under the *)(* terms of the GNU Lesser General Public License as published by the Free *)(* Software Foundation, either version 3 of the License, or (at your *)(* option) any later version, as described in the file LICENSE. *)(* *)(******************************************************************************)(* Before [save()] has been called, we maintain a list of [save] functions that
have been registered with us. When [save()] is called, we apply each of them
to one argument, so we obtain a list of [reset] functions, which we store.
When [reset()] is called, we invoke each of these functions. *)typestatus=|BeforeSavingof(unit->unit->unit)list|AfterSavingof(unit->unit)listletstatus=ref(BeforeSaving[])letregistersave=match!statuswith|BeforeSavingsaves->status:=BeforeSaving(save::saves)|AfterSaving_->(* [register] after [save] has no effect. *)()letcallf=f()letsave()=match!statuswith|BeforeSavingsaves->status:=AfterSaving(List.mapcallsaves)|AfterSaving_->assertfalse(* protocol violation *)letreset()=match!statuswith|BeforeSaving_->assertfalse(* protocol violation *)|AfterSavingresets->List.itercallresetsletregister_refr=register(fun()->letsnapshot=!rinfun()->r:=snapshot)