[m-dev.] for review: make univ a user defined type.

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 8 19:13:32 AEDT 2001


> +++ library/io.m	2001/01/08 01:48:37
...
> -:- pred io__write_univ_as_univ(univ, io__state, io__state).
> -:- mode io__write_univ_as_univ(in, di, uo) is det.
> -
> -io__write_univ_as_univ(Univ) -->
> -	io__write_string("univ("),
> -	io__write_univ(Univ),
> -	% XXX what is the right TYPE_QUAL_OP to use here?
> -	io__write_string(" : "),
> -	io__write_string(type_name(univ_type(Univ))),
> -	io__write_string(")").

We still don't handle output of types with existentially quantifiers
in a way that lets them be read back in again.  So there should still
be an XXX comment somewhere to replace that one.

> Index: library/std_util.m
>  :- pragma foreign_code("C", 
>  	construct(TypeDesc::in, FunctorNumber::in, ArgList::in) = (Term::out),
> -	will_not_call_mercury, "
> +	may_call_mercury, "
>  {

That will cause problems, because if the code is declared
`may_call_mercury', then the Mercury compiler will wrap it
inside MR_save_registers()/MR_restore_registers().
But the code in this procedure accesses MR_hp rather than
MR_saved_hp.  The MR_restore_registers() call will overwrite
the updated value of MR_hp with the original value,
so any heap allocated here will be overwritten by the
next heap allocation.

I think the simplest fix for this is to leave the
MR_UNIV_OFFSET_FOR_DATA and MR_UNIV_OFFSET_FOR_TYPEINFO
macros around, and continue to let code construct and
deconstruct univs manually using those macros,
rather than using callbacks to Mercury.
That will be a little more efficient, anyway.

> @@ -3724,7 +3537,7 @@
>  
>  :- pragma foreign_code("C",
>  	argument(Term::in, ArgumentIndex::in) = (ArgumentUniv::out),
> -        will_not_call_mercury, "
> +        may_call_mercury, "
>  {

Likewise here.
And in lots of other places in this file.

> Index: runtime/mercury_mcpp.h
> ===================================================================
> RCS file: /home/staff/zs/imp/mercury/runtime/mercury_mcpp.h,v
> retrieving revision 1.2
> diff -u -r1.2 mercury_mcpp.h
> --- runtime/mercury_mcpp.h	2001/01/01 15:05:40	1.2
> +++ runtime/mercury_mcpp.h	2001/01/07 23:37:21
> @@ -132,7 +132,6 @@
>  #define MR_TYPECTOR_REP_FLOAT_val			10
>  #define MR_TYPECTOR_REP_STRING_val			11
>  #define MR_TYPECTOR_REP_PRED_val		    	12
> -#define MR_TYPECTOR_REP_UNIV_val		    	13
>  #define MR_TYPECTOR_REP_VOID_val		    	14
>  #define MR_TYPECTOR_REP_C_POINTER_val			15
>  #define MR_TYPECTOR_REP_TYPEINFO_val			16
...
> Index: runtime/mercury_type_info.h
> ===================================================================
> RCS file: /home/staff/zs/imp/mercury/runtime/mercury_type_info.h,v
> retrieving revision 1.61
> diff -u -r1.61 mercury_type_info.h
> --- runtime/mercury_type_info.h	2000/12/18 07:42:58	1.61
> +++ runtime/mercury_type_info.h	2001/01/07 23:38:09
>  /*
>  ** Definitions for accessing the representation of the
>  ** Mercury typeclass_info.
> @@ -443,7 +413,6 @@
>      MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_FLOAT),
>      MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_STRING),
>      MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_PRED),
> -    MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_UNIV),
>      MR_DEFINE_ENUM_CONST(MR_TYPECTOR_REP_VOID),

That will change the values of the remaining enumeration
constants.  The resulting values will no longer match
the values used in other parts of the Mercury implementation
(e.g. the .NET back-end's mercury_mcpp.cpp, above).

Apart from that, this looks fine, but I think it needs another
round of reviewing after those issues are addressed.

Cheers,
	Fergus.

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