[m-dev.] Trailing

Fergus Henderson fjh at cs.mu.oz.au
Wed Aug 13 23:00:24 AEST 1997


Bart Demoen, you wrote:
> 
> Peter Schachte writes:
> 
> > But I have another idea.  For this source code
> > 
> >         p(A, Z) :-
> >                 (   mangle_array(A, A1),
> >                     test(A1) ->
> >                         q(A1, Z)
> >                 ;   q(A, Z)
> >                 ).
> > 
> > we generate code that looks like
> > 
> >         prev_trail = trail_pointer
> >         call mangle_array/2
> >         if (call test/1) {
> >             notify trailed functions that they are being trimmed
> >             trail_pointer = prev_trail
> >             call q/2
> >         } else {
> >             untrail back to prev_trail
> >             trail_pointer = prev_trail
> >             call q/2
> >         }
> 
> This has a problem if mangle_array/2 (or test/1) calls p/2. Can't you
> store the prev_trail in the "environment" of p/2 ? (or was that your
> intention ?)

Yes, that was Peter's intention.

In fact this is basically what is done by the current implementation:

         prev_trail = save_ticket()
         call mangle_array/2
         if (call test/1) {
             discard_ticket()
             call q/2
         } else {
	     restore_ticket(prev_trail)
	     discard_ticket()
             call q/2
         }

It needs only a couple of minor changes (### denotes lines changed):

         prev_trail = save_ticket()
         call mangle_array/2
         if (call test/1) {
             discard_ticket(prev_trail)				###
             call q/2
         } else {
	     restore_and_discard_ticket(prev_trail)		###
             call q/2
         }

Then with suitable definitions of the macros you will get the
desired effect.

> Another thing: you might want to store also the current
> heap top if you want to recover heap space used during the If in case
> it fails.

The current implementation already does that.

> Putting TR and H in local variables was how if-then-else was
> implemented in BIM (for certain tests only).  Also HB := H temporarily
> to do correct trailing ... (sorry for talking WAM :-)

Could you elaborate about `HB := H'?

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list