diff: map__lookup error message

David Glen JEFFERY dgj at cs.mu.oz.au
Fri May 16 17:12:56 AEST 1997


Hi,

Here's a diff which adds a better error message when map__lookup fails. It
now tells you the types of the key and the value for which it fails, which
should cut down the search space considerably.

As a consequence, I've also added a `normal' version for use by Sicstus and
NU Prolog.

---
Estimated hours taken: 4

Improved the error messages for map__lookup failure by writing out the types
of the values and keys.

Also, since the Prologs cannot handle the type_of functions, a `normal' 
version of map__lookup has been added to map.nu.nl

To accomodate this, this change implements a mechanism to override 
definitions of predicates for particular Prologs. This mechanism makes
explicit which .no or .ql files contain preds overriding others, and so
makes things a bit more robust.

library/map.m:
	Implement the better error messages.
library/map.nu.nl:
	The Prolog version of map__lookup.
library/Mmakefile:
	Set new environment variables, MERCURY_NU_OVERRIDDEN_LIB_OBJS or
	MERCURY_SP_OVERRIDDEN_LIB_OBJS to be the files which are to be
	linked, but contain definitions which override others.
scripts/mnl.in:
	Link everything in MERCURY_NU_OVERRIDDEN_LIB_OBJS last.
scripts/msl.in:
	Link everything in MERCURY_SP_OVERRIDDEN_LIB_OBJS last.


Index: library/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/Mmakefile,v
retrieving revision 1.2
diff -u -r1.2 Mmakefile
--- Mmakefile	1997/02/19 05:32:53	1.2
+++ Mmakefile	1997/05/16 06:43:01
@@ -23,7 +23,8 @@
 MNC	=	MERCURY_NC_BUILTIN="`vpath_find nc_builtin.nl`" \
 		$(SCRIPTS_DIR)/mnc
 MNL	=	MERCURY_NU_LIB_DIR=. \
-	MERCURY_NU_LIB_OBJS="`vpath_find $(library.nos) $(NU_LIBRARY_NOS)`" \
+		MERCURY_NU_LIB_OBJS="`vpath_find $(library.nos) $(NU_LIBRARY_NOS)`" \
+		MERCURY_NU_OVERRIDDEN_LIB_OBJS="$(NU_OVERRIDDEN_LIBRARY_NOS)" \
 		$(SCRIPTS_DIR)/mnl -v
 
 MSC	=	MERCURY_SICSTUS_COMPILER=./sicstus_compile $(SCRIPTS_DIR)/msc
@@ -31,6 +32,7 @@
 		MERCURY_SICSTUS_PROLOG=./sicstus_saved_state \
 		MERCURY_SP_LIB_OBJS="`vpath_find sp_builtin.ql \
 				$(library.qls) $(NU_LIBRARY_QLS) portray.ql`" \
+		MERCURY_SP_OVERRIDDEN_LIB_OBJS="$(NU_OVERRIDDEN_LIBRARY_QLS)" \
 		$(SCRIPTS_DIR)/msl
 
 MCD	=	MERCURY_INT_DIR=. \
@@ -57,9 +59,12 @@
 NU_LIBRARY_NOS = \
 	io.nu.no require.nu.no std_util.nu.no string.nu.no term_io.nu.no \
 	int.nu.no float.nu.no char.nu.no mercury_builtin.nu.no
+NU_OVERRIDDEN_LIBRARY_NOS = map.nu.no
+
 NU_LIBRARY_QLS = \
 	io.nu.ql require.nu.ql std_util.nu.ql string.nu.ql term_io.nu.ql \
 	int.nu.ql float.nu.ql char.nu.ql mercury_builtin.nu.ql sp_lib.ql
+NU_OVERRIDDEN_LIBRARY_QLS = map.nu.ql
 
 #-----------------------------------------------------------------------------#
 
@@ -73,7 +78,7 @@
 
 .PHONY: nuprolog
 nuprolog : ints library.nu library.nu.debug $(library.nos) $(NU_LIBRARY_NOS) \
-			nc_builtin.nl
+			$(NU_OVERRIDDEN_LIBRARY_NOS) nc_builtin.nl
 
 .PHONY: sicstus
 sicstus : ints sicstus_compile library.sicstus.debug
@@ -147,15 +152,16 @@
 # automatic dependencies assume that the library
 # isn't part of the application, but in this case it is.
 
-library.nu library.nu.debug: $(NU_LIBRARY_NOS)
-library.sicstus library.sicstus.debug: sp_builtin.ql $(NU_LIBRARY_QLS)
+library.nu library.nu.debug: $(NU_LIBRARY_NOS) $(NU_OVERRIDDEN_LIBRARY_NOS)
+library.sicstus library.sicstus.debug: sp_builtin.ql $(NU_LIBRARY_QLS) $(NU_OVERRIDDEN_LIBRARY_QLS)
 
 library.nu.debug: error.no debug.no portray.no
 library.sicstus library.sicstus.debug: portray.ql
 
-sp_builtin.ql $(library.qls) $(NU_LIBRARY_QLS) portray.ql: sicstus_compile
+sp_builtin.ql $(library.qls) $(NU_LIBRARY_QLS) $(NU_OVERRIDDEN_LIBRARY_QLS) portray.ql: sicstus_compile
 
-$(library.nos) $(NU_LIBRARY_NOS) error.no debug.no portray.no: nc_builtin.nl
+$(library.nos) $(NU_LIBRARY_NOS) $(NU_OVERRIDDEN_LIBRARY_NOS) error.no \
+	debug.no portray.no: nc_builtin.nl
 
 #-----------------------------------------------------------------------------#
 
@@ -249,11 +255,13 @@
 
 .PHONY: install_library_nu
 install_library_nu: $(library.nos) $(NU_LIBRARY_NOS) \
+			$(NU_OVERRIDDEN_LIBRARY_NOS) \
 			error.no debug.no portray.no nc_builtin.nl
 	[ -d $(INSTALL_NU_DIR) ] || mkdir -p $(INSTALL_NU_DIR)
 	cp `vpath_find nc_builtin.nl` $(INSTALL_NU_DIR)
 	[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR)
 	cp `vpath_find $(library.nos) $(NU_LIBRARY_NOS) \
+		$(NU_OVERRIDDEN_LIBRARY_NOS) \
 		error.no debug.no portray.no` $(INSTALL_NU_ARCH_DIR)
 
 .PHONY: install_interpreter_nu
Index: library/map.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/map.m,v
retrieving revision 1.56
diff -u -r1.56 map.m
--- map.m	1997/05/01 10:00:15	1.56
+++ map.m	1997/05/12 08:24:59
@@ -177,7 +177,7 @@
 
 %-----------------------------------------------------------------------------%
 
-:- import_module tree234.
+:- import_module tree234, string.
 
 :- type map(K,V)	==	tree234(K,V).
 
@@ -212,7 +212,17 @@
 	( tree234__search(Map, K, V1) ->
 		V = V1
 	;
-		error("map__lookup: key not found")
+		KeyType = type_name(type_of(K)),
+		ValueType = type_name(type_of(V)),
+		string__append_list(
+			["map__lookup: key not found\n",
+			"\tKey Type: ",
+			KeyType,
+			"\n\tValue Type: ",
+			ValueType
+			],
+			ErrorString),
+		error(ErrorString)
 	).
 
 map__insert(Map0, K, V, Map) :-



Index: scripts/mnl.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/scripts/mnl.in,v
retrieving revision 1.6
diff -u -r1.6 mnl.in
--- mnl.in	1996/05/13 06:12:46	1.6
+++ mnl.in	1997/05/16 06:54:35
@@ -17,6 +17,7 @@
 
 NULIBDIR=${MERCURY_NU_LIB_DIR=@LIBDIR@/nuprolog/@FULLARCH@}
 LIBRARY_OBJS=${MERCURY_NU_LIB_OBJS=" `cd $NULIBDIR; echo *.no` "}
+OVERRIDDEN_LIBRARY_OBJS=${MERCURY_NU_OVERRIDDEN_LIB_OBJS=""}
 debug_objs="portray.no debug.no error.no"
 
 options=
@@ -53,6 +54,10 @@
 		objlist="$objlist $NULIBDIR/$obj"
 	fi
 done
+overriden_objlist=
+for obj in $OVERRIDDEN_LIBRARY_OBJS; do
+	overriden_objlist="$overriden_objlist $NULIBDIR/$obj"
+done
 if $debug; then
 	for obj in $debug_objs; do
 		if echo "" "$@" "" | grep " $obj " > /dev/null; then
@@ -64,9 +69,9 @@
 fi
 
 if $verbose; then
-	echo nc $options $objlist "$@"
+	echo nc $options $objlist "$@" $overriden_objlist
 fi
 case $# in
-	0) exec nc $options $objlist ;;
-	*) exec nc $options $objlist "$@" ;;
+	0) exec nc $options $objlist $overriden_objlist ;;
+	*) exec nc $options $objlist "$@" $overriden_objlist ;;
 esac
Index: scripts/msl.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/scripts/msl.in,v
retrieving revision 1.10
diff -u -r1.10 msl.in
--- msl.in	1996/05/13 06:12:48	1.10
+++ msl.in	1997/05/16 06:18:15
@@ -22,6 +22,7 @@
 SPLIBDIR=${MERCURY_SP_LIB_DIR=@LIBDIR@/sicstus/@FULLARCH@}
 SP=${MERCURY_SICSTUS_PROLOG=$SPLIBDIR/library.sicstus.debug}
 LIBRARY_OBJS=${MERCURY_SP_LIB_OBJS=""}
+OVERRIDDEN_LIBRARY_OBJS=${MERCURY_SP_OVERRIDDEN_LIB_OBJS=""}
 
 verbose=false
 debug=false
@@ -68,8 +69,17 @@
 	fi
 done
 
+overriden_objlist=
+for obj in $OVERRIDDEN_LIBRARY_OBJS 'kludge for broken shells'; do
+	if [ "$obj" = 'kludge for broken shells' ]; then
+		true
+	else
+		overriden_objlist="$overriden_objlist $SPLIBDIR/$obj"
+	fi
+done
+
 if $verbose; then
-	echo Linking $objlist "$@" $sp_lib
+	echo Linking $objlist "$@" $overriden_objlist $sp_lib
 fi
 if $save_temp; then
 	tmp=msl.tmp
@@ -103,8 +113,8 @@
 
 EOF
 	case $# in
-		0) $SP $objlist $sp_lib < $tmp 2>&1 ;;
-		*) $SP $objlist "$@" $sp_lib < $tmp 2>&1 ;;
+		0) $SP $objlist $overriden_objlist $sp_lib < $tmp 2>&1 ;;
+		*) $SP $objlist "$@" $overriden_objlist $sp_lib < $tmp 2>&1 ;;
 	esac
 else
 	cat > $tmp << EOF
@@ -131,8 +141,8 @@
 	e
 EOF
 	case $# in
-		0) $SP $objlist $sp_lib < $tmp 2>&1 ;;
-		*) $SP $objlist "$@" $sp_lib < $tmp 2>&1 ;;
+		0) $SP $objlist $overriden_objlist $sp_lib < $tmp 2>&1 ;;
+		*) $SP $objlist "$@" $overriden_objlist $sp_lib < $tmp 2>&1 ;;
 	esac
 fi # grep -v 'DOMAIN ERROR.*when_condition' 
 # We pipe the output through grep -v to suppress some spurious warnings
---
And here's the version of map__lookup for the Prologs:

%---------------------------------------------------------------------------%
% Copyright (C) 1995 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.
%---------------------------------------------------------------------------%
%
% File: map.nu.nl.
% Main author: dgj.
%
% This file provides an implementation of map__lookup, for which the Mercury
% version calls type_of/1 if the lookup fails, but type_of/1 is not available
% from Prolog.
%
%-----------------------------------------------------------------------------%

:- map__lookup(_Map, K, _V) when K.     % required by bimap.m

map__lookup(Map, K, V) :-
	( tree234__search(Map, K, V1) ->
		V = V1
	;
		error("map__lookup: key not found")
	).

---


love and cuddles,
dgj
-- 



This .sig deliberately left blank






More information about the developers mailing list