Skip to content

Commit

Permalink
Make it possible to install and use the csharp.ssdebug grade.
Browse files Browse the repository at this point in the history
Branches: main

Make it possible to install and use the csharp.ssdebug grade.

Mmake.workspace:
        Never try to link with `mer_rt' in C# grades.

browser/Mmakefile:
mdbcomp/Mmakefile:
ssdb/Mmakefile:
        Use `mmc --make' to install these libraries in `csharp' grades.

        Don't add C libraries to MLLIBS in non-C or asm grades.

browser/Mercury.options:
ssdb/Mercury.options:
        "EXTRA_LIBRARIES-libname" doesn't actually work with `mmc --make',
        but "LIBRARIES-name" does.

library/exception.m:
ssdb/ssdb.m:
        Handle EXCP events in C# grades.

        Trap SIGINT when running ssdb in C# grades.

        Add `exit_process' implementation.

browser/declarative_execution.m:
browser/listing.m:
        Add stubs for C#.

README.CSharp:
        Document the C# backend.

README.DotNet:
        Add a pointer to README.CSharp.

README.Erlang:
README.Java:
        Remove a non-sensical paragraph.

.INSTALL.in:
configure.in:
        Add `--enable-csharp-grade' option.

        Make `configure --enable-ssdebug-grades' add `csharp.ssdebug'
        to the list of library grades.
  • Loading branch information
wangp committed Oct 26, 2010
1 parent 97cd495 commit 91b78d6
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 36 deletions.
1 change: 1 addition & 0 deletions .nocopyright
Expand Up @@ -34,3 +34,4 @@ README.MS-Windows
README.OSF1
README.Solaris
README.ssdebug
README.CSharp
7 changes: 6 additions & 1 deletion Mmake.workspace
@@ -1,5 +1,5 @@
#-----------------------------------------------------------------------------#
# Copyright (C) 2002-2008 The University of Melbourne.
# Copyright (C) 2002-2008, 2010 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
Expand Down Expand Up @@ -211,7 +211,12 @@ LINK_RT_LIB_OPTS=
LINK_STD_LIB_OPTS=
LINK_TRACE_SSDB_LIB_OPTS=
ifneq ($(LINK_BOEHM_GC_ONLY),yes)
ifneq ("$(filter csharp%,$(GRADE))","")
# There is no separate runtime library for C# grades.
LINK_RT_LIB_OPTS =
else
LINK_RT_LIB_OPTS = -l$(RT_LIB_NAME)
endif
ifneq ($(LINK_RUNTIME_ONLY),yes)
LINK_STD_LIB_OPTS = -l$(STD_LIB_NAME)
ifneq ($(LINK_STDLIB_ONLY),yes)
Expand Down
124 changes: 124 additions & 0 deletions README.CSharp
@@ -0,0 +1,124 @@
-----------------------------------------------------------------------------

INTRODUCTION

This release of Mercury contains a port to the ECMA Common Language
Infrastructure (CLI), i.e. Microsoft .NET or Mono. The Mercury
compiler will generate C# source code that can be compiled into
bytecode suitable for running on the .NET or Mono runtime systems.

The port is mostly complete, but some parts of the Mercury standard
library are not yet implemented (for a full list see the FAQ below).

The port is currently targeted at C# 2.0 or higher.

NOTE: a previous backend also targetted the .NET runtime, by generating IL
(Intermediate Language), rather than going via C#. That backend is
out-of-date and may be removed in the future.

PREREQUISITES

In order to try this system you will need

- Either Microsoft.NET or Mono 2.8 or above.

WARNING

Please note that the C# backend is still an experimental feature.

-----------------------------------------------------------------------------

THE C# GRADE

The Mercury compiler currently supports the grade `csharp'.
The csharp grade is enabled by using any of the options
`--grade csharp', `--target csharp', or just `--csharp'.

To run a Mercury program using the csharp grade, you need to build the Mercury
library and runtime in the csharp grade, using the Mercury source distribution.

You can now build programs such as hello.m or calculator.m in the samples
directory.

cd samples
mmc --make --csharp hello

Now you can run hello

./hello

-----------------------------------------------------------------------------

USING C#

The Mercury standard library has not been fully ported to C# yet.
The use of unimplemented procedures will result in a run-time error,
with a message such as "Sorry, not implemented: foreign code for this
function", and a stack trace.

If you find missing functionality, you can interface to C# using Mercury's
foreign language interface.

For example:

:- pred to_string(T::in, string::out) is det.
:- pragma foreign_proc("C#", to_string(T::in, Str::out), [],
"
Str = T.ToString();
").

The implementation will include this C# code in the module's .cs file, and
you can then call the predicate to_string exactly the same as if it were
implemented using pure Mercury code.

For more information about the foreign language interface, see the Mercury
Language Reference Manual, which you can find at:

<http://www.mercury.csse.unimelb.edu.au/information/documentation.html>

-----------------------------------------------------------------------------

FREQUENTLY ASKED QUESTIONS (FAQS)

Q. What are the advantages of using the C# back-end?

A. The main advantage is easy access to the wide range of libraries for the
.NET platform, and the portability you get from using CIL bytecode.


Q. What features are not yet implemented for the C# back-end?

A. The following implementation features are not supported:

Mercury-level debugging (but see next question)
Mercury-level profiling
trailing
tabling

In addition, the following individual procedures are incompletely
implemented:

io.read_binary/{3,4}:
io.write_binary/{3,4}:
io.read_binary is broken.

benchmarking.report_stats/0:
benchmarking.report_full_memory_stats/0:
Memory usage statistics are not yet available, and cpu time
is not the same as in the C backends, as per time.m.

store.arg_ref/5:
store.new_arg_ref/5:
Due to the absence of RTTI, dynamic type checking is missing
for these predicates. They should be used with care.

This list is not complete.


Q. How do I debug Mercury programs on .NET?

A. The only Mercury-level debugger available for C# grades is the
source-to-source debugger; see README.ssdebug.


-----------------------------------------------------------------------------
5 changes: 5 additions & 0 deletions README.DotNet
@@ -1,5 +1,10 @@
-----------------------------------------------------------------------------

WARNING

The .NET backend described herein is out-of-date and may be removed in
the future. See README.Charp for details of a newer backend that targets .NET.

INTRODUCTION

This release of Mercury contains a port to the Microsoft.NET Common
Expand Down
10 changes: 0 additions & 10 deletions README.Erlang
Expand Up @@ -19,16 +19,6 @@ In order to try this system you will need
downloaded from
<http://www.erlang.org/download.html>

- The Mercury source distribution. See below for installation
instructions.

If you're reading this file from somewhere other than the
Mercury distribution, try the Mercury homepage at
<http://www.mercury.csse.unimelb.edu.au>

- An installed Mercury compiler. You must use `mmc --make' to
install the standard library for Erlang. See below.

- A Unix-like environment. The Erlang support has not been
tested on Windows, but you will need a shell script
interpreter.
Expand Down
7 changes: 0 additions & 7 deletions README.Java
Expand Up @@ -21,13 +21,6 @@ In order to try this system you will need

OR any other compatible Java implementation.

- The Mercury distribution -- installed as usual. You can install
from either the source or binary distribution.

If you're reading this file from somewhere other than the
Mercury distribution, try the Mercury homepage at
<http://www.mercury.csse.unimelb.edu.au>

WARNING

Please note that the Java backend is still an experimental feature.
Expand Down
18 changes: 11 additions & 7 deletions README.ssdebug
Expand Up @@ -18,7 +18,8 @@ INSTALLATION
To use the source-to-source debugger you must install grades containing the
".ssdebug" grade component. One way to do this is to invoke configure
with the option `--enable-ssdebug-grades'. This will add the grades
hlc.gc.ssdebug and java.ssdebug to the set of library grades to install.
hlc.gc.ssdebug, csharp.ssdebug and java.ssdebug to the set of library grades
to install.

-----------------------------------------------------------------------------

Expand Down Expand Up @@ -59,7 +60,7 @@ increase the stack size, e.g.
LIMITATIONS

- There are no internal events. The only events are CALL, EXIT, REDO, FAIL,
and, for Java grades, EXCP.
and, for Java and C# grades, EXCP.

- Standard library procedures are treated specially. Events will only be
generated at the boundaries at which a user procedure calls and returns
Expand All @@ -72,13 +73,16 @@ LIMITATIONS
reach the end of the procedure to retry, the program will simply keep
executing. Press ^C to get back the debugger prompt.

- Exceptions are only handled in Java grades. Only a single EXCP event is
generated when an exception is thrown, instead of propagating EXCP events
- When running on Mono, ^C sometimes causes the program to hang.
This appears to be a bug in Mono.

- Exceptions are only handled in Java and C# grades. Only a single EXCP event
is generated when an exception is thrown, instead of propagating EXCP events
up the call stack to the nearest exception handler.

- In non-Java grades, the debugger's internal state will be inconsistent with
the program's execution after an exception, so you had better quit the
program and restart.
- In grades which don't handle exceptions, the debugger's internal state will
be inconsistent with the program's execution after an exception, so you had
better quit the program and restart.

- Breakpoints currently match procedures by module and name only. Predicates
or functions with the same name but different arities will still match.
Expand Down
4 changes: 2 additions & 2 deletions browser/Mercury.options
@@ -1,5 +1,5 @@
#-----------------------------------------------------------------------------#
# Copyright (C) 2002-2006 University of Melbourne.
# Copyright (C) 2002-2006, 2010 University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
Expand All @@ -23,7 +23,7 @@ MCFLAGS-mdb.declarative_execution = --no-optimize-unused-args

# XXX This line is needed so that `mmake --use-mmc-make libmer_browser'
# passes `-lmer_mdbcomp' to `mmc --make' in the MLLIBS variable.
EXTRA_LIBRARIES-libmer_browser = mer_mdbcomp
LIBRARIES-mer_browser = mer_mdbcomp

# Whereas these lines are needed for plain `mmake'.
EXTRA_LIBRARIES-libmer_browser.so = mer_mdbcomp
Expand Down
6 changes: 4 additions & 2 deletions browser/Mmakefile
Expand Up @@ -65,8 +65,10 @@ MLFLAGS += -R$(FINAL_INSTALL_MERC_LIB_DIR) \
MCFLAGS += -R$(FINAL_INSTALL_MERC_LIB_DIR) \
-R$(FINAL_INSTALL_MERC_GC_LIB_DIR)
endif
ifeq ("$(filter il% csharp% java% erlang%,$(GRADE))","")
MLLIBS += $(SOCKET_LIBRARY) $(NSL_LIBRARY) $(DL_LIBRARY) \
$(READLINE_LIBRARIES)
endif

MCFLAGS += --flags MDB_FLAGS $(CONFIG_OVERRIDE)

Expand Down Expand Up @@ -252,14 +254,14 @@ realclean_local:
.PHONY: install
install: install_library

ifneq ("$(filter il% csharp% erlang%,$(GRADE))","")
ifneq ("$(filter il% erlang%,$(GRADE))","")

# there is no browser in the .NET or Erlang backends

.PHONY: install_library
install_library:

else ifneq (,$(findstring java,$(GRADE)))
else ifeq ($(MMAKE_USE_MMC_MAKE),yes)

.PHONY: install_library
install_library: lib$(BROWSER_LIB_NAME).install
Expand Down
16 changes: 15 additions & 1 deletion browser/declarative_execution.m
@@ -1,7 +1,7 @@
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 1999-2007 The University of Melbourne.
% Copyright (C) 1999-2007, 2010 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.
%-----------------------------------------------------------------------------%
Expand Down Expand Up @@ -538,6 +538,13 @@ impure cache_proc_defn_rep(ProcLayout, ProcDefnRep),
}
").

:- pragma foreign_proc("C#",
call_node_bytecode_layout(_CallLabelLayout::in, _ProcLayout::out),
[will_not_call_mercury, thread_safe, promise_pure],
"
if (1 == 1) throw new System.Exception(\"not supported in csharp grade\");
").

:- pragma foreign_proc("Java",
call_node_bytecode_layout(_CallLabelLayout::in, _ProcLayout::out),
[will_not_call_mercury, thread_safe, promise_pure],
Expand Down Expand Up @@ -570,6 +577,13 @@ impure cache_proc_defn_rep(ProcLayout, ProcDefnRep),
}
").

:- pragma foreign_proc("C#",
have_cached_proc_defn_rep(_ProcLayout::in, _ProcDefnRep::out),
[will_not_call_mercury, thread_safe, promise_semipure],
"
if (1 == 1) throw new System.Exception(\"not supported in csharp grade\");
").

:- pragma foreign_proc("Java",
have_cached_proc_defn_rep(_ProcLayout::in, _ProcDefnRep::out),
[will_not_call_mercury, thread_safe, promise_semipure],
Expand Down
1 change: 1 addition & 0 deletions browser/listing.m
Expand Up @@ -104,6 +104,7 @@

:- pragma foreign_type("C", c_file_ptr, "FILE *", [can_pass_as_mercury_type]).
% stub.
:- pragma foreign_type("C#", c_file_ptr, "object").
:- pragma foreign_type("Java", c_file_ptr, "java.lang.Object").

% These predicates are called from trace/mercury_trace_internal.c.
Expand Down
15 changes: 15 additions & 0 deletions configure.in
Expand Up @@ -3345,6 +3345,11 @@ AC_ARG_ENABLE(dotnet-grades,
AC_HELP_STRING([--enable-dotnet-grades], [install the .NET grades]),
enable_dotnet_grades="$enableval",enable_dotnet_grades=no)

# We don't enable the csharp grade by default.
AC_ARG_ENABLE(csharp-grade,
AC_HELP_STRING([--enable-csharp-grade], [install the C# grade]),
enable_csharp_grade="$enableval",enable_csharp_grade=no)

# We don't enable the java grade by default.
AC_ARG_ENABLE(java-grade,
AC_HELP_STRING([--enable-java-grade], [install the Java grade]),
Expand Down Expand Up @@ -3378,6 +3383,7 @@ if test "$enable_most_grades" = no; then
enable_par_grades=no
enable_stseg_grades=no
enable_dotnet_grades=no
enable_csharp_grade=no
enable_java_grade=no
enable_erlang_grade=no
fi
Expand Down Expand Up @@ -3601,6 +3607,12 @@ then
LIBGRADES="$LIBGRADES il"
fi

# Add C# back-end grade, if a C# compiler is installed.
if test "$CSC" != "" -a "$enable_csharp_grade" = yes
then
LIBGRADES="$LIBGRADES csharp"
fi

# Add Java back-end grade, if Java is installed.
if test $mercury_cv_java = yes -a "$enable_java_grade" = yes
then
Expand All @@ -3626,6 +3638,9 @@ if test "$enable_ssdebug_grades" = yes; then
case "$LIBGRADES" in
*hlc.gc*) LIBGRADES="$LIBGRADES hlc.gc.ssdebug" ;;
esac
case "$LIBGRADES" in
*csharp*) LIBGRADES="$LIBGRADES csharp.ssdebug" ;;
esac
case "$LIBGRADES" in
*java*) LIBGRADES="$LIBGRADES java.ssdebug" ;;
esac
Expand Down

0 comments on commit 91b78d6

Please sign in to comment.