[m-rev.] for review: start implementing RTTI in Mercury
Tyson Dowd
trd at cs.mu.OZ.AU
Fri Aug 17 19:55:19 AEST 2001
On 17-Aug-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Quite a bit of this code is very much specific to the --no-high-level-data
> case; you should add appropriate XXX comments to document that.
>
> On 17-Aug-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > library/rtti_implementation.m:
> > Add a new module to implement RTTI for the .NET (and possibly
> > Java) backend. This module tries to do most of the RTTI tasks
> > in Mercury rather than in C. Hopefully it will be easier to
> > port this implementation in future.
>
> You need to modify doc/Mmakefile to exclude this from the
> modules that go in the Mercury library reference manual.
>
> > library/std_util.m:
> > Call into rtti.m to compare type_infos.
>
> s/rtti.m/rtti_implementation.m/
>
> > runtime/mercury_il.il:
> > Add helper functions to get the function pointers for tuple
> > compare and unify procedures.
> >
> > runtime/mercury_mcpp.cpp:
> > runtime/mercury_mcpp.h:
> > Add tuple to the type_ctor_rep.
> >
> > runtime/mercury_type_info.h:
> > Mention that changes in the type_ctor_rep might require changes
> > in rtti_implementation and mercury_mcpp.{h,cpp}.
>
> That part of the log message is wrong; it's from the
> other change that you posted.
It's not the same, this one mentions both rtti_implementation and
mercury_mcpp.{h,cpp}. The previous change only mentions
mercury_mcpp.{h,cpp}.
After the merge the change will be slightly different.
> But looking at the code, I can't see why you wrote it in IL.
> It looks like it would be very easy to translate that into C#:
>
> object[] get_type_ctor_info(object[] TypeInfo) {
> try {
> return (object[]) TypeInfo[0];
> } catch (System.BadCastException) {
> return TypeInfo;
> }
> }
>
> Much shorter, and easier to read.
>
> Are you worried about efficiency,
> i.e. the overhead of exception handling?
> If so, then I think this is premature optimization.
Yes I was worried about efficiency, but if you think it is premature
then I will put it into C#.
> Writing in assembler using poor data structures (in this case, `object[]')
> is a great way to make things run slow and be unmaintainable.
I haven't done any benchmarking so I don't know anything about the
speed.
Here's the interdiff:
diff -u library/rtti_implementation.m library/rtti_implementation.m
--- library/rtti_implementation.m
+++ library/rtti_implementation.m
@@ -158,8 +158,8 @@
%-----------------------------------------------------------------------------%
% In the .NET backend, we don't generally have to collapse equivalences
- % because they are already collapsed (this is why il grades require
- % intermodule optimization).
+ % because they are already collapsed (il grades require
+ % intermodule optimization, which will collapse them for us).
%
% XXX For other backends this code may have to be completed.
@@ -180,17 +180,32 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
+%
+% XXX we have only implemented the .NET backend for the low-level data case.
:- pred get_type_ctor_info(type_info::in, type_ctor_info::out) is det.
- % XXX Some bug in the handling of foreign_proc IL stopped me
- % implementing this in IL directly, so for the moment I will just work
- % around it by calling the IL from C#. -- trd.
+:- pragma foreign_decl("C#", "
+
+ enum type_ctor_info_field_nums {
+ type_ctor_rep = 4,
+ type_ctor_module_name = 7,
+ type_ctor_name = 8,
+ type_layout = 11
+ }
+
+").
+
+
:- pragma foreign_proc("C#",
get_type_ctor_info(TypeInfo::in, TypeCtorInfo::out), [],
"
- TypeCtorInfo = mercury.runtime.RuntimeHelperFunctions.get_type_ctor_info(TypeInfo);
+ try {
+ TypeCtorInfo = (object[]) TypeInfo[0];
+ } catch (System.InvalidCastException) {
+ TypeCtorInfo = TypeInfo;
+ }
").
:- pragma foreign_proc("C",
@@ -218,7 +233,8 @@
:- pragma foreign_proc("C#",
type_ctor_rep(TypeCtorInfo::in) = (TypeCtorRep::out), [], "
int rep;
- rep = (int) TypeCtorInfo[4];
+ rep = (int) TypeCtorInfo[
+ (int) type_ctor_info_field_nums.type_ctor_rep];
TypeCtorRep = mercury.runtime.LowLevelData.make_enum(rep);
").
:- pragma foreign_proc("C",
@@ -232,7 +248,9 @@
:- pragma foreign_proc("C#",
type_ctor_module_name(TypeCtorInfo::in) = (Name::out), [], "
- Name = (string) TypeCtorInfo[7];
+ Name = (string)
+ TypeCtorInfo[(int)
+ type_ctor_info_field_nums.type_ctor_module_name];
").
:- pragma foreign_proc("C",
@@ -247,7 +265,8 @@
:- pragma foreign_proc("C#",
type_ctor_name(TypeCtorInfo::in) = (Name::out), [], "
- Name = (string) TypeCtorInfo[8];
+ Name = (string)
+ TypeCtorInfo[(int) type_ctor_info_field_nums.type_ctor_name];
").
:- pragma foreign_proc("C",
type_ctor_name(TypeCtorInfo::in) = (Name::out), [], "
@@ -260,7 +279,8 @@
:- pragma foreign_proc("C#",
type_layout(TypeCtorInfo::in) = (TypeLayout::out), [], "
- TypeLayout = (object[]) TypeCtorInfo[11];
+ TypeLayout = (object[])
+ TypeCtorInfo[(int) type_ctor_info_field_nums.type_layout];
").
:- pragma foreign_proc("C",
type_layout(TypeCtorInfo::in) = (TypeLayout::out), [], "
reverted:
--- runtime/mercury_il.il 16 Aug 2001 14:10:27 -0000
+++ runtime/mercury_il.il 31 Jul 2001 10:08:01 -0000 1.10
@@ -42,26 +42,6 @@
// MC++ used to handle this, and then it stopped working, so now it's just
// not supported at all. I hope it will make a comeback.
-.class public RuntimeHelperFunctions {
-
-.method public static default class [mscorlib]System.Object[]
-get_type_ctor_info(class [mscorlib]System.Object[] TypeInfo) {
- ldarg TypeInfo
- ldc.i4.0
- ldelem.ref
- isinst class [mscorlib]System.Object[]
- brfalse isnull
- ldarg TypeInfo
- ldc.i4.0
- ldelem.ref
- castclass class [mscorlib]System.Object[]
- ret
-isnull:
- ldarg TypeInfo
- ret
-}
-} // end class RuntimeHelperFunctions
-
.class public TempHack {
.method public static default int32
diff -u runtime/mercury_type_info.h runtime/mercury_type_info.h
--- runtime/mercury_type_info.h
+++ runtime/mercury_type_info.h
@@ -516,7 +516,7 @@
** information.
**
** Any changes in this definition might also require changes in
-** runtime/mercury_mcpp.{h,cpp}
+** library/rtti_implementation.m and runtime/mercury_mcpp.{h,cpp}
*/
typedef enum {
only in patch2:
--- doc/Mmakefile 25 Jun 2001 04:10:06 -0000 1.26
+++ doc/Mmakefile 17 Aug 2001 09:54:38 -0000
@@ -163,8 +163,8 @@
# The following rules automatically build the library documentation
# by extracting the module interfaces from the library source code.
-# Note that the private_builtin.m module is just an implementation
-# detail of the library, so it is not documented.
+# Note that some modules are just implementation details of the library,
+# so they are not documented.
library-menu.texi: $(LIBRARY_DIR)/*.m
{ \
@@ -173,10 +173,12 @@
case $$filename in \
$(LIBRARY_DIR)/private_builtin.m) \
;; \
- $(LIBRARY_DIR)/table_builtin.m) \
- ;; \
$(LIBRARY_DIR)/profiling_builtin.m) \
;; \
+ $(LIBRARY_DIR)/rtti_implementation.m) \
+ ;; \
+ $(LIBRARY_DIR)/table_builtin.m) \
+ ;; \
*) \
echo "* `basename $$filename .m`::"; \
;; \
@@ -189,9 +191,11 @@
case $$filename in \
$(LIBRARY_DIR)/private_builtin.m) \
;; \
- $(LIBRARY_DIR)/table_builtin.m) \
- ;; \
$(LIBRARY_DIR)/profiling_builtin.m) \
+ ;; \
+ $(LIBRARY_DIR)/rtti_implementation.m) \
+ ;; \
+ $(LIBRARY_DIR)/table_builtin.m) \
;; \
*) \
file="`basename $$filename .m`"; \
Tyson.
--------------------------------------------------------------------------
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