[m-rev.] make nb_reference table-able

David Overton dmo at cs.mu.OZ.AU
Wed Aug 20 10:15:28 AEST 2003


On Tue, Aug 12, 2003 at 04:52:39PM +1000, Fergus Henderson wrote:
> Branches: main
> Estimated hours taken: 1
> 
> extras/references/nb_reference.m:
> 	Use private_builtin.ref(T) rather than c_pointer for the
> 	nb_reference type, so that nb_references can be copied using
> 	copy/1 or stored in `pragma memo' tables.

Is there a reason that you didn't make the same change in reference.m?
I.e.:


Estimated hours taken: 0.1
Branches: main

extras/references/reference.m:
	Use private_builtin.ref(T) rather than c_pointer for the
	reference type, so that references can be copied using
	copy/1 or stored in `pragma memo' tables.


Index: reference.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/references/reference.m,v
retrieving revision 1.5
diff -u -r1.5 reference.m
--- reference.m	10 Jan 2003 05:49:22 -0000	1.5
+++ reference.m	20 Aug 2003 00:11:00 -0000
@@ -1,5 +1,5 @@
 %-----------------------------------------------------------------------------%
-% Copyright (C) 1998-2000,2002-2003 University of Melbourne.
+% Copyright (C) 1998-2000,2002 University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %-----------------------------------------------------------------------------%
@@ -49,7 +49,7 @@
 :- implementation.
 
 %  This type is implemented in C.
-:- type reference(T) ---> reference(c_pointer).
+:- type reference(T) ---> reference(private_builtin.ref(T)).
 
 :- pragma c_header_code("#include ""c_reference.h""").
 
@@ -57,7 +57,7 @@
 new_reference(X, reference(Ref)) :-
 	impure new_reference_2(X, Ref).
 
-:- impure pred new_reference_2(T::in, c_pointer::out) is det.
+:- impure pred new_reference_2(T::in, private_builtin.ref(T)::out) is det.
 :- pragma inline(new_reference_2/2).
 :- pragma c_code(new_reference_2(X::in, Ref::out), will_not_call_mercury, "
 	MR_incr_hp(Ref, (sizeof(ME_Reference) + sizeof(MR_Word) - 1) / 
@@ -70,7 +70,7 @@
 value(reference(Ref), X) :-
 	semipure value_2(Ref, X).
 
-:- semipure pred value_2(c_pointer::in, T::out) is det.
+:- semipure pred value_2(private_builtin.ref(T)::in, T::out) is det.
 :- pragma inline(value_2/2).
 :- pragma c_code(value_2(Ref::in, X::out), will_not_call_mercury, "
 	X = (MR_Word) ((ME_Reference *) Ref)->value;
@@ -80,7 +80,7 @@
 update(reference(Ref), X) :-
 	impure update_2(Ref, X).
 
-:- impure pred update_2(c_pointer::in, T::in) is det.
+:- impure pred update_2(private_builtin.ref(T)::in, T::in) is det.
 :- pragma inline(update_2/2).
 :- pragma c_code(update_2(Ref::in, X::in), will_not_call_mercury, "
 	ME_Reference *ref = (ME_Reference *) Ref;
@@ -119,7 +119,7 @@
 init(reference(Ref), X) :-
 	impure init_2(Ref, X).
 
-:- impure pred init_2(c_pointer::in, T::in) is det.
+:- impure pred init_2(private_builtin.ref(T)::in, T::in) is det.
 :- pragma inline(init_2/2).
 :- pragma c_code(init_2(Ref::in, X::in), will_not_call_mercury, "
 	((ME_Reference *) Ref)->value = (void *) X;
@@ -128,7 +128,9 @@
 
 
 :- pragma inline(reference__from_c_pointer/1).
-reference__from_c_pointer(CPointer) = reference(CPointer).
+reference__from_c_pointer(CPointer) = reference(Ref) :-
+	private_builtin.unsafe_type_cast(CPointer, Ref).
 
 :- pragma inline(reference__to_c_pointer/1).
-reference__to_c_pointer(reference(CPointer)) = CPointer.
+reference__to_c_pointer(reference(Ref)) = CPointer :-
+	private_builtin.unsafe_type_cast(Ref, CPointer).

-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 5779
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list