[m-rev.] diff: .NET back-end fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 13 19:28:29 AEDT 2003


Estimated hours taken: 20
Branches: main

Various bug fixes for the `il' grade.
These get us closer to bootstrapping on .NET.

Mmake.workspace:
	Set MERC_C_INCL_DIR and MERC_DLL_DIR, since these are needed
	when building in grade `il'.

library/Mmakefile:
	Fix the dependencies for `mercury.dll' to avoid relinking it
	every time `mmake' gets invoked.

library/io.m:
	- Implement io__rename_file in C#.
	- Change io__file_modification_time so that on .NET it returns
	  an error rather than throwing an exception.
	- Fix some bugs in the MC++ code for mercury_getchar():
	  - add a missing "break" statement
	  - update the line count correctly when reading a character
	    after it has been put back by io__putback_char.
	  - compute line numbers correctly even for text files formatted
	    differently than the environment expects, e.g. those that use
	    Unix-style bare LF rather than Windows-style CR-LF.

trace/Mmakefile:
	Ensure that in `il' grade we don't build anything in this directory.

compiler/Mmakefile:
	Conditionalize some dependencies that were bogus for the `il' grade.
	Add a work-around for the lack of Mmake support for
	`--transitive-intermodule-optimization'.

compiler/bytecode_data.m:
	Provide Mercury clauses (that just call sorry/1) as an alternative
	to C foreign_proc code for `float_to_float64_bytes'.

compiler/process_util.m:
	Fix a mode error and a missing import that only showed up in `il'
	grade, since they occured in Mercury clauses which are only used
	on back-ends which don't support the C interface.

Workspace: /home/fjh/ws/hermes
Index: Mmake.workspace
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.workspace,v
retrieving revision 1.11
diff -u -d -r1.11 Mmake.workspace
--- Mmake.workspace	5 Feb 2003 14:41:05 -0000	1.11
+++ Mmake.workspace	13 Feb 2003 08:26:37 -0000
@@ -126,6 +126,12 @@
 MCFLAGS +=	$(C_INCL_DIRS:-I%=--c-include-directory %)
 
 #
+# Work out the .NET directories
+#
+MERC_C_INCL_DIR = $(RUNTIME_DIR)
+MERC_DLL_DIR = $(LIBRARY_DIR)
+
+#
 # Work out which libraries to link with.
 # The $(shell) here is needed to allow the variable values in
 # ECHO_MERCURY_OPTIONS in Mmake.vars to be single-quoted when
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.65
diff -u -d -r1.65 Mmakefile
--- compiler/Mmakefile	5 Feb 2003 14:41:11 -0000	1.65
+++ compiler/Mmakefile	13 Feb 2003 08:26:37 -0000
@@ -219,21 +219,27 @@
 .PHONY: cs
 cs: 		mlds_to_gcc.c gcc.c
 
+
 #-----------------------------------------------------------------------------#
 
 # Add some additional dependencies, so that Mmake knows to remake the
 # compiler if one of the libraries changes.
 
+ifeq ($(findstring il,$(GRADE)),il)        
+# This line works around an Mmake bug: mmake doesn't record
+# dependencies properly with --transitive-intermodule-optimization
+%.il: opts
+else
 $(MC_PROG): ../main.$O
 $(MC_PROG): $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
 $(MC_PROG): $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
 $(MC_PROG): $(BROWSER_DIR)/lib$(BROWSER_LIB_NAME).$A
 $(MC_PROG): $(TRACE_DIR)/lib$(TRACE_LIB_NAME).$A
 $(MC_PROG): $(ANALYSIS_DIR)/lib$(ANALYSIS_LIB_NAME).$A
-# Should also depend on $(BOEHM_GC_DIR)/libgc(_prof).$A, but only
-# if in .gc(.prof) grade; GNU make does not support dynamic dependencies,
-# so just leave it out.
+# XXX should also depend on $(BOEHM_GC_DIR)/libgc(_prof).$A, but only
+# if in .gc(.prof) grade
 $(MC_PROG): $(GCC_MAIN_LIBS)
+endif
 
 $(MC_PROG)_init.c: $(UTIL_DIR)/mkinit
 
@@ -268,10 +274,12 @@
 os: $($(MC_PROG).os)
 cs: $($(MC_PROG).cs)
 ss: $($(MC_PROG).ss)
+opts: $($(MC_PROG).opts)
 else
 os: $(MC_PROG).os
 cs: $(MC_PROG).cs
 ss: $(MC_PROG).ss
+opts: $(MC_PROG).opts
 endif
 
 #-----------------------------------------------------------------------------#
Index: compiler/bytecode_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_data.m,v
retrieving revision 1.9
diff -u -d -r1.9 bytecode_data.m
--- compiler/bytecode_data.m	10 Jan 2003 05:12:19 -0000	1.9
+++ compiler/bytecode_data.m	13 Feb 2003 08:26:37 -0000
@@ -80,6 +80,7 @@
 
 :- implementation.
 
+:- import_module hlds.error_util.
 :- import_module char, require.
 
 output_string(Val) -->
@@ -289,6 +290,12 @@
 	
 	"
 ).
+float_to_float64_bytes(_FloatVal, _B0, _B1, _B2, _B3, _B4, _B5, _B6, _B7) :-
+	sorry(this_file, "float_to_float64_bytes for non-C target").
 
-%---------------------------------------------------------------------------%
+:- func this_file = string.
+this_file = "bytecode_data.m".
+
+:- end_module bytecode_data.
 
+%---------------------------------------------------------------------------%
Index: compiler/process_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/process_util.m,v
retrieving revision 1.7
diff -u -d -r1.7 process_util.m
--- compiler/process_util.m	22 Nov 2002 08:50:59 -0000	1.7
+++ compiler/process_util.m	13 Feb 2003 08:26:37 -0000
@@ -73,7 +73,7 @@
 :- implementation.
 
 :- import_module libs__globals, libs__options.
-:- import_module std_util.
+:- import_module std_util, require.
 
 build_with_check_for_interrupt(Build, Cleanup, Succeeded, Info0, Info) -->
 	setup_signal_handlers(MaybeSigIntHandler),
@@ -225,7 +225,7 @@
 :- pred check_for_signal(int::out, int::out,
 		io__state::di, io__state::uo) is det.
 
-check_for_signal(0::out, 0::out, _::di, _::uo).
+check_for_signal(0::out, 0::out, IO::di, IO::uo).
 
 :- pragma foreign_proc("C",
 	check_for_signal(Signalled::out, Signal::out, IO0::di, IO::uo),
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.105
diff -u -d -r1.105 Mmakefile
--- library/Mmakefile	5 Feb 2003 14:41:19 -0000	1.105
+++ library/Mmakefile	13 Feb 2003 08:26:37 -0000
@@ -222,7 +222,8 @@
 library_strong_name.sn:
 	sn -k library_strong_name.sn
 
-mercury.dll: copy_runtime_dlls lib$(STD_LIB_NAME) library_strong_name.sn
+mercury.dll: $($(STD_LIB_NAME).dlls) $($(STD_LIB_NAME).foreign_dlls) \
+		$(RUNTIME_DLLS) library_strong_name.sn
 	$(MS_AL) -v:0.0.0.0 -keyf:library_strong_name.sn -out:mercury.dll \
 		$($(STD_LIB_NAME).dlls) $($(STD_LIB_NAME).foreign_dlls) \
 		$(RUNTIME_DLLS) 
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.287
diff -u -d -r1.287 io.m
--- library/io.m	20 Jan 2003 12:23:08 -0000	1.287
+++ library/io.m	13 Feb 2003 08:26:37 -0000
@@ -2096,10 +2096,14 @@
 
 }").
 
-io__file_modification_time_2(_, _, _, _) -->
+io__file_modification_time_2(_FileName, Status, Msg, Time) -->
 	% This version is only used for back-ends for which there is no
 	% matching foreign_proc version.
-	{ private_builtin__sorry("io__file_modification_time_2") }.
+	{ Status = 0 },
+	{ Msg = "io__file_modification_time not implemented for this target "
+		++ "(or compiler back-end)" },
+	% This value will not be used
+	{ Time = rtti_implementation.unsafe_cast(0) }.
 
 %-----------------------------------------------------------------------------%
 
@@ -4044,6 +4048,9 @@
 	if (mf->putback != -1) {
 		c = mf->putback;
 		mf->putback = -1;
+		if (c == '\\n') {
+			mf->line_number++;
+		}
 		return c;
 	}
 
@@ -4065,11 +4072,23 @@
 		// System::Environment::NewLine.
 		// We assume that System::Environment::NewLine is non-null
 		// and that System::Environment::NewLine->Length > 0.
-		if (c == System::Environment::NewLine->get_Chars(0)) {
+		if (c != System::Environment::NewLine->get_Chars(0)) {
+			if (c == '\\n') {
+				// the input file was ill-formed,
+				// e.g. it contained only raw
+				// LFs rather than CR-LF.
+				// Perhaps we should throw an exception?
+				// If not, we still need to treat
+				// this as a newline, and thus
+				// increment the line counter.
+				mf->line_number++;
+			}
+		} else /* c == NewLine->get_Chars(0) */ {
 			switch (System::Environment::NewLine->Length) {
 			case 1:
 				mf->line_number++;
 				c = '\\n';
+				break;
 			case 2:
 				if (mf->reader->Peek() == System::
 					Environment::NewLine->get_Chars(1))
@@ -4077,6 +4096,15 @@
 					(void) mf->reader->Read();
 					mf->line_number++;
 					c = '\\n';
+				} else if (c == '\\n') {
+					// the input file was ill-formed,
+					// e.g. it contained only raw
+					// CRs rather than CR-LF. Perhaps
+					// we should throw an exception?
+					// If not, we still need to treat
+					// this as a newline, and thus
+					// increment the line counter.
+					mf->line_number++;
 				}
 				break;
 			default:
@@ -6119,6 +6147,28 @@
 	ML_maybe_make_err_msg(RetVal != 0, ""rename failed: "",
 		MR_PROC_LABEL, RetStr);
 	MR_update_io(IO0, IO);
+}").
+
+:- pragma foreign_proc("C#",
+	io__rename_file_2(OldFileName::in, NewFileName::in,
+			RetVal::out, RetStr::out, _IO0::di, _IO::uo),
+		[will_not_call_mercury, promise_pure, tabled_for_io,
+			thread_safe],
+"{
+	try {
+		if (System.IO.File.Exists(OldFileName)) {
+			System.IO.File.Move(OldFileName, NewFileName);
+			RetVal = 0;
+			RetStr = """";
+		} else {
+			RetVal = -1;
+			RetStr = ""rename failed: No such file or directory"";
+		}
+	}
+	catch (System.Exception e) {
+		RetVal = -1;
+		RetStr = e.Message;
+	}
 }").
 
 io__rename_file_2(_, _, _, _) -->
Index: trace/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/Mmakefile,v
retrieving revision 1.36
diff -u -d -r1.36 Mmakefile
--- trace/Mmakefile	18 Oct 2002 04:16:18 -0000	1.36
+++ trace/Mmakefile	13 Feb 2003 08:26:37 -0000
@@ -125,8 +125,13 @@
 #-----------------------------------------------------------------------------#
 
 .PHONY: trace
+ifeq ($(findstring il,$(GRADE)),il)        
+# there is no tracing in the .NET backend
+trace:
+else
 trace: lib$(TRACE_LIB_NAME).$A lib$(TRACE_LIB_NAME).$(EXT_FOR_SHARED_LIB)
 trace: $(LIB_DLL_H) $(LIB_GLOBALS_H)
+endif
 
 lib$(TRACE_LIB_NAME)$(DLL_DEF_LIB).$A: $(OBJS)
 	rm -f lib$(TRACE_LIB_NAME)$(DLL_DEF_LIB).$A

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