[m-rev.] for review: start implementing RTTI in Mercury
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Aug 17 05:38:51 AEST 2001
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.
> Index: library/rtti_implementation.m
...
> + % 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).
The comment there has causality the wrong way around.
> +:- func type_ctor_rep(type_ctor_info) = type_ctor_rep.
> +:- pragma foreign_proc("C#",
> + type_ctor_rep(TypeCtorInfo::in) = (TypeCtorRep::out), [], "
> + int rep;
> + rep = (int) TypeCtorInfo[4];
> + TypeCtorRep = mercury.runtime.LowLevelData.make_enum(rep);
> +").
Ouch, horrible magic numbers.
I would prefer it if those were extracted out into some code
at the top
enum type_ctor_info_field_nums {
type_ctor_rep = 4,
type_ctor_module_name = 7,
type_ctor_name = 8,
type_layout = 11
}
> +++ runtime/mercury_il.il 16 Aug 2001 14:10:27 -0000
> @@ -42,6 +42,26 @@
> // 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 {
The comment above this code is now in the wrong place --
it refers to the "TempHack" class.
You should also add comments explaining what your new code does
and why it needs to be written in IL.
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.
Writing in assembler using poor data structures (in this case, `object[]')
is a great way to make things run slow and be unmaintainable.
--
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