[m-rev.] diff: add option --mercury-standard-library-directory

Simon Taylor stayl at cs.mu.OZ.AU
Sun Nov 11 21:11:03 AEDT 2001


Estimated hours taken: 0.25
Branches: main

compiler/options.m:
doc/user_guide.texi:
	Add an option `--mercury-standard-library-directory',
	which can be used to override the standard library
	directory without setting environment variables.

compiler/handle_options.m:
	Append the standard library directory to the list
	of Mercury library directories.

compiler/globals.m:
	Add globals__lookup_maybe_string_option and
	globals__io_lookup_maybe_string_option.

Index: compiler/globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.46
diff -u -u -r1.46 globals.m
--- compiler/globals.m	23 Jul 2001 12:22:04 -0000	1.46
+++ compiler/globals.m	11 Nov 2001 09:10:17 -0000
@@ -17,7 +17,7 @@
 
 :- interface.
 :- import_module options, trace_params, prog_data.
-:- import_module bool, getopt, list, io.
+:- import_module bool, getopt, list, io, std_util.
 
 :- type globals.
 
@@ -89,6 +89,8 @@
 :- pred globals__lookup_int_option(globals::in, option::in, int::out) is det.
 :- pred globals__lookup_string_option(globals::in, option::in, string::out)
 	is det.
+:- pred globals__lookup_maybe_string_option(globals::in, option::in,
+	maybe(string)::out) is det.
 :- pred globals__lookup_accumulating_option(globals::in, option::in,
 	list(string)::out) is det.
 
@@ -167,6 +169,9 @@
 :- pred globals__io_lookup_string_option(option::in, string::out,
 	io__state::di, io__state::uo) is det.
 
+:- pred globals__io_lookup_maybe_string_option(option::in, maybe(string)::out,
+	io__state::di, io__state::uo) is det.
+
 :- pred globals__io_lookup_accumulating_option(option::in, list(string)::out,
 	io__state::di, io__state::uo) is det.
 
@@ -289,6 +294,15 @@
 		error("globals__lookup_int_option: invalid int option")
 	).
 
+globals__lookup_maybe_string_option(Globals, Option, Value) :-
+	globals__lookup_option(Globals, Option, OptionData),
+	( OptionData = maybe_string(MaybeString) ->
+		Value = MaybeString
+	;
+		error(
+		"globals__lookup_string_option: invalid maybe_string option")
+	).
+
 globals__lookup_accumulating_option(Globals, Option, Value) :-
 	globals__lookup_option(Globals, Option, OptionData),
 	( OptionData = accumulating(Accumulating) ->
@@ -439,6 +453,10 @@
 globals__io_lookup_string_option(Option, Value) -->
 	globals__io_get_globals(Globals),
 	{ globals__lookup_string_option(Globals, Option, Value) }.
+
+globals__io_lookup_maybe_string_option(Option, Value) -->
+	globals__io_get_globals(Globals),
+	{ globals__lookup_maybe_string_option(Globals, Option, Value) }.
 
 globals__io_lookup_accumulating_option(Option, Value) -->
 	globals__io_get_globals(Globals),
Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.122
diff -u -u -r1.122 handle_options.m
--- compiler/handle_options.m	10 Nov 2001 10:29:17 -0000	1.122
+++ compiler/handle_options.m	11 Nov 2001 09:59:08 -0000
@@ -226,9 +226,9 @@
     trace_level::in, trace_suppress_items::in, maybe(string)::out,
     io__state::di, io__state::uo) is det.
 
-postprocess_options_2(OptionTable, Target, GC_Method, TagsMethod,
+postprocess_options_2(OptionTable0, Target, GC_Method, TagsMethod,
 		TermNorm, TraceLevel, TraceSuppress, Error) -->
-	{ unsafe_promise_unique(OptionTable, OptionTable1) }, % XXX
+	{ unsafe_promise_unique(OptionTable0, OptionTable1) }, % XXX
 	globals__io_init(OptionTable1, Target, GC_Method, TagsMethod,
 		TermNorm, TraceLevel, TraceSuppress),
 
@@ -717,6 +717,24 @@
 			{ User = "guest" }
 		),
 		globals__io_set_option(aditi_user, string(User))
+	;
+		[]
+	),
+
+	%
+	% Add the standard library directory.
+	%
+	globals__io_lookup_maybe_string_option(
+		mercury_standard_library_directory, MaybeStdLibDir),
+	( { MaybeStdLibDir = yes(StdLibDir) } ->
+		globals__io_get_globals(Globals2),
+		{ globals__get_options(Globals2, OptionTable2) },
+		{ globals__set_options(Globals2,
+			option_table_add_mercury_library_directory(
+				OptionTable2, StdLibDir),
+			Globals3) },
+		{ unsafe_promise_unique(Globals3, Globals4) },
+		globals__io_set_globals(Globals4)
 	;
 		[]
 	),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.344
diff -u -u -r1.344 options.m
--- compiler/options.m	10 Nov 2001 12:34:50 -0000	1.344
+++ compiler/options.m	11 Nov 2001 09:18:49 -0000
@@ -43,6 +43,12 @@
 :- type option_table == option_table(option).
 :- type maybe_option_table == maybe_option_table(option).
 
+	% Add a directory to search for Mercury libraries. This
+	% adds `--search-directory', `--c-include-directory',
+	% `--library-directory' and `--init-file-directory' options.
+:- func option_table_add_mercury_library_directory(option_table,
+		string) = option_table.
+
 :- type option	
 	% Warning options
 		--->	inhibit_warnings
@@ -472,6 +478,7 @@
 		;	mercury_library_directory_special
 		;	mercury_libraries
 		;	mercury_library_special
+		;	mercury_standard_library_directory
 		;	init_file_directories
 		;	init_files
 
@@ -933,6 +940,9 @@
 	mercury_library_directories -	accumulating([]),
 	mercury_library_special -	string_special,
 	mercury_libraries -		accumulating([]),
+					% The mmc script will set the default
+					% --mercury_standard_library_directory.
+	mercury_standard_library_directory - maybe_string(no),
 	init_file_directories -		accumulating([]),
 	init_files -			accumulating([]),
 
@@ -1442,6 +1452,8 @@
 long_option("ml",			mercury_library_special).
 long_option("mercury-library-directory", mercury_library_directory_special).
 long_option("mld",			mercury_library_directory_special).
+long_option("mercury-standard-library-directory",
+					mercury_standard_library_directory).
 long_option("init-file-directory",	init_file_directories).
 long_option("init-file",		init_files).
 long_option("shared-library-extension",	shared_library_extension).
@@ -1579,16 +1591,8 @@
 	set_opt_level(N, OptionTable0, OptionTable).
 special_handler(mercury_library_directory_special, string(Dir),
 			OptionTable0, ok(OptionTable)) :-
-	% The link_library_directories for Mercury libraries are grade
-	% dependent, so they need to be handled in handle_options.m
-	% when we know the grade.
-	OptionTable =
-	    list__foldl(append_to_accumulating_option, [
-	    	search_directories - dir__make_path_name(Dir, "ints"),
-		c_include_directory - dir__make_path_name(Dir, "inc"),
-		init_file_directories - dir__make_path_name(Dir, "modules"),
-		mercury_library_directories - Dir
-		], OptionTable0).
+	OptionTable = option_table_add_mercury_library_directory(
+			OptionTable0, Dir).
 special_handler(mercury_library_special, string(Lib),
 			OptionTable0, ok(OptionTable)) :-
 	OptionTable =
@@ -1597,6 +1601,17 @@
 		mercury_libraries - Lib,
 		init_files - (Lib ++ ".init")
 		], OptionTable0).
+
+option_table_add_mercury_library_directory(OptionTable0, Dir) =
+	% The link_library_directories for Mercury libraries are grade
+	% dependent, so they need to be handled in handle_options.m
+	% when we know the grade.
+	list__foldl(append_to_accumulating_option, [
+	    	search_directories - dir__make_path_name(Dir, "ints"),
+		c_include_directory - dir__make_path_name(Dir, "inc"),
+		init_file_directories - dir__make_path_name(Dir, "modules"),
+		mercury_library_directories - Dir
+	], OptionTable0).
 	  
 :- func append_to_accumulating_option(pair(option, string),
 		option_table) = option_table.
@@ -3021,6 +3036,10 @@
 		"\t`--search-directory', `--library-directory',",
 		"\t`--init-file-directory' and `--c-include-directory'",
 		"\toptions as needed.",
+		"--mercury-standard-library-directory <directory>",
+		"\tSearch <directory> for the Mercury standard library.",
+		"--no-mercury-standard-library-directory",
+		"\tDon't use the Mercury standard library.",
 		"--ml <library>, --mercury-library <library>",
 		"\tLink with the specified Mercury library.",
 		"--init-file-directory <directory>",
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.278
diff -u -u -r1.278 user_guide.texi
--- doc/user_guide.texi	10 Nov 2001 12:34:55 -0000	1.278
+++ doc/user_guide.texi	11 Nov 2001 09:03:51 -0000
@@ -5627,6 +5627,14 @@
 @cindex Libraries, linking with
 Link with the specified Mercury library.
 
+ at item --mercury-standard-library-directory @var{directory}
+ at findex --mercury-standard-library-directory
+Search @var{directory} for the Mercury standard library.
+
+ at item --no-mercury-standard-library-directory
+ at findex --no-mercury-standard-library-directory
+Don't use the Mercury standard library.
+
 @item --init-file-directory @var{directory}
 @findex --init-file-directory
 Append @var{directory} to the list of directories to
--------------------------------------------------------------------------
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