[m-rev.] for review: rewrite mercury_mcpp.cpp in C#

Peter Ross pro at missioncriticalit.com
Sun Oct 26 00:17:19 AEST 2003


Hi,


===================================================================


Estimated hours taken: 3
Branches: main

Replace mercury_mcpp.cpp with a version in C#.

This has two advantages
	* we can no longer compiler mercury_mcpp.cpp on v1.1 of the
	  framework with the downloadable version of the SDK, due to a
	  missing object file, nochkclr.obj.
	* not all .NET implementations provide a MC++ compiler, while
	  all provide a C# compiler.

runtime/mercury_mcpp.cs:
runtime/mercury_mcpp.cpp:
	Rewrite in C#.

library/io.m:
	s/MR_string_list_cons/MR_list_cons/ in the MC++.

runtime/Mmakefile:
	Add a line which causes the C# module to be built as a module,
	rather than the default of an assembly.


New File: runtime/mercury_mcpp.cs
===================================================================
//
// Copyright (C) 2003 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.
//

// mercury_mcpp.cs - This file defines the system runtime types and
// methods that are used when generating code for the .NET backend.

// vi: ts=4 sw=4 et tw=0 wm=0

namespace mercury {

namespace runtime {

public class SystemException : System.Exception
{
    public SystemException(string Msg) : base(Msg)
    {
		// the parent constructor sets the error message that
		// will be printed.
    }
}

public class Errors
{
    public static void SORRY(string s)
    {
        string msg;
        msg = System.String.Concat("Sorry, unimplemented: ", s);
        throw new mercury.runtime.SystemException(msg);
    }

    public static void fatal_error(string s)
    {
        string msg;
        msg = System.String.Concat("Fatal error: ", s);
        throw new mercury.runtime.SystemException(msg);
    }
}

public class Environment
{
}

public class Commit : System.Exception
{
}

public class Constants
{
    // These constants are duplicated in library/private_builtin.m.
    // They must be kept sychronized.

	// XXX it would be nice if these could be const or an enum.  But
	// there are some problems with accessing the values from IL if we do
	// that because neither alternatives seem to define field names we
	// can reference from IL.

    public static int MR_TYPECTOR_REP_ENUM 			= MR_TYPECTOR_REP_ENUM_val;
    public static int MR_TYPECTOR_REP_ENUM_USEREQ 	= MR_TYPECTOR_REP_ENUM_USEREQ_val;
    public static int MR_TYPECTOR_REP_DU			= MR_TYPECTOR_REP_DU_val;
    public static int MR_TYPECTOR_REP_DU_USEREQ		= 3;
    public static int MR_TYPECTOR_REP_NOTAG			= 4;
    public static int MR_TYPECTOR_REP_NOTAG_USEREQ	= 5;
    public static int MR_TYPECTOR_REP_EQUIV			= 6;
    public static int MR_TYPECTOR_REP_FUNC			= 7;
    public static int MR_TYPECTOR_REP_INT		   	= 8;
    public static int MR_TYPECTOR_REP_CHAR		   	= 9;
    public static int MR_TYPECTOR_REP_FLOAT			=10;
    public static int MR_TYPECTOR_REP_STRING		=11;
    public static int MR_TYPECTOR_REP_PRED		   	=12;
    public static int MR_TYPECTOR_REP_SUBGOAL	   	=13;
    public static int MR_TYPECTOR_REP_VOID		  	=14;
    public static int MR_TYPECTOR_REP_C_POINTER		=15;
    public static int MR_TYPECTOR_REP_TYPEINFO		=16;
    public static int MR_TYPECTOR_REP_TYPECLASSINFO	=17;
    public static int MR_TYPECTOR_REP_ARRAY			=18;
    public static int MR_TYPECTOR_REP_SUCCIP		=19;
    public static int MR_TYPECTOR_REP_HP			=20;
    public static int MR_TYPECTOR_REP_CURFR			=21;
    public static int MR_TYPECTOR_REP_MAXFR			=22;
    public static int MR_TYPECTOR_REP_REDOFR		=23;
    public static int MR_TYPECTOR_REP_REDOIP		=24;
    public static int MR_TYPECTOR_REP_TRAIL_PTR		=25;
    public static int MR_TYPECTOR_REP_TICKET		=26;
    public static int MR_TYPECTOR_REP_NOTAG_GROUND	=27;
    public static int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ	=28;
    public static int MR_TYPECTOR_REP_EQUIV_GROUND	=29;
    public static int MR_TYPECTOR_REP_TUPLE			=30;
    public static int MR_TYPECTOR_REP_RESERVED_ADDR	=31;
    public static int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ	=32;
    public static int MR_TYPECTOR_REP_TYPECTORINFO	        =33;
    public static int MR_TYPECTOR_REP_BASETYPECLASSINFO     =34;
    public static int MR_TYPECTOR_REP_TYPEDESC	        	=35;
    public static int MR_TYPECTOR_REP_TYPECTORDESC	        =36;
    public static int MR_TYPECTOR_REP_FOREIGN			    =37;
    public static int MR_TYPECTOR_REP_REFERENCE		        =38;
    public static int MR_TYPECTOR_REP_STABLE_C_POINTER	    =39;
    public static int MR_TYPECTOR_REP_UNKNOWN		        =40;

    public static int MR_SECTAG_NONE				= 0;
    public static int MR_SECTAG_LOCAL				= 1;
    public static int MR_SECTAG_REMOTE				= 2;
}

}
}

Removed file: runtime/mercury_mcpp.cpp
===================================================================
//
// Copyright (C) 2000-2003 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.
//

// mercury_mcpp.cpp - This file defines the system runtime types and
// methods that are used when generating code for the .NET backend.
// It is written using Microsoft's Managed Extensions for C++ (usually
// called Managed C++ or MC++).

// vi: ts=4 sw=4 et tw=0 wm=0

#using <mscorlib.dll>
#using "mercury_il.dll"

#include "mercury_mcpp.h"

namespace mercury {

namespace runtime {

__gc public class SystemException : public System::Exception
{
public:
	SystemException(MR_String Msg) : System::Exception(Msg)
	{	
		// the parent constructor sets the error message that
		// will be printed.
	}
};


__gc public class LowLevelData
{

public:
	// Make a Mercury enumeration with the given integer value.
static MR_Word make_enum(int enum_value) {

	MR_Word e;
	MR_newenum(e, enum_value);
	return e;

}

	// Make an MR_Word with the given tag and arity.
static MR_Word make_MR_Word(int tag, int arity) {
	MR_Word e;
	MR_newobj(e, tag, arity);
	return e;

}
	// Set a field of an MR_Word with a given value.
	// The first field is at index 1.
static void set_MR_Word_field(MR_Word w, int index, System::Object *value) {
	MR_objset(w, index, value);
}
	// Get the value from an MR_Word.
	// The first field is at index 1.
static System::Object * get_MR_Word_field(MR_Word w, int index) {
	return w[index];
}

static bool list_is_cons(MR_Word w) {
	return (System::Convert::ToInt32(w[0]) != 0);
}

static MR_Box list_get_head(MR_Word w) {
	return w[1];
}

static MR_Word list_get_tail(MR_Word w) {
	return dynamic_cast<MR_Word>(w[2]);
}

};

__gc public class Errors {
    public:
    static void SORRY(MR_String s) 
    {
        MR_String msg;
        msg = System::String::Concat(S"Sorry, unimplemented: ", s);
        throw new mercury::runtime::SystemException(msg);
    }

    static void fatal_error(MR_String s)
    {
        MR_String msg;
        msg = System::String::Concat(S"Fatal error: ", s);
        throw new mercury::runtime::SystemException(msg);
    }
};


__gc public class Constants {
    public:

        // These constants are duplicated in library/private_builtin.m.
        // They must be kept sychronized.

	// XXX it would be nice if these could be const or an enum.  But
	// there are some problems with accessing the values from IL if we do
	// that because neither alternatives seem to define field names we
	// can reference from IL.

    static int MR_TYPECTOR_REP_ENUM 			= MR_TYPECTOR_REP_ENUM_val;
    static int MR_TYPECTOR_REP_ENUM_USEREQ 		= MR_TYPECTOR_REP_ENUM_USEREQ_val;
    static int MR_TYPECTOR_REP_DU			= MR_TYPECTOR_REP_DU_val;
    static int MR_TYPECTOR_REP_DU_USEREQ		= 3;
    static int MR_TYPECTOR_REP_NOTAG			= 4;
    static int MR_TYPECTOR_REP_NOTAG_USEREQ		= 5;
    static int MR_TYPECTOR_REP_EQUIV			= 6;
    static int MR_TYPECTOR_REP_FUNC			= 7;
    static int MR_TYPECTOR_REP_INT		    	= 8;
    static int MR_TYPECTOR_REP_CHAR		    	= 9;
    static int MR_TYPECTOR_REP_FLOAT			=10;
    static int MR_TYPECTOR_REP_STRING			=11;
    static int MR_TYPECTOR_REP_PRED		    	=12;
    static int MR_TYPECTOR_REP_SUBGOAL		    	=13;
    static int MR_TYPECTOR_REP_VOID		    	=14;
    static int MR_TYPECTOR_REP_C_POINTER		=15;
    static int MR_TYPECTOR_REP_TYPEINFO			=16;
    static int MR_TYPECTOR_REP_TYPECLASSINFO		=17;
    static int MR_TYPECTOR_REP_ARRAY			=18;
    static int MR_TYPECTOR_REP_SUCCIP			=19;
    static int MR_TYPECTOR_REP_HP			=20;
    static int MR_TYPECTOR_REP_CURFR			=21;
    static int MR_TYPECTOR_REP_MAXFR			=22;
    static int MR_TYPECTOR_REP_REDOFR			=23;
    static int MR_TYPECTOR_REP_REDOIP			=24;
    static int MR_TYPECTOR_REP_TRAIL_PTR		=25;
    static int MR_TYPECTOR_REP_TICKET			=26;
    static int MR_TYPECTOR_REP_NOTAG_GROUND		=27;
    static int MR_TYPECTOR_REP_NOTAG_GROUND_USEREQ	=28;
    static int MR_TYPECTOR_REP_EQUIV_GROUND		=29;
    static int MR_TYPECTOR_REP_TUPLE			=30;
    static int MR_TYPECTOR_REP_RESERVED_ADDR		=31;
    static int MR_TYPECTOR_REP_RESERVED_ADDR_USEREQ	=32;
    static int MR_TYPECTOR_REP_TYPECTORINFO	        =33;
    static int MR_TYPECTOR_REP_BASETYPECLASSINFO        =34;
    static int MR_TYPECTOR_REP_TYPEDESC	        	=35;
    static int MR_TYPECTOR_REP_TYPECTORDESC	        =36;
    static int MR_TYPECTOR_REP_FOREIGN			=37;
    static int MR_TYPECTOR_REP_REFERENCE		=38;
    static int MR_TYPECTOR_REP_STABLE_C_POINTER	        =39;
    static int MR_TYPECTOR_REP_UNKNOWN		        =40;

    static int MR_SECTAG_NONE				= 0;
    static int MR_SECTAG_LOCAL				= 1;
    static int MR_SECTAG_REMOTE				= 2;
};

__gc public class Environment
{
public:
};

__gc public class Commit : public System::Exception
{
public:
};

}

}


Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.307
diff -u -r1.307 io.m
--- library/io.m	20 Oct 2003 07:29:27 -0000	1.307
+++ library/io.m	25 Oct 2003 14:10:38 -0000
@@ -6401,7 +6401,7 @@
 	MR_list_nil(Args);
 		// We don't get the 0th argument: it is the executable name
 	while (--i > 0) {
-		MR_string_list_cons(Args, arg_vector[i], Args);
+		MR_list_cons(Args, arg_vector[i], Args);
 	}
 	MR_update_io(IO0, IO);
 ").
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.105
diff -u -r1.105 Mmakefile
--- runtime/Mmakefile	23 Oct 2003 02:02:31 -0000	1.105
+++ runtime/Mmakefile	25 Oct 2003 14:10:39 -0000
@@ -286,6 +286,7 @@
 # assembly of their own.  We put the runtime and library dlls into a single
 # assembly called `mercury'
 MS_CL_NOASM=:noAssembly
+MS_CSCFLAGS=/t:module
 
 # We need to build the following DLLs for the .NET runtime
 DOTNET_DLLS=mercury_il.dll mercury_mcpp.dll


-- 
Peter Ross		
Software Engineer                                (Work)   +32 2 757 10 15
Mission Critical                                 (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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