[m-rev.] for review: linking with shared Mercury libraries

Simon Taylor stayl at cs.mu.OZ.AU
Thu Jan 23 10:37:45 AEDT 2003


On 16-Jan-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 16-Jan-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 
> > There is now a third kind of object file, `.lpic_o'.
> > These files are compiled with `--pic-reg' but not
> > with CFLAGS_FOR_PIC, so they can be linked with shared
> > Mercury libraries.
> 
> The new file extension should be documented in user_guide.texi.

Done.

> > This doesn't work with Mmake because ml doesn't know
> > which libraries are Mercury libraries, so it can't
> > link with the static versions of those libraries if
> > MERCURY_LINKAGE is set to "static".
> 
> Couldn't we figure out at `mmake depend' time which libraries
> are Mercury libraries?

Possibly, but I'm not planning to add any new functionality
to Mmake from now on.

> > NEWS:
> > README.Linux:
> > compiler/options.m:
> > doc/user_guide.texi:
> > 	Document MERCURY_LINKAGE, LINKAGE, --linkage,
> > 	--mercury-linkage and -R.
> 
> There should also be some mention of these options in the
> "Using Libraries" section.

Done.

> What effect do these options have if they are set when
> you are building a shared library?
>
> Why does `mmc' use different option names for what are conceptually
> the same options as `ml'? 
> 
> 	mmc				ml
> 
> 	--mercury-linkage shared	--mercury-libs shared
> 	--mercury-linkage shared	--mercury-libs static

These don't do the same thing -- `ml --mercury-libs static'
only affects linking with the standard library and runtime, not
other Mercury libraries.  Arguably that's a bug, but it's not likely
to be fixed.  Also, `mmc --mercury-linkage none' doesn't work.

> 	--linkage shared		--shared
> 	--linkage static		--static

I could add `mmc --shared', but `gcc -shared' does a completely
different thing (builds a shared library), so I'm not sure whether
it's a good idea.

> Some general comments:
> 
> You should add some test cases to the test suite to test this change.

Done.

> Please test that your change works with the `--target asm' back-end
> before committing it.

Done.

Simon.


Estimated hours taken: 20
Branches: main

Make it easier to use shared libraries on x86 with
`mmc --make'.

There is now a third kind of object file, `.lpic_o'.
These files are compiled with `--pic-reg' but not with
CFLAGS_FOR_PIC, so they can be linked with shared Mercury
libraries.

On x86, executables which are linked with shared Mercury
libraries now depend on $(main_module.lpic_os), not
$(main_module.os).

This doesn't work with Mmake because ml doesn't know
which libraries are Mercury libraries, so it can't
link with the static versions of those libraries if
MERCURY_LINKAGE is set to "static".

configure.in:
bindist/bindist.configure.in:
bindist/bindist.build_vars.in:
	Work out whether `.lpic_o' files are needed.

compiler/modules.m:
	Add `.lpic_o' to the list of grade or architecture
	dependent files.

NEWS:
README.Linux:
compiler/options.m:
doc/user_guide.texi:
	Document MERCURY_LINKAGE, LINKAGE, --linkage,
	--mercury-linkage and -R.

compiler/options_file.m:
compiler/make.program_target.m:
	Handle LINKAGE and MERCURY_LINKAGE variables.

	Allow LIBGRADES, LINKAGE and MERCURY_LINKAGE to be target-specific.

scripts/mmc.in:
	Set up the default linkage using the MERCURY_LINKAGE
	variable.
	
compiler/compile_target_code.m:
	Build `.lpic_o' files.

	Work out which type of object files to link with.

	When linking statically with Mercury libraries,
	find the absolute pathname for the `.a' file
	for each Mercury library, and pass that to ml,
	rather than just using `-lname'.

	Pass `-R' options to ml for each `-R' option to mmc.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
	Specify which type of object files to build.

compiler/make.program_target.m:
compiler/make.module_target.m:
	Make sure all generated object files are cleaned up.

compiler/prog_io.m:
	Add a better message for files which can't be found.

compiler/make.util.m:
	Add `.lpic_o' to the list of extensions.

compiler/Mmakefile:
profiler/Mmakefile:
deep_profiler/Mmakefile:
	Pass `--linkage shared' to mmc (`--shared' is in MLFLAGS).

tests/Mmakefile:
tests/mmc_make/Mmakefile:
tests/mmc_make/Mercury.options:
tests/mmc_make/complex_test.{m,exp}:
tests/mmc_make/hello.{m,exp}:
	Test `mmc --make'.

tests/lib/complex*.m:
	The complex numbers library from the extras distribution,
	for use in the mmc_make tests.

diff -u NEWS NEWS
--- NEWS
+++ NEWS
@@ -57,10 +57,7 @@
 
 Changes to the Mercury compiler:
 
-* It's now easier to use shared libraries on Linux/x86 systems with
-  `mmc --make'.  See the documentation for the `--mercury-linkage'
-  and `--linkage' options and the `MERCURY_LINKAGE' Mmake variable
-  in the Mercury User's Guide.
+* Nothing yet.
 
 Portability improvements:
 
@@ -71,6 +68,11 @@
 * Nothing yet.
 
 Changes to the Mercury compiler:
+
+* It's now easier to use shared libraries on Linux/x86 systems with
+  `mmc --make'.  See the documentation for the `--mercury-linkage'
+  and `--linkage' options and the `MERCURY_LINKAGE' Mmake variable
+  in the Mercury User's Guide.
 
 * The Mercury compiler now uses `.' and not `:' as the module separator
   in all output.
diff -u compiler/compile_target_code.m compiler/compile_target_code.m
--- compiler/compile_target_code.m
+++ compiler/compile_target_code.m
@@ -103,13 +103,12 @@
 :- pred link_module_list(list(string), bool, io__state, io__state).
 :- mode link_module_list(in, out, di, uo) is det.
 
-	% get_linkage_info(TargetType, PIC, ObjExt)
+	% get_object_code_type(TargetType, PIC)
 	%
-	% Work out whether we should be using position independent
-	% code, and what object extension should be used.
-:- pred get_linkage_info(linked_target_type, pic, string,
-		io__state, io__state).
-:- mode get_linkage_info(in, out, out, di, uo) is det.
+	% Work out whether we should be generating position-independent
+	% object code.
+:- pred get_object_code_type(linked_target_type, pic, io__state, io__state).
+:- mode get_object_code_type(in, out, di, uo) is det.
 
 %-----------------------------------------------------------------------------%
 	% Code to deal with `--split-c-files'.
@@ -694,23 +693,24 @@
 %-----------------------------------------------------------------------------%
 
 assemble(ErrorStream, PIC, ModuleName, Succeeded) -->
-	% XXX What is the difference between the PIC argument
-	%     and the setting of the `--pic' option here?
-	%     When can they be different?
-	globals__io_lookup_bool_option(pic, PicOption),
-	{ ( PicOption = yes ; PIC = pic ) ->
-		ReallyPic = pic,
+	{
+		PIC = pic,
 		AsmExt = ".pic_s",
 		GCCFLAGS_FOR_ASM = "-x assembler ",
 		GCCFLAGS_FOR_PIC = "-fpic "
 	;
-		ReallyPic = non_pic,
+		PIC = link_with_pic,
+		% `--target asm' doesn't support any grades for
+		% which `.lpic_o' files are needed.
+		error("compile_target_code__assemble: link_with_pic")
+	;
+		PIC = non_pic,
 		AsmExt = ".s",
 		GCCFLAGS_FOR_ASM = "",
 		GCCFLAGS_FOR_PIC = ""
 	},
 	module_name_to_file_name(ModuleName, AsmExt, no, AsmFile),
-	maybe_pic_object_file_extension(ReallyPic, ObjExt),
+	maybe_pic_object_file_extension(PIC, ObjExt),
 	module_name_to_file_name(ModuleName, ObjExt, yes, ObjFile),
 
 	globals__io_lookup_bool_option(verbose, Verbose),
@@ -812,7 +812,8 @@
 		CompileToSharedLib),
 	{ TargetType =
 		(CompileToSharedLib = yes -> shared_library ; executable) },
-	get_linkage_info(TargetType, _, Obj),
+	get_object_code_type(TargetType, PIC),
+	maybe_pic_object_file_extension(PIC, Obj),
 
 	globals__io_get_target(Target),
 	globals__io_lookup_bool_option(split_c_files, SplitFiles),
@@ -902,7 +903,8 @@
 
 	standard_library_directory_option(StdLibOpt),
 
-	get_linkage_info(executable, PIC, ObjExt),
+	get_object_code_type(executable, PIC),
+	maybe_pic_object_file_extension(PIC, ObjExt),
 	{ InitObj = "_init" ++ ObjExt },
 		
 	module_name_to_file_name(ModuleName, "_init.c", yes, InitCFileName),
@@ -1198,44 +1200,32 @@
 	invoke_system_command(ErrorStream, verbose_commands,
 		MakeLibCmd, MakeLibCmdOK).
 
-get_linkage_info(FileType, ObjectCodeType, ObjExtToUse, !IO) :-
-	globals__io_lookup_string_option(pic_object_file_extension,
-		PicObjExt, !IO),
+get_object_code_type(FileType, ObjectCodeType) -->
+	globals__io_lookup_string_option(pic_object_file_extension, PicObjExt),
 	globals__io_lookup_string_option(link_with_pic_object_file_extension,
-		LinkWithPicObjExt, !IO),
-	globals__io_lookup_string_option(object_file_extension, ObjExt, !IO),
-	globals__io_lookup_string_option(mercury_linkage, MercuryLinkage, !IO),
-	globals__io_lookup_bool_option(gcc_global_registers, GCCGlobals, !IO),
-	globals__io_lookup_bool_option(pic, PIC, !IO),
-	(
+		LinkWithPicObjExt),
+	globals__io_lookup_string_option(object_file_extension, ObjExt),
+	globals__io_lookup_string_option(mercury_linkage, MercuryLinkage),
+	globals__io_lookup_bool_option(gcc_global_registers, GCCGlobals),
+	globals__io_lookup_bool_option(highlevel_code, HighLevelCode),
+	globals__io_lookup_bool_option(pic, PIC),
+	globals__io_get_target(Target),
+	{
 	    PIC = yes,
 		% We've been explicitly told to use position independent code.
-	    ( PicObjExt = ObjExt ->
-		ObjectCodeType = non_pic,
-		ObjExtToUse = ObjExt
-	    ;
-		ObjectCodeType = pic,
-		ObjExtToUse = PicObjExt
-	    )
+	    ObjectCodeType = ( if PicObjExt = ObjExt then non_pic else pic )
 	;
     	    PIC = no,
 	    (
 		FileType = static_library,
-		ObjectCodeType = non_pic,
-		ObjExtToUse = ObjExt
+		ObjectCodeType = non_pic
 	    ;
 		FileType = shared_library,
-		( PicObjExt = ObjExt ->
-			ObjectCodeType = non_pic,
-			ObjExtToUse = ObjExt
-		;
-			ObjectCodeType = pic,
-			ObjExtToUse = PicObjExt
-		)
+		ObjectCodeType =
+			( if PicObjExt = ObjExt then non_pic else pic )
 	    ;
 		FileType = executable,
 		( MercuryLinkage = "shared" ->
-			ObjExtToUse = LinkWithPicObjExt,
 			(
 				% We only need to create `.lpic'
 				% files if `-DMR_PIC_REG' has an
@@ -1243,7 +1233,9 @@
 				% with grades using GCC global
 				% registers on x86.
 				( LinkWithPicObjExt = ObjExt
+				; HighLevelCode = yes
 				; GCCGlobals = no
+				; Target \= c
 				)
 			->
 				ObjectCodeType = non_pic
@@ -1255,14 +1247,13 @@
 				ObjectCodeType = link_with_pic
 			)
 		; MercuryLinkage = "static" ->
-			ObjectCodeType = non_pic,
-			ObjExtToUse = ObjExt
+			ObjectCodeType = non_pic
 		;
 			% The linkage string is checked by options.m.
 			error("unknown linkage " ++ MercuryLinkage)
 		)
 	    )
-	).
+	}.
 
 %-----------------------------------------------------------------------------%
 
diff -u compiler/handle_options.m compiler/handle_options.m
--- compiler/handle_options.m
+++ compiler/handle_options.m
@@ -971,11 +971,6 @@
 		globals__io_set_option(link_library_directories,
 			accumulating(LinkLibDirs ++ ExtraLinkLibDirs)),
 
-		globals__io_lookup_accumulating_option(
-			runtime_link_library_directories, Rpath),
-		globals__io_set_option(runtime_link_library_directories,
-			accumulating(Rpath ++ ExtraLinkLibDirs)),
-
 		{ ExtraCIncludeDirs = list__map(
 			(func(MercuryLibDir) =
 
@@ -987,6 +982,11 @@
 			link_library_directories, LinkLibDirs),
 		globals__io_set_option(link_library_directories,
 			accumulating(LinkLibDirs ++ ExtraLinkLibDirs)),
+
+		globals__io_lookup_accumulating_option(
+			runtime_link_library_directories, Rpath),
+		globals__io_set_option(runtime_link_library_directories,
+			accumulating(Rpath ++ ExtraLinkLibDirs)),
 
 		{ ExtraCIncludeDirs = list__map(
 			(func(MercuryLibDir) =
diff -u compiler/make.program_target.m compiler/make.program_target.m
--- compiler/make.program_target.m
+++ compiler/make.program_target.m
@@ -34,7 +34,11 @@
 :- import_module hlds__passes_aux.
 
 make_linked_target(MainModuleName - FileType, Succeeded, Info0, Info) -->
-	build_with_module_options(MainModuleName, [],
+	{ ExtraOptions =
+		( if FileType = shared_library then ["--compile-to-shared-lib"]
+		  else []
+		) },
+	build_with_module_options(MainModuleName, ExtraOptions,
 		make_linked_target_2(MainModuleName - FileType),
 		Succeeded, Info0, Info).
 
@@ -49,7 +53,7 @@
     ( { DepsSuccess = no, KeepGoing = no } ->
 	{ Succeeded = no }
     ;
-	get_linkage_info(FileType, PIC, ObjExtToUse),
+	get_object_code_type(FileType, PIC),
 
 	%
 	% Build the `.c' files first so that errors are
@@ -104,7 +108,7 @@
 		build_with_output_redirect(MainModuleName, 
 			build_linked_target(MainModuleName, FileType,
 				OutputFileName, MaybeTimestamp, AllModules,
-				ObjModules, CompilationTarget, ObjExtToUse,
+				ObjModules, CompilationTarget,
 				PIC, DepsSuccess, BuildDepsResult)),
 		linked_target_cleanup(MainModuleName, FileType, OutputFileName,
 			CompilationTarget),
@@ -204,13 +208,13 @@
 
 :- pred build_linked_target(module_name::in, linked_target_type::in,
 	file_name::in, maybe_error(timestamp)::in, set(module_name)::in,
-	list(module_name)::in, compilation_target::in, string::in, pic::in,
+	list(module_name)::in, compilation_target::in, pic::in,
 	bool::in, dependencies_result::in, io__output_stream::in,
 	bool::out, make_info::in, make_info::out,
 	io__state::di, io__state::uo) is det.
 
 build_linked_target(MainModuleName, FileType, OutputFileName, MaybeTimestamp,
-		AllModules, ObjModules, CompilationTarget, ObjExtToUse, PIC,
+		AllModules, ObjModules, CompilationTarget, PIC,
 		DepsSuccess, BuildDepsResult, ErrorStream, Succeeded,
 		Info0, Info) -->
 	globals__io_lookup_maybe_string_option(pre_link_command,
@@ -227,7 +231,7 @@
 	( { PreLinkSucceeded = yes } ->
 		build_linked_target_2(MainModuleName, FileType, OutputFileName,
 			MaybeTimestamp, AllModules, ObjModules,
-			CompilationTarget, ObjExtToUse, PIC, DepsSuccess,
+			CompilationTarget, PIC, DepsSuccess,
 			BuildDepsResult, ErrorStream, Succeeded,
 			Info0, Info)
 	;
@@ -237,12 +241,12 @@
 
 :- pred build_linked_target_2(module_name::in, linked_target_type::in,
 	file_name::in, maybe_error(timestamp)::in, set(module_name)::in,
-	list(module_name)::in, compilation_target::in, string::in, pic::in,
+	list(module_name)::in, compilation_target::in, pic::in,
 	bool::in, dependencies_result::in, io__output_stream::in, bool::out,
 	make_info::in, make_info::out, io__state::di, io__state::uo) is det.
 
 build_linked_target_2(MainModuleName, FileType, OutputFileName, MaybeTimestamp,
-		AllModules, ObjModules, CompilationTarget, ObjExtToUse, PIC,
+		AllModules, ObjModules, CompilationTarget, PIC,
 		DepsSuccess, BuildDepsResult, ErrorStream, Succeeded,
 		Info0, Info) -->
 	globals__io_lookup_accumulating_option(link_objects, LinkObjects),
@@ -349,6 +353,7 @@
 			(func(foreign_code_file(_, _, ObjFile)) = ObjFile),
 			list__condense(ExtraForeignFiles)) },
 
+		maybe_pic_object_file_extension(PIC, ObjExtToUse),
 		list__map_foldl(
 		    (pred(ObjModule::in, ObjToLink::out, di, uo) is det -->
 			module_name_to_file_name(ObjModule,
diff -u compiler/mercury_compile.m compiler/mercury_compile.m
--- compiler/mercury_compile.m
+++ compiler/mercury_compile.m
@@ -392,7 +392,7 @@
 		( { Result = ok, TargetCodeOnly = no } ->
 			io__output_stream(OutputStream),
 			get_linked_target_type(TargetType),
-			get_linkage_info(TargetType, PIC, _),
+			get_object_code_type(TargetType, PIC),
 			compile_target_code__assemble(OutputStream,
 				PIC, ModuleName, AssembleOK),
 			maybe_set_exit_status(AssembleOK)
@@ -1205,8 +1205,9 @@
 				%
 				( { ContainsCCode = yes } ->
 					get_linked_target_type(TargetType),
-					compile_target_code__get_linkage_info(
-						TargetType, PIC, Obj),
+					get_object_code_type(TargetType, PIC),
+					maybe_pic_object_file_extension(PIC,
+						Obj),
 					module_name_to_file_name(ModuleName,
 						".c", no, CCode_C_File),
 					{ ForeignModuleName =
@@ -1242,7 +1243,8 @@
 				module_name_to_file_name(ModuleName, ".c", no,
 					C_File),
 				get_linked_target_type(TargetType),
-				get_linkage_info(TargetType, PIC, Obj),
+				get_object_code_type(TargetType, PIC),
+				maybe_pic_object_file_extension(PIC, Obj),
 				module_name_to_file_name(ModuleName, Obj, yes,
 					O_File),
 				io__output_stream(OutputStream),
@@ -3478,7 +3480,8 @@
 			NumChunks, Succeeded)
 	;
 		get_linked_target_type(LinkedTargetType),
-		get_linkage_info(LinkedTargetType, PIC, Obj),
+		get_object_code_type(LinkedTargetType, PIC),
+		maybe_pic_object_file_extension(PIC, Obj),
 		module_name_to_file_name(ModuleName, ".c", no, C_File),
 		module_name_to_file_name(ModuleName, Obj, yes, O_File),
 		compile_target_code__compile_c_file(ErrorStream, PIC,
diff -u compiler/options.m compiler/options.m
--- compiler/options.m
+++ compiler/options.m
@@ -3782,7 +3782,7 @@
 		"\texecutables.",
 		"--mercury-linkage {shared|static}",
 		"\tSpecify whether to use shared or static linking when",
-		"\tlinking with Mercury libraries.",
+		"\tlinking an executable with Mercury libraries.",
 
 		"--init-file-directory <directory>",
 		"\tAppend <directory> to the list of directories to",
diff -u compiler/options_file.m compiler/options_file.m
--- compiler/options_file.m
+++ compiler/options_file.m
@@ -786,11 +786,11 @@
 	% depend on C libraries, but C libraries typically do not
 	% depend on Mercury libraries).
 options_variable_types =
-	[grade_flags, mmc_flags, c_flags, java_flags,
+	[grade_flags, linkage, mercury_linkage, mmc_flags, c_flags, java_flags,
 	ilasm_flags, csharp_flags, mcpp_flags,
 	ml_objs, lib_dirs, ml_flags, ld_flags,
 	libraries, ml_libs, c2init_args,
-	lib_grades, install_prefix, linkage, mercury_linkage].
+	lib_grades, install_prefix].
 
 :- func options_variable_name(options_variable_type) = string.
 
diff -u doc/user_guide.texi doc/user_guide.texi
--- doc/user_guide.texi
+++ doc/user_guide.texi
@@ -228,6 +228,9 @@
 and @file{.o} files are object code.
 In addition, @file{.pic_o} files are object code files
 that contain position-independent code (PIC).
+ at file{.lpic_o} files are object code files that can be
+linked with shared libraries, but don't necessarily
+contain position-independent code themselves.
 @file{.mh} and @file{.mih} files are C header files generated
 by the Mercury compiler. The non-standard extensions are necessary
 to avoid conflicts with system header files.
@@ -1142,7 +1145,11 @@
 @findex --ml
 @findex --mercury-library
 To use a library when invoking @samp{mmc} directly, use the @samp{--mld}
-and @samp{--ml} options (@pxref{Link options}).
+and @samp{--ml} options (@pxref{Link options}).  You can also specify
+whether to link executables with the shared or static versions of Mercury
+libraries using @samp{--mercury-linkage shared} or
+ at samp{--mercury-linkage static} (shared libraries are always linked with
+the shared versions of libraries).
 
 Beware that the directory name that you must use in @samp{EXTRA_LIB_DIRS}
 or as the argument of the @samp{--mld} option is not quite the same as
@@ -6572,8 +6579,8 @@
 @sp 1
 @item --mercury-linkage @{shared,static@}
 @findex --mercury-linkage
-Specify whether to link with the shared or static versions of
-the Mercury standard library and runtime.
+Specify whether to use shared or static linking when
+linking an executable with Mercury libraries.
 
 @end table
 
diff -u scripts/mmc.in scripts/mmc.in
--- scripts/mmc.in
+++ scripts/mmc.in
@@ -47,6 +47,7 @@
 		--c-flag-to-name-object-file \"@OBJFILE_OPT@\" \
 		--object-file-extension \". at OBJ_SUFFIX@\" \
 		--pic-object-file-extension \". at EXT_FOR_PIC_OBJECTS@\" \
+		--link-with-pic-object-file-extension \". at EXT_FOR_LINK_WITH_PIC_OBJECTS@\" \
 		--executable-file-extension \"@EXT_FOR_EXE@\" \
 		--shared-library-extension \". at EXT_FOR_SHARED_LIB@\" \
 		--library-extension \". at LIB_SUFFIX@\"
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/imag_float.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,48 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: imag_float.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (imag, float).
+%
+% See also:
+%	complex.m, imag.m, float_imag.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:imag_float.
+:- interface.
+:- import_module complex_numbers:imag, float, complex_numbers:complex.
+
+	% addition
+:- func imag + float = complex.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func imag - float = complex.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func imag * float = imag.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func imag / float = imag.
+:- mode in   / in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+im(XI) + YR = cmplx(0.0 + YR, 0.0 + XI).
+im(XI) - YR = cmplx(0.0 - YR, 0.0 + XI).
+im(XI) * YR = im(XI * YR).
+im(XI) / YR = im(XI / YR).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/imag_complex.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,58 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: imag_complex.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (imag, complex).
+%
+% See also:
+%	complex.m, imag.m, complex_imag.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:imag_complex.
+:- interface.
+:- import_module complex_numbers:imag, complex_numbers:complex.
+
+	% addition
+:- func imag + complex = complex.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func imag - complex = complex.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func imag * complex = complex.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func imag / complex = complex.
+:- mode in   / in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+:- import_module float.
+
+im(XI) + cmplx(YR, YI) = cmplx(0.0 + YR, XI + YI).
+im(XI) - cmplx(YR, YI) = cmplx(0.0 - YR, XI - YI).
+im(XI) * cmplx(YR, YI) = cmplx(-XI * YI, XI * YR).
+im(XI) / cmplx(YR, YI) = cmplx((XI * YI) / Div, (XI * YR) / Div) :-
+	Div = (YR * YR + YI * YI).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+% Division of imag / complex formula obtained by simplifying this one:
+% cmplx(Xr, Xi) / cmplx(Yr, Yi) =
+%		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
+%	Div = (Yr * Yr + Yi * Yi).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/imag.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,77 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: imag.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% Imaginary numbers.
+%
+% There are several reasons for supporting a separate type for imaginary
+% numbers rather than just treating them as a special case of complex
+% numbers.  It is sometimes more convenient, and can be slightly more
+% efficient.   But perhaps the most important reason is to get correct
+% handling of infinity and not-a-number on platforms that support IEEE
+% floating point.
+%
+% Note that the overloaded versions of the binary operators which
+% provide mixed type arithmetic are defined in different modules.
+%
+% See also:
+%	float.m, imag_float.m, float_imag.m,
+%	complex.m, imag_complex.m, complex_imag.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:imag.
+:- interface.
+:- import_module float.
+
+:- type imag ---> im(float).
+
+:- func i = imag.	% i = sqrt(-1)
+:- func j = imag.	% another name for `i'
+
+	% addition
+:- func imag + imag = imag.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func imag - imag = imag.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func imag * imag = float.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func imag / imag = float.
+:- mode in   / in   = uo  is det.
+
+	% unary plus
+:- func + imag = imag.
+:- mode + in   = uo  is det.
+
+	% unary minus
+:- func - imag = imag.
+:- mode - in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+i = im(1.0).
+j = i.
+
++im(X) = im(X + 0.0).
+-im(X) = im(-X).
+im(X) + im(Y) = im(X + Y).
+im(X) - im(Y) = im(X - Y).
+im(X) * im(Y) = 0.0 - X * Y.
+im(X) / im(Y) = X / Y.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/float_imag.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,48 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: float_imag.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (float, imag).
+%
+% See also:
+%	complex.m, imag.m, float.m, imag_float.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:float_imag.
+:- interface.
+:- import_module float, complex_numbers:imag, complex_numbers:complex.
+
+	% addition
+:- func float + imag = complex.
+:- mode in    + in   = uo  is det.
+
+	% subtraction
+:- func float - imag = complex.
+:- mode in    - in   = uo  is det.
+
+	% multiplication
+:- func float * imag = imag.
+:- mode in    * in   = uo  is det.
+
+	% division
+:- func float / imag = imag.
+:- mode in    / in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+XR + im(YI) = cmplx(0.0 + XR, 0.0 + YI).
+XR - im(YI) = cmplx(0.0 + XR, 0.0 - YI).
+XR * im(YI) = im(XR * YI).
+XR / im(YI) = im(0.0 - XR / YI).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/float_complex.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,58 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: float_complex.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (float, complex).
+%
+% See also:
+%	complex.m, float.m, complex_float.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:float_complex.
+:- interface.
+:- import_module float, complex_numbers:complex.
+
+	% addition
+:- func float + complex = complex.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func float - complex = complex.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func float * complex = complex.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func float / complex = complex.
+:- mode in   / in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+:- import_module complex_numbers:complex_float.
+
+XR + cmplx(YR, YI) = cmplx(XR + YR, + YI).
+XR - cmplx(YR, YI) = cmplx(XR - YR, - YI).
+XR * cmplx(YR, YI) = cmplx(XR * YR, XR * YI).
+XR / cmplx(YR, YI) = cmplx(XR * YR / Div, - XR * YI / Div) :-
+	Div = YR * YR + YI * YI.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+% Division of float / complex formula obtained by simplifying this one:
+% cmplx(Xr, Xi) / cmplx(Yr, Yi) =
+%		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
+%	Div = (Yr * Yr + Yi * Yi).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/complex_numbers.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,11 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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.
+%---------------------------------------------------------------------------%
+:- module complex_numbers.
+:- interface.
+:- include_module complex, imag.
+:- include_module complex_float, float_complex.
+:- include_module complex_imag, imag_complex.
+:- include_module float_imag, imag_float.
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/complex_imag.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,54 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: complex_imag.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (complex, imag).
+%
+% See also:
+%	complex.m, imag.m, imag_complex.m.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:complex_imag.
+:- interface.
+:- import_module complex_numbers:complex, complex_numbers:imag.
+
+	% addition
+:- func complex + imag = complex.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func complex - imag = complex.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func complex * imag = complex.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func complex / imag = complex.
+:- mode in   / in   = uo  is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+:- import_module float.
+
+cmplx(XR, XI) + im(YI) = cmplx(0.0 + XR, XI + YI).
+cmplx(XR, XI) - im(YI) = cmplx(0.0 + XR, XI - YI).
+cmplx(XR, XI) * im(YI) = cmplx(0.0 - XI * YI, 0.0 + XR * YI).
+cmplx(XR, XI) / im(YI) = cmplx(0.0 + XI / YI, 0.0 - XR / YI).
+
+% Division of complex / imag formula obtained by simplifying this one:
+% cmplx(Xr, Xi) / cmplx(Yr, Yi) =
+%		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
+%	Div = (Yr * Yr + Yi * Yi).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/complex_float.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,59 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: complex_float.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% This module provides binary operators on (complex, float).
+%
+% See also:
+%	complex, float, complex_float.
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:complex_float.
+:- interface.
+:- import_module complex_numbers:complex, float.
+
+	% addition
+:- func complex + float = complex.
+:- mode in   + in   = uo  is det.
+
+	% subtraction
+:- func complex - float = complex.
+:- mode in   - in   = uo  is det.
+
+	% multiplication
+:- func complex * float = complex.
+:- mode in   * in   = uo  is det.
+
+	% division
+:- func complex / float = complex.
+:- mode in   / in   = uo  is det.
+
+	% exponentiation
+:- func pow(complex, float) = complex.
+:- mode pow(in, in) = out is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+:- import_module math.
+
+cmplx(XR, XI) + YR = cmplx(XR + YR, + XI).
+cmplx(XR, XI) - YR = cmplx(XR - YR, + XI).
+cmplx(XR, XI) * YR = cmplx(XR * YR, XI * YR).
+cmplx(XR, XI) / YR = cmplx(XR / YR, XI / YR).
+
+pow(Z0, P) = Z :-
+	complex_to_polar(Z0, L0, Th0),
+	L = math__pow(L0, P),
+	Th = Th0 * P,
+	Z = polar_to_complex(L, Th).
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/lib/complex.m	20 Jan 2003 05:57:23 -0000
@@ -0,0 +1,158 @@
+%---------------------------------------------------------------------------%
+% Copyright (C) 1997-1998,2001 The 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: complex.m.
+% Main author: fjh.
+% Stability: medium.
+%
+% Complex numbers.
+%
+% Note that the overloaded versions of the binary operators that
+% provide mixed-type arithmetic are defined in other modules.
+%
+% See also:
+%	complex_float.m, float_complex.m
+%	imag.m, complex_imag.m, imag_complex.m
+%
+%---------------------------------------------------------------------------%
+
+:- module complex_numbers:complex.
+:- interface.
+
+:- type complex ---> cmplx(float, float).	% real part, imag part
+
+% The constructor cmplx/2 is made public, but
+% generally it is most convenient to use the syntax `X + Y*i' for
+% complex numbers, where `i' is declared in module `imag'.
+% Due to the wonders of logic programming, this works fine for
+% both constructing and pattern matching; with intermodule optimization
+% enabled, the compiler should generate equally good code for it.
+
+	% convert float to complex
+:- func complex(float) = complex.
+
+	% extract real part
+:- func real(complex) = float.
+
+	% extract imaginary part
+:- func imag(complex) = float.
+
+	% square of absolute value
+:- func abs2(complex) = float.
+
+	% absolute value (a.k.a. modulus)
+:- func abs(complex) = float.
+
+	% argument (a.k.a. phase, or amplitude, or angle)
+	% This function returns the principle value:
+	% for all Z, -pi < arg(Z) and arg(Z) =< pi.
+:- func arg(complex) = float.
+
+	% complex conjugate
+:- func conj(complex) = complex.
+
+	% addition
+:- func complex + complex = complex.
+:- mode in  + in  = uo  is det.
+
+	% subtraction
+:- func complex - complex = complex.
+:- mode in  - in  = uo  is det.
+
+	% multiplication
+:- func complex * complex = complex.
+:- mode in  * in  = uo  is det.
+
+	% division
+:- func complex / complex = complex.
+:- mode in  / in  = uo  is det.
+
+	% unary plus
+:- func + complex = complex.
+:- mode + in    = uo  is det.
+
+	% unary minus
+:- func - complex = complex.
+:- mode - in    = uo  is det.
+
+	% sqr(X) = X * X.
+:- func sqr(complex) = complex.
+:- mode sqr(in) = out is det.
+
+	% square root
+:- func sqrt(complex) = complex.
+:- mode sqrt(in) = out is det.
+
+	% cis(Theta) = cos(Theta) + i * sin(Theta)
+:- func cis(float) = complex.
+
+	% polar_to_complex(R, Theta):
+	% conversion from polar coordinates
+:- func polar_to_complex(float, float) = complex.
+:- mode polar_to_complex(in, in) = out is det.
+
+	% polar_to_complex(Z, R, Theta):
+	% conversion to polar coordinates
+:- pred complex_to_polar(complex, float, float).
+:- mode complex_to_polar(in, out, out) is det.
+
+%---------------------------------------------------------------------------%
+
+:- implementation.
+:- import_module float, math.
+
+complex(Real) = cmplx(Real, 0.0).
+
+real(cmplx(Real, _Imag)) = Real.
+imag(cmplx(_Real, Imag)) = Imag.
+
+cmplx(Xr, Xi) + cmplx(Yr, Yi) = cmplx(Xr + Yr, Xi + Yi).
+cmplx(Xr, Xi) - cmplx(Yr, Yi) = cmplx(Xr - Yr, Xi - Yi).
+cmplx(Xr, Xi) * cmplx(Yr, Yi) =
+		cmplx(Xr * Yr - Xi * Yi, Xr * Yi + Xi * Yr).
+cmplx(Xr, Xi) / cmplx(Yr, Yi) =
+		cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
+	Div = (Yr * Yr + Yi * Yi).
+% Here's the derivation of the formula for complex division:
+% cmplx(Xr, Xi) / cmplx(Yr, Yi) =
+%	(cmplx(Xr, Xi) / cmplx(Yr, Yi)) * 1.0 =
+%	(cmplx(Xr, Xi) / cmplx(Yr, Yi)) * (cmplx(Yr, -Yi) / cmplx(Yr, -Yi)) =
+%	(cmplx(Xr, Xi) * (cmplx(Yr, -Yi)) / (cmplx(Yr, Yi) * cmplx(Yr, -Yi)) =
+%	(cmplx(Xr, Xi) * (cmplx(Yr, -Yi)) / (Yr * Yr + Yi * Yi) =
+%	cmplx(Xr * Yr + Xi * Yi, Xi * Yr - Xr * Yi) / (Yr * Yr + Yi * Yi) =
+%	cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
+%		Div = (Yr * Yr + Yi * Yi).
+
++ cmplx(R, I) = cmplx(+ R, + I).
+- cmplx(R, I) = cmplx(- R, - I).
+
+abs2(cmplx(R, I)) = R*R + I*I.
+
+abs(Z) = sqrt(abs2(Z)).
+
+arg(cmplx(R, I)) = atan2(I, R).
+
+conj(cmplx(R, I)) = cmplx(R, -I).
+
+sqr(cmplx(Re0, Im0)) = cmplx(Re, Im) :-
+	Re = Re0 * Re0 - Im0 * Im0,
+	Im = 2.0 * Re0 * Im0.
+
+sqrt(Z0) = Z :-
+	complex_to_polar(Z0, Magnitude0, Theta0),
+	Magnitude = sqrt(Magnitude0),
+	Theta = Theta0 / 2.0,
+	Z = polar_to_complex(Magnitude, Theta).
+
+complex_to_polar(Z, abs(Z), arg(Z)).
+
+polar_to_complex(Magnitude, Theta) = cmplx(Real, Imag) :-
+	Real = Magnitude * cos(Theta),
+	Imag = Magnitude * sin(Theta).
+
+cis(Theta) = cmplx(cos(Theta), sin(Theta)).
+
+%------------------------------------------------------------------------------%
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/hello.m	20 Jan 2003 07:04:11 -0000
@@ -0,0 +1,13 @@
+% "Hello World" in Mercury.
+
+% This source file is hereby placed in the public domain.  -fjh (the author).
+
+:- module hello.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main --> io__write_string("Hello, world\n").
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/hello.exp	20 Jan 2003 12:19:55 -0000
@@ -0,0 +1 @@
+Hello, world
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/complex_test.m	20 Jan 2003 07:02:35 -0000
@@ -0,0 +1,78 @@
+% A test case for arithmetic on complex, imag, and float.
+
+:- module complex_test.
+:- interface.
+:- import_module io.
+
+:- pred main(state::di, state::uo) is det.
+
+:- implementation.
+:- import_module float.
+:- import_module complex_numbers.
+:- import_module complex_numbers:complex, complex_numbers:imag.
+:- import_module complex_numbers:complex_imag, complex_numbers:imag_complex.
+:- import_module complex_numbers:float_imag, complex_numbers:imag_float.
+
+main -->
+	print("tests of (complex op complex)"), nl,
+	{ X = 3.0 + 4.0 * i},
+	print("X = "), print(X), nl,
+	print("X + X = "), print(X + X), nl,
+	print("X - X = "), print(X - X), nl,
+	print("X * X = "), print(X * X), nl,
+	print("X / X = "), print(X / X), nl,
+	{ Y = - 5.0 + 6.0 * i},
+	print("Y = "), print(Y), nl,
+	print("Y + Y = "), print(Y + Y), nl,
+	print("Y - Y = "), print(Y - Y), nl,
+	print("Y * Y = "), print(Y * Y), nl,
+	print("Y / Y = "), print(Y / Y), nl,
+	print("X + Y = "), print(X + Y), nl,
+	print("X - Y = "), print(X - Y), nl,
+	print("X * Y = "), print(X * Y), nl,
+	print("X / Y = "), print(X / Y), nl,
+	nl,
+
+	print("tests of (imag op imag)"), nl,
+	{ Z = 4.0 * i},
+	print("Z = "), print(Z), nl,
+	print("Z + Z = "), print(Z + Z), nl,
+	print("Z - Z = "), print(Z - Z), nl,
+	print("Z * Z = "), print(Z * Z), nl,
+	print("Z / Z = "), print(Z / Z), nl,
+	nl,
+
+	print("tests of (float op imag)"), nl,
+	print("5.0 + Z = "), print(5.0 + Z), nl,
+	print("5.0 - Z = "), print(5.0 - Z), nl,
+	print("5.0 * Z = "), print(5.0 * Z), nl,
+	print("5.0 / Z = "), print(5.0 / Z), nl,
+	nl,
+
+	print("tests of (imag op float)"), nl,
+	print("Z + 5.0 = "), print(Z + 5.0), nl,
+	print("Z - 5.0 = "), print(Z - 5.0), nl,
+	print("Z * 5.0 = "), print(Z * 5.0), nl,
+	print("Z / 5.0 = "), print(Z / 5.0), nl,
+	nl,
+
+	print("tests of (complex op imag)"), nl,
+	print("X + Z = "), print(X + Z), nl,
+	print("X - Z = "), print(X - Z), nl,
+	print("X * Z = "), print(X * Z), nl,
+	print("X / Z = "), print(X / Z), nl,
+	print("Y + Z = "), print(Y + Z), nl,
+	print("Y - Z = "), print(Y - Z), nl,
+	print("Y * Z = "), print(Y * Z), nl,
+	print("Y / Z = "), print(Y / Z), nl,
+	nl,
+
+	print("tests of (imag op complex)"), nl,
+	print("Z + X = "), print(Z + X), nl,
+	print("Z - X = "), print(Z - X), nl,
+	print("Z * X = "), print(Z * X), nl,
+	print("Z / X = "), print(Z / X), nl,
+	print("Z + Y = "), print(Z + Y), nl,
+	print("Z - Y = "), print(Z - Y), nl,
+	print("Z * Y = "), print(Z * Y), nl,
+	print("Z / Y = "), print(Z / Y), nl.
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/complex_test.exp	20 Jan 2003 12:32:42 -0000
@@ -0,0 +1,54 @@
+tests of (complex op complex)
+X = cmplx(3.00000000000000, 4.00000000000000)
+X + X = cmplx(6.00000000000000, 8.00000000000000)
+X - X = cmplx(0.00000000000000, 0.00000000000000)
+X * X = cmplx(-7.00000000000000, 24.0000000000000)
+X / X = cmplx(1.00000000000000, 0.00000000000000)
+Y = cmplx(-5.00000000000000, 6.00000000000000)
+Y + Y = cmplx(-10.0000000000000, 12.0000000000000)
+Y - Y = cmplx(0.00000000000000, 0.00000000000000)
+Y * Y = cmplx(-11.0000000000000, -60.0000000000000)
+Y / Y = cmplx(1.00000000000000, 0.00000000000000)
+X + Y = cmplx(-2.00000000000000, 10.0000000000000)
+X - Y = cmplx(8.00000000000000, -2.00000000000000)
+X * Y = cmplx(-39.0000000000000, -2.00000000000000)
+X / Y = cmplx(0.14754098360655737, -0.6229508196721312)
+
+tests of (imag op imag)
+Z = im(4.00000000000000)
+Z + Z = im(8.00000000000000)
+Z - Z = im(0.00000000000000)
+Z * Z = -16.0000000000000
+Z / Z = 1.00000000000000
+
+tests of (float op imag)
+5.0 + Z = cmplx(5.00000000000000, 4.00000000000000)
+5.0 - Z = cmplx(5.00000000000000, -4.00000000000000)
+5.0 * Z = im(20.0000000000000)
+5.0 / Z = im(-1.25000000000000)
+
+tests of (imag op float)
+Z + 5.0 = cmplx(5.00000000000000, 4.00000000000000)
+Z - 5.0 = cmplx(-5.00000000000000, 4.00000000000000)
+Z * 5.0 = im(20.0000000000000)
+Z / 5.0 = im(0.800000000000000)
+
+tests of (complex op imag)
+X + Z = cmplx(3.00000000000000, 8.00000000000000)
+X - Z = cmplx(3.00000000000000, 0.00000000000000)
+X * Z = cmplx(-16.0000000000000, 12.0000000000000)
+X / Z = cmplx(1.00000000000000, -0.750000000000000)
+Y + Z = cmplx(-5.00000000000000, 10.0000000000000)
+Y - Z = cmplx(-5.00000000000000, 2.00000000000000)
+Y * Z = cmplx(-24.0000000000000, -20.0000000000000)
+Y / Z = cmplx(1.50000000000000, 1.25000000000000)
+
+tests of (imag op complex)
+Z + X = cmplx(3.00000000000000, 8.00000000000000)
+Z - X = cmplx(-3.00000000000000, 0.00000000000000)
+Z * X = cmplx(-16.0000000000000, 12.0000000000000)
+Z / X = cmplx(0.640000000000000, 0.480000000000000)
+Z + Y = cmplx(-5.00000000000000, 10.0000000000000)
+Z - Y = cmplx(5.00000000000000, -2.00000000000000)
+Z * Y = cmplx(-24.0000000000000, -20.0000000000000)
+Z / Y = cmplx(0.39344262295081966, -0.32786885245901637)
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/Mmakefile	22 Jan 2003 12:39:54 -0000
@@ -0,0 +1,41 @@
+#-----------------------------------------------------------------------------#
+
+THIS_DIR = mmc_make
+
+#-----------------------------------------------------------------------------#
+
+# Any program added here should also be added to the `.cvsignore' file.
+
+MMAKE_USE_MMC_MAKE=yes
+
+PROGS =	\
+		complex_test \
+		hello
+
+# These tests only work if the workspace was compiled with `--use-subdirs'.
+ifneq ($(origin WORKSPACE),undefined)
+    ifeq ($(shell [ -d $(WORKSPACE)/library/Mercury ] || echo cannot_run),cannot_run)
+	PROGS =
+    endif
+endif
+
+SUBDIRS=
+TESTS=$(PROGS)
+TESTS_DIR=..
+include $(TESTS_DIR)/Mmake.common
+
+%.runtest: %.res ;
+
+complex_test.log: install_libs
+
+.PHONY: install_libs
+install_libs: start_runtests_local
+	cd lib; \
+	$(MCM) --no-libgrade --install-prefix $(shell pwd)/install \
+			libcomplex_numbers.install
+
+realclean_local:
+	rm -rf install
+	cd lib; $(MCM) complex_numbers.realclean
+
+#-----------------------------------------------------------------------------#
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/mmc_make/Mercury.options	21 Jan 2003 23:57:36 -0000
@@ -0,0 +1,4 @@
+LIB_DIRS = install/lib/mercury
+LIBRARIES-complex_test = complex_numbers
+
+MCFLAGS-complex_test = --linkage shared
only in patch2:
--- tests/Mmakefile	18 Jan 2003 13:56:14 -0000	1.11
+++ tests/Mmakefile	20 Jan 2003 05:47:25 -0000
@@ -10,6 +10,7 @@
 	hard_coded \
 	invalid \
 	misc_tests \
+	mmc_make \
 	recompilation \
 	tabling \
 	term \
--------------------------------------------------------------------------
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