[m-rev.] for review: initialise mercury runtime on .NET fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 16 00:04:34 AEST 2003


On 15-Oct-2003, Peter Ross <pro at missioncriticalit.com> wrote:
> 
> Ensure that the mercury runtime is always initialised on the .NET
> backend, regardless of whether Mercury is used as a library or an
> executable.

> +++ compiler/mlds_to_il.m	15 Oct 2003 13:07:37 -0000
> @@ -2857,6 +2857,8 @@
>  	{ Method = method(methodhead([public, static], cctor, 
>  		signature(call_conv(no, default), void, []), []),
>  		MethodDecls) },
> + 	{ MaybeInitRuntimeInstrs = maybe_init_runtime_instrs },
> + 	{ RuntimeInitInstrs = runtime_initialization_instrs },
>  	test_rtti_initialization_field(DoneFieldRef, TestInstrs),
>  	set_rtti_initialization_field(DoneFieldRef, SetInstrs),
>  	{ CCtorCalls = list__filter_map(
> @@ -2866,8 +2868,9 @@
>  			C = call_class_constructor(
>  				class_name(ImportName, wrapper_class_name))
>  		), Imports) },
> -	{ AllInstrs = list__condense([TestInstrs, AllocInstrs, SetInstrs,
> -		CCtorCalls, InitInstrs, [ret]]) },
> +	{ AllInstrs = list__condense([MaybeInitRuntimeInstrs,
> +		TestInstrs, AllocInstrs, SetInstrs,
> +		CCtorCalls, InitInstrs, RuntimeInitInstrs, [ret]]) },
>  	{ MethodDecls = [instrs(AllInstrs)] }.
>  
>  :- pred test_rtti_initialization_field(fieldref, list(instr),

There should be some comments explaining what MaybeInitRuntimeInstrs
and RuntimeInitInstrs are, and outlining the pattern of the IL that
we will generate.

> @@ -2876,7 +2879,7 @@
>  test_rtti_initialization_field(FieldRef, Instrs) -->
>  	il_info_make_next_label(DoneLabel),
>  	{ Instrs = [ldsfld(FieldRef), brfalse(label_target(DoneLabel)),
> -		ret, label(DoneLabel)] }.
> +		pop, ret, label(DoneLabel)] }.

The comment showing the pattern of instructions which includes these
should be updated.

> Index: runtime/mercury_il.il
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_il.il,v
> retrieving revision 1.21
> diff -u -r1.21 mercury_il.il
> --- runtime/mercury_il.il	5 Mar 2003 15:55:22 -0000	1.21
> +++ runtime/mercury_il.il	15 Oct 2003 13:07:40 -0000
> @@ -605,17 +605,49 @@
>  
>  }
>  
> -// Call init_state/2 in the IO module.
> -// This gets called before main runs.
> -// It has to be written in IL because we call something that might not
> -// yet be available in a .DLL.
> +// The init class is responsible for ensuring that the mercury runtime
> +// is initialised before the first piece of Mercury code is executed.
> +// This is done by calling responsible_for_initialising_runtime as the first
> +// thing and init_runtime as the last thing in each .cctor for every
> +// mercury_code class.
> +// XXX These routines needs to be made thread safe!
>  
>  .class public 'Init' {
> -    .method public static default void init_runtime() {
> -        tail.
> +
> +    .method public static default void .cctor()
> +    {
> +    	ldc.i4.1
> +	stsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
> +	ret
> +    }
> +
> +    .method public static default bool responsible_for_initialising_runtime() {
> +    	ldsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
> +	brfalse false_branch
> +
> +	true_branch:
> +	ldc.i4.0
> +	stsfld bool [mercury]mercury.runtime.Init::will_initialise_runtime
> +	ldc.i4.1
> +	ret
> +
> +	false_branch:
> +	ldc.i4.0
> +	ret
> +    }
> +
> +    .method public static default void init_runtime(bool initialise) {
> +	ldarg initialise
> +	brtrue true_branch 
> +	ret
> +
> +	true_branch:
>          call void ['mercury']mercury.io.mercury_code::init_state_2()
>  	ret
>      }
> +
> +
> +    .field private static bool will_initialise_runtime
>  }

It would be clearer if the .field declaration preceded the
.method declarations. 

But the code here is complicated enough that it would be better if it was
written in C# or MC++ rather than IL.

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