[m-rev.] diff: .NET backend runtime and library fixes

Peter Ross peter.ross at miscrit.be
Thu May 3 00:13:46 AEST 2001


On Wed, May 02, 2001 at 11:36:43PM +1000, Tyson Dowd wrote:
> Hi,
> 
> Here are a bunch of changes for the .NET backend.  Most of my outstanding
> runtime and library patches are in this change.  This breaks
> compatibility with Beta 1.
> 
> Pete is waiting on these changes, so perhaps he can review them too.
> 
> ===================================================================
> 
> 
> Estimated hours taken: 5
> Branches: main
> 
> Updates to the runtime and library for .NET backend.
> 
> These changes mean the runtime and library will no longer work for Beta 1.
> If you want to use Beta 1, you will have to use mercury 0.10.x.
> 
> library/.cvsignore:
> 	Add .cpp .dll and .il files.
> 
> runtime/.cvsignore:
> 	Add .dll files.
> 
> library/Mmakefile:
> 	Add an assembly search patch to the MS_CLFLAGS
> 	Work around bugs in the assembly cache installer by generating one
> 	big .il file for the library.
> 	Generate a strong name file and use it.
> 	
> library/array.m:
> 	Update the code to work correctly -- the MC++ compiler is now a bit
> 	stricter about type casts.
> 
> library/exception.m:
> 	Stop using an enum and use #defines -- the enum has stopped working.
> 	(I don't have time to figure out why just now).
> 
> library/float.m:
> library/math.m:
> 	Some of the mathematical functions have changed names.
> 
> library/io.m:
> 	Use an ascii encoder to generate ASCII output by default.
> 	Without this we get Unicode UTF output, and it seems to like to
> 	insert a BOM (byte-order-mark) which means Hello World doesn't work
> 	anymore.
> 
> runtime/mercury_il.il:
> 	Insert .publickeytoken to identify the mercury assembly and mscorlib.
> 	Add ['mscorlib'] assembly refs to System.Object and ['mercury'] for
> 	mercury code.
> 	Use box and unbox instructions instead of our hand-hacked boxing
> 	classes.  Remove the old conversion classes.
> 	Add a missing return to mercury.Init::init_runtime()
> 
> runtime/mercury_mcpp.cpp:
> 	Minor fix: s/Exception/System.Exception/
> 
> runtime/mercury_mcpp.h:
> 	Fix the definition of MR_Array.
> 	Use array syntax for macros that manipulate arrays.
> 
> 

> Index: library/exception.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/exception.m,v
> retrieving revision 1.45
> diff -u -r1.45 exception.m
> --- library/exception.m	2001/03/15 07:42:21	1.45
> +++ library/exception.m	2001/05/02 13:28:23
> @@ -304,21 +304,15 @@
>  #ifndef ML_DETERMINISM_GUARD
>  #define ML_DETERMINISM_GUARD
>  
> -	/*
> -	** The enumeration constants in this enum must be in the same
> -	** order as the functors in the Mercury type `determinism'
> -	** defined above.
> -	*/
> -	typedef enum {
> -		ML_DET,
> -		ML_SEMIDET,
> -		ML_CC_MULTI,
> -		ML_CC_NONDET,
> -		ML_MULTI,
> -		ML_NONDET,
> -		ML_ERRONEOUS,
> -		ML_FAILURE
> -	} ML_Determinism;
> +#define ML_DET	0
> +#define	ML_SEMIDET	1
> +#define	ML_CC_MULTI	2
> +#define	ML_CC_NONDET	3
> +#define	ML_MULTI	4
> +#define	ML_NONDET	5
> +#define	ML_ERRONEOUS	6
> +#define	ML_FAILURE	7
> +
>  #endif
>  ").
>  
Don't delete the comment, reword it.

> Index: library/io.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/io.m,v
> retrieving revision 1.223
> diff -u -r1.223 io.m
> --- library/io.m	2001/04/08 08:59:30	1.223
> +++ library/io.m	2001/05/02 13:28:27
> @@ -1135,6 +1135,7 @@
>  	static MR_Word		ML_io_stream_names;
>  	static MR_Word		ML_io_user_globals;
>  	static int next_id;
> +	static System::Text::ASCIIEncoding *ascii_encoder;
>  ").
>  
>  
> @@ -2829,8 +2830,23 @@
>  		io__gc_init(_StreamNamesType::in, _UserGlobalsType::in,
>  		IO0::di, IO::uo), will_not_call_mercury, "
>  	update_io(IO0, IO);
> +	ascii_encoder =	new System::Text::ASCIIEncoding();
>  ").
>  
> +:- pred io__stream_init(io__state, io__state).
> +:- mode io__stream_init(di, uo) is det.
> +
> +:- pragma foreign_proc("MC++", 
> +		io__stream_init(IO0::di, IO::uo), will_not_call_mercury, "
> +	ascii_encoder =	new System::Text::ASCIIEncoding();
> +	update_io(IO0, IO);
> +").
> +
> +:- pragma foreign_proc("C", 
> +		io__stream_init(IO0::di, IO::uo), will_not_call_mercury, "
> +	update_io(IO0, IO);
> +").
> +
>  :- pred io__insert_std_stream_names(io__state, io__state).
>  :- mode io__insert_std_stream_names(di, uo) is det.
>  
> @@ -2956,12 +2972,13 @@
>  
>  :- pragma foreign_decl("MC++", "
>  
> -	// XXX for efficiency we should re-use the same stream writer
> -	// on a stream, perhaps we should store it with a stream.
> +	// XXX currently we only handle text streams.
>  
>  __gc struct MR_MercuryFileStruct {
>  public:
>  	System::IO::Stream 	*stream;
> +	System::IO::TextReader 	*reader;
> +	System::IO::TextWriter 	*writer;
>  	int		line_number;
>  	int		id;
>  };

Where are these reader and writer things?

> @@ -3036,20 +3053,37 @@
>  		int line_number) {
>  	MR_MercuryFile mf = new MR_MercuryFileStruct();
>  	mf->stream = stream;
> +	mf->reader = NULL;
> +	mf->writer = NULL;
>  	mf->line_number = line_number;
>  	mf->id = next_id++;
>  	return mf;
>  }
>  
> +static MR_MercuryFile new_open_mercury_file(System::IO::Stream *stream,
> +		System::IO::TextReader *reader, System::IO::TextWriter *writer,
> +		int line_number) {
> +	MR_MercuryFile mf = new MR_MercuryFileStruct();
> +	mf->stream = stream;
> +	mf->reader = reader;
> +	mf->writer = writer;
> +	mf->line_number = line_number;
> +	mf->id = next_id++;
> +	return mf;
> +}
> +
>  	// XXX this will cause problems with GUI programs that have no
>  	// consoles.
>  
>  static MR_MercuryFile mercury_stdin =
> -	new_mercury_file(System::Console::OpenStandardInput(), 1);
> +	new_open_mercury_file(System::Console::OpenStandardInput(),
> +		System::Console::In, NULL, 1);
>  static MR_MercuryFile mercury_stdout =
> -	new_mercury_file(System::Console::OpenStandardOutput(), 1);
> +	new_open_mercury_file(System::Console::OpenStandardOutput(),
> +		NULL, System::Console::Out, 1);
>  static MR_MercuryFile mercury_stderr =
> -	new_mercury_file(System::Console::OpenStandardError(), 1);
> +	new_open_mercury_file(System::Console::OpenStandardError(),
> +		NULL, System::Console::Error, 1);
>  
>  static MR_MercuryFile mercury_stdin_binary =
>  	new_mercury_file(0, 1);
> @@ -3060,9 +3094,11 @@
>  	// use the mercury_files above.
>  
>  static MR_MercuryFile mercury_current_text_input =
> -	new_mercury_file(System::Console::OpenStandardInput(), 1);
> +	new_open_mercury_file(System::Console::OpenStandardInput(),
> +		System::Console::In, NULL, 1);
>  static MR_MercuryFile mercury_current_text_output =
> -	new_mercury_file(System::Console::OpenStandardOutput(), 1);
> +	new_open_mercury_file(System::Console::OpenStandardOutput(),
> +		NULL, System::Console::Out, 1);
>  static MR_MercuryFile mercury_current_binary_input =
>          new_mercury_file(0, 1);
>  static MR_MercuryFile mercury_current_binary_output =
> @@ -3184,10 +3220,10 @@
>  static void
>  mercury_print_string(MR_MercuryFile mf, MR_String s)
>  {
> -	// XXX we should re-use the same stream writer...
> -        System::IO::StreamWriter *w = new System::IO::StreamWriter(mf->stream);
> -        w->Write(s);
> -        w->Flush();
> +	unsigned char ByteArray __gc[] = ascii_encoder->GetBytes(s);
> +	mf->stream->Write(ByteArray, 0, ByteArray->get_Length());
> +	mf->stream->Flush();
> +
>          for (int i = 0; i < s->Length; i++) {
>                  if (s->Chars[i] == '\\n') {
>                          mf->line_number++;
> Index: library/library_strong_name.sn
> ===================================================================
> RCS file: library_strong_name.sn
> diff -N library_strong_name.sn
> Binary files /dev/null and library_strong_name.sn differ

Mention this new file in the log message.

Apart from the above little issues this change looks fine.

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