[m-dev.] for review: cfloat.m

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Jan 26 15:32:31 AEDT 2000


For Fergus to review. However, this diff also identifies a bug in the compiler,
which Simon should look at; it shouldn't be too hard to fix.

extras/clpr/cfloat.m:
	Fix an archaic way of implementing the cfloat type, which was causing
	problems by relying on obsolete parts of the RTTI system.

Zoltan.

cvs diff: Diffing .
Index: cfloat.m
===================================================================
RCS file: /home/mercury1/repository/clpr/cfloat.m,v
retrieving revision 1.26
diff -u -b -r1.26 cfloat.m
--- cfloat.m	1999/10/27 05:24:50	1.26
+++ cfloat.m	2000/01/26 04:24:37
@@ -349,9 +349,27 @@
 
 %----------------------------------------------------------------------------%
 
-:- type cfloat.
+:- type cfloat ---> cfloat(int)
+	where equality is cfloat__unify.
 	% The cfloat is stored as an int (the CLP(R) solver_id for it).
 
+:- interface.
+
+	% This predicate is never invoked directly; it is only ever invoked
+	% for complicated unifications of cfloat variables.
+	%
+	% XXX This predicate is only exported because keeping it private
+	% tickles a bug: when creating the .opt file, the compiler outputs
+	% the true definition of the cfloat type, complete with the name of
+	% the equality predicate, but does not include the declaration of the
+	% equality predicate. This causes the consumers of the .opt file
+	% to barf.
+
+:- pred cfloat__unify(cfloat, cfloat).
+:- mode cfloat__unify(in, in) is semidet.
+
+:- implementation.
+
 :- pragma c_header_code("
 
 #include ""./clpr/emul.h""
@@ -869,59 +887,11 @@
 ").
 
 :- pragma c_code("
-
-	/* type_ctor_functors for `cfloat' */
-
-MR_MODULE_STATIC_OR_EXTERN
-const struct mercury_data_cfloat__type_ctor_functors_cfloat_0_struct {
-	Integer f1;
-} mercury_data_cfloat__type_ctor_functors_cfloat_0 = {
-	MR_TYPE_CTOR_FUNCTORS_SPECIAL
-};
-
-	/* type_ctor_layout for `cfloat' */
-
-MR_MODULE_STATIC_OR_EXTERN
-const struct mercury_data_cfloat__type_ctor_layout_cfloat_0_struct {
-	TYPE_LAYOUT_FIELDS
-} mercury_data_cfloat__type_ctor_layout_cfloat_0 = {
-	make_typelayout_for_all_tags(TYPE_CTOR_LAYOUT_CONST_TAG, 
-		MR_mkbody(MR_TYPE_CTOR_LAYOUT_C_POINTER_VALUE))
-};
-
-	/* unify/2, compare/3, and index/2 predicates for `cfloat' */
-
-Define_extern_entry(mercury____Unify___cfloat__cfloat_0_0);
-Define_extern_entry(mercury____Compare___cfloat__cfloat_0_0);
-Define_extern_entry(mercury____Index___cfloat__cfloat_0_0);
-
-BEGIN_MODULE(cfloat_module)
-	init_entry(mercury____Unify___cfloat__cfloat_0_0);
-	init_entry(mercury____Compare___cfloat__cfloat_0_0);
-	init_entry(mercury____Index___cfloat__cfloat_0_0);
-
-BEGIN_CODE
-
-Define_entry(mercury____Unify___cfloat__cfloat_0_0);
-	r1 = ML_cfloat_eq(r1, r2);
-	proceed();
-
-Define_entry(mercury____Compare___cfloat__cfloat_0_0);
-	fatal_error(""cannot compare cfloats"");
-
-Define_entry(mercury____Index___cfloat__cfloat_0_0);
-	fatal_error(""cannot index cfloats"");
-
-END_MODULE
-
-/* Ensure that the initialization code for the above module gets run. */
 /*
 INIT init_cfloat_module
 */
 void init_cfloat_module(void) __attribute__((constructor)); /* XXX gcc-ism */
 void init_cfloat_module(void) {
-	extern ModuleFunc cfloat_module;
-	cfloat_module();
 	CLPR_init();
 }
 
@@ -1091,6 +1061,10 @@
 
 %-----------------------------------------------------------------------------%
 
+:- pragma c_code(cfloat__unify(Svar1::in, Svar2::in),
+	"
+		SUCCESS_INDICATOR = ML_cfloat_eq(Svar1, Svar2);
+	").
 :- pragma c_code(cfloat__eq(Svar1::ca, Svar2::ca),
 	"
 		SUCCESS_INDICATOR = ML_cfloat_eq(Svar1, Svar2);
cvs diff: Diffing clpr
cvs diff: Diffing samples
--------------------------------------------------------------------------
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