[m-dev.] Question about WAM style variables in Mercury

Ralph Becket rafe at cs.mu.OZ.AU
Thu Feb 5 14:39:01 AEDT 2004


Fergus Henderson, Thursday,  5 February 2004:
> On 05-Feb-2004, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > For adding Herbrand types to the language, it would be good if WAM style
> > variables didn't require heap allocation, but instead just formed direct
> > pointer chains.
> > 
> > However, this would mean having pointers to the interior of cells rather
> > than the start of a cell.
> 
> How so?  Could you explain in more detail?

Consider this Mercury snippet:

	X = f(A, B),	% Construct f/2, A & B are unbound Herbrand vars.
	Y = g(C, D),	% Construct g/2, C & D are unbound Herbrand vars.
	A = D,		% Alias A and D.
	B = C		% Alias B and C.

The C code for the constructions using non-heap allocated WAM variables
could be something like

	X = <<construct f/2 cell>>;

	A = &X[0];	% ) Initialize A.
	*A = NULL;	% )

	B = &X[1];	% ) Initialize B.
	*B = NULL;	% )

	Y = <<construct g/2 cell>>;

	C = &X[0];	% ) Initialize C.
	*C = NULL;	% )

	D = &X[1];	% ) Initialize D.
	*D = NULL;	% )

then the unifications would be (assuming we have already dereferenced A,
B, C, D and decided they're each unbound),

	if(A != D) { *A = D; }	% Unify A with D.
	if(B != C) { *B = C; }	% Unify B with C.

The thing is that A, B, C and D at various times point into different
places of the interior of X and Y.

However, the whole thing already looks a tad complicated and, given that
what you've said about GC issues is as I suspected, I'll just use heap
allocated WAM variables.

-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list