[m-rev.] For review: Implementation of linking stage for Java

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jan 31 12:27:23 AEDT 2004


On 27-Jan-2004, James Goddard <goddardjames at yahoo.com> wrote:
> Implement linking stage of compiler for grade Java.
> 
> compiler/make.program_target.m:
> 	Added new predicate create_java_shell_script/4 which is called at
> 	the linking stage of compilation  for grade Java.  This predicate
> 	creates a shell script which in theory should:
> 
> 	* change to the directory where the module's class files are kept.

I don't think that changing directory a good idea.  Consider, for
example, if the purpose of the program was to create a file in the
current directory... it would be better to instead just add the class
files directory to the CLASSPATH environment variable.

> Index: make.program_target.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/make.program_target.m,v
> retrieving revision 1.22
> diff -u -d -r1.22 make.program_target.m
> --- make.program_target.m	24 Sep 2003 06:35:26 -0000	1.22
> +++ make.program_target.m	27 Jan 2004 03:28:20 -0000
> @@ -388,9 +388,9 @@
>  			{ Succeeded = yes }
>  		;
>  			{ CompilationTarget = java },
> -			{ Succeeded = no },
> -			io__write_string(
> -			"Sorry, not implemented, linking for `--target java'")
> +			module_name_to_file_name(MainModuleName, "", no,
> +					FileName),
> +			create_java_shell_script(FileName, Succeeded)
>  		),
>  
>  		{ Info5 = Info4 ^ command_line_targets :=
> @@ -406,6 +406,98 @@
>  		)
>  	),
>  	globals__io_set_option(link_objects, accumulating(LinkObjects)).
> +
> +	% create_java_shell_script:
> +	%	Create a shell script with the same name as the given module
> +	%	to invoke Java with the appropriate options on the class of the
> +	%	same name.
> +	
> +:- pred create_java_shell_script(string::in, bool::out,
> +		io__state::di, io__state::uo) is det.
> +
> +create_java_shell_script(MainModuleName, Succeeded) -->
> +        globals__io_lookup_bool_option(verbose, Verbose),
> +        maybe_write_string(Verbose, "% Generating shell script `" ++
> +        		MainModuleName ++ "':\n"),
> +
> +        globals__io_lookup_bool_option(use_subdirs, UseSubdirs),
> +        globals__io_lookup_bool_option(use_grade_subdirs, UseGradeSubdirs),
> +        globals__io_lookup_string_option(fullarch, FullArch),
> +        globals__io_get_globals(Globals),
> +        ( { UseSubdirs = yes } ->
> +                { UseGradeSubdirs = yes ->
> +                        grade_directory_component(Globals, Grade),
> +                        DirName = "Mercury"/Grade/FullArch/"Mercury"/"classs"
> +                ;
> +                        DirName = "Mercury"/"classs"
> +                }
> +	;
> +		{ DirName = "." }
> +	),

This should use module_name_to_file_name/6 from modules.m,
rather than hard-coding the algorithm for choosing the directory.

	e.g.

		module_name_to_file_name(MainModuleName, ".class", no,
			ClassFileName),
		DirName = dir.dirname(ClassFileName)

> +	% XXX The correct classpath needs to be set somewhere.
> +	%     It should take the form:
> +	%     <path>/mer_std.jar:<path>/mer_std.runtime.jar:.
> +	%     Currently this variable is empty, which causes problems.
> +	% globals__io_lookup_accumulating_option(java_classpath,
> +	%		Java_Incl_Dirs),
> +	% ( { Java_Incl_Dirs = [] } ->
> +	%	{ ClassPath = "" }
> +	% ;
> +	% 	% XXX PathSeparator should be ";" on Windows
> +	%	{ PathSeparator = ":" },
> +	%	{ join_string_list(Java_Incl_Dirs, "", "",
> +	%			PathSeparator, ClassPath) }
> +	% ),
> +	globals__io_lookup_string_option(java_interpreter, Java),
> +
> +	io__open_output(MainModuleName, OpenResult),
> +	(
> +		{ OpenResult = ok(ShellScript) },
> +		io__write_string(ShellScript, "#!"/"bin"/"sh\n"),

I would just use "#!/bin/sh\n", not "#!"/"bin"/"sh\n".
"#!\bin\sh" is not likely to work on any system.
On Windows, we should probably write out a .bat file instead.
(It's OK if you leave the creation of a .bat file on Windows
as an XXX for now...)

> Index: options.m
...
> @@ -3851,6 +3854,10 @@
>  		"--java-compiler <javac>",
>  		"\tSpecify which Java compiler to use.  The default is `javac'.",
>  		
> +		"--java-interpreter <java>",
> +		"\tSpecify which Java interpreter to use.",
> +		"\tThe default is `java'",
> +
>  		"--java-flags <options>, --java-flag <option>",
>  		"\tSpecify options to be passed to the Java compiler.",
>  		"\t`--java-flag' should be used for single words which need",

The new option should also be documented in doc/user_guide.texi.

Otherwise that looks good.

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