[m-dev.] fix table_nondet_return_all_ans problems

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Apr 23 02:16:49 AEST 1999


Estimated hours taken: 0.5

library/private_builtin.m:
	Use `pragma c_code' rather than hand-coded low-level C code
	for table_nondet_return_all_ans/2.  The hand-coded low-level
	C code had some bugs in it which meant that it didn't compile
	in all grades.  The bug which previously stopped us using
	`pragma c_code' has been fixed now, we think.

Workspace: /home/mercury0/fjh/mercury-other
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.20
diff -u -r1.20 private_builtin.m
--- private_builtin.m	1999/04/21 07:32:45	1.20
+++ private_builtin.m	1999/04/22 15:45:20
@@ -882,78 +882,34 @@
 #endif
 ").
 
-% The following nondet pragma c code seems to be compiled to C all right,
-% but the C compiler seems to simply omit several statements from the
-% generated executable. This is the reason for the handwritten module below.
-
-% :- pragma c_code(table_nondet_return_all_ans(T::in, A::out),
-% 	will_not_call_mercury,
-% 	local_vars("
-% 		MR_AnswerList	cur_node;
-% 	"),
-% 	first_code("
-% 		LOCALS->cur_node = MR_SUBGOAL(T)->answer_list;
-% 	"),
-% 	retry_code("
-% 	"),
-% 	shared_code("
-% 		if (LOCALS->cur_node == NULL) {
-% 			FAIL;
-% 		} else {
-% 			A = LOCALS->cur_node->answer_data;
-% 			LOCALS->cur_node = LOCALS->cur_node->next_answer;
-% 			SUCCEED;
-% 		}
-% 	")
-% ).
-
-:- external(table_nondet_return_all_ans/2).
-
-:- pragma c_code("
-BEGIN_MODULE(private_builtin_module_XXX)
-	init_entry(mercury__table_nondet_return_all_ans_2_0);
-	init_label(mercury__table_nondet_return_all_ans_2_0_i1);
-BEGIN_CODE
-Define_entry(mercury__table_nondet_return_all_ans_2_0);
-#ifdef	MR_USE_MINIMAL_MODEL
-	mkframe(""private_builtin:table_nondet_return_all_ans/2"", 1,
-		LABEL(mercury__table_nondet_return_all_ans_2_0_i1));
-	MR_framevar(1) = (Word) MR_SUBGOAL(r1)->answer_list;
-#ifdef	MR_TABLE_DEBUG
-	if (MR_tabledebug) {
-		printf(""from subgoal %p, ""
-			""returning everything in answer list %p\\n"",
-			 MR_SUBGOAL(r1), MR_SUBGOAL(r1)->answer_list);
-	}
+:- pragma c_code(table_nondet_return_all_ans(T::in, A::out),
+	will_not_call_mercury,
+	local_vars("
+#ifdef MR_USE_MINIMAL_MODEL
+		MR_AnswerList	cur_node;
 #endif
-Define_label(mercury__table_nondet_return_all_ans_2_0_i1);
-	if ( ((MR_AnswerList) MR_framevar(1)) == NULL) {
-		fail();
-	} else {
-#ifdef	MR_TABLE_DEBUG
-		if (MR_tabledebug) {
-			printf(""returning answer block %p\\n"",
-				(MR_AnswerList) MR_framevar(1));
-			printf(""num %ld, answer %ld at %p, next %p\\n"",
-				(long) ((MR_AnswerList)
-					MR_framevar(1))->answer_num,
-				(long) ((MR_AnswerList)
-					MR_framevar(1))->answer_data,
-				&((MR_AnswerList) MR_framevar(1))->answer_data,
-				((MR_AnswerList) MR_framevar(1))->next_answer);
-		}
+	"),
+	first_code("
+#ifdef MR_USE_MINIMAL_MODEL
+		LOCALS->cur_node = MR_SUBGOAL(T)->answer_list;
 #endif
-		r1 = (Word) &((MR_AnswerList) MR_framevar(1))->answer_data;
-		MR_framevar(1) = (Word)
-			((MR_AnswerList) MR_framevar(1))->next_answer;
-		succeed();
-	}
+	"),
+	retry_code("
+	"),
+	shared_code("
+#ifdef MR_USE_MINIMAL_MODEL
+		if (LOCALS->cur_node == NULL) {
+			FAIL;
+		} else {
+			A = LOCALS->cur_node->answer_data;
+			LOCALS->cur_node = LOCALS->cur_node->next_answer;
+			SUCCEED;
+		}
 #else
-	fatal_error(""minimal model code entered when not enabled"");
+		fatal_error(""minimal model code entered when not enabled"");
 #endif
-END_MODULE
-").
-
+	")
+).
 %-----------------------------------------------------------------------------%
 
 :- interface.

-- 
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.
--------------------------------------------------------------------------
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