[m-rev.] for review: semidet C# code

Tyson Dowd trd at cs.mu.OZ.AU
Fri Oct 12 14:51:39 AEST 2001


On 12-Oct-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 12-Oct-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > 
> > library/int.m:
> > 	Implement much of the code in Mercury rather than C# or MC++.
> > 	The more efficient C bindings remain, but for other backends we
> > 	fall back on the Mercury bindings.
> ...
> > +++ library/int.m	11 Oct 2001 07:31:15 -0000
> > @@ -477,17 +477,6 @@
> >  	#define ML_BITS_PER_INT		(sizeof(MR_Integer) * CHAR_BIT)
> >  ").
> >  
> > -:- pragma foreign_decl("MC++", "
> > -	#include <limits.h>
> > -
> > -	// XXX this should work, but it would be nice to have a more robust
> > -	// technique that used the fact we map to System.Int32 in the compiler.
> > -
> > -	#define ML_BITS_PER_INT		(sizeof(MR_Integer) * CHAR_BIT)
> > -
> > -").
> > -
> > -
> >  :- pragma foreign_proc("C", int__max_int(Max::out),
> >  		[will_not_call_mercury, thread_safe], "
> >  	if (sizeof(MR_Integer) == sizeof(int))
> > @@ -541,24 +530,20 @@
> >  
> >  :- pragma foreign_proc("MC++", int__bits_per_int(Bits::out),
> >  		[will_not_call_mercury, thread_safe], "
> > -	Bits = ML_BITS_PER_INT;
> > +	Bits = 32;
> >  ").
> 
> That change isn't covered by the log message,
> and I don't think it is an improvement.


Hmmm... I will back out that part of the change actually, I was going to
implement this stuff in C#, but it isn't really necessary right now.

> > -:- pragma foreign_proc("MC++", int__quot_bits_per_int(Int::in) = (Div::out),
> > -		[will_not_call_mercury, thread_safe], "
> > -	Div = Int / ML_BITS_PER_INT;
> > -").
> > -
> > -:- pragma foreign_proc("MC++", int__times_bits_per_int(Int::in) = (Result::out),
> > -		[will_not_call_mercury, thread_safe], "
> > -	Result = Int * ML_BITS_PER_INT;
> > -").
> > +int__quot_bits_per_int(Int::in) = (Result::out) :-
> > +	int__bits_per_int(Bits),
> > +	Result = Int // Bits.
> 
> It would be nicer to use the int__bits_per_int/0 function, rather than the
> .../1 predicate.
> 
> > +int__times_bits_per_int(Int::in) = (Result::out) :-
> > +	int__bits_per_int(Bits),
> > +	Result = Int * Bits.
> 
> Likewise.
> 
> > +int__rem_bits_per_int(Int::in) = (Result::out) :-
> > +	int__bits_per_int(Bits),
> > +	Result = Int rem Bits.
> 
> Likewise.
> 

Ok, done.

> Also, as part of the change to use bool rather than int32,
> the following code in mlds_to_il.m should be considered:
> 
>  | load(const(Const), Instrs, Info, Info) :-
>  |                 % XXX is there a better way to handle true and false
>  |                 % using IL's bool type?
>  |         ( Const = true,
>  |                 Instrs = instr_node(ldc(int32, i(1)))
>  |         ; Const = false,
>  |                 Instrs = instr_node(ldc(int32, i(0)))
> 
> Ideally at least the XXX comment should be replaced with
> something a bit more definite.

These are the right constants to load, there are (AFAIK) no special
opcodes for true and false, this comment was just me being unsure.

I will replace int32 with bool, but it will eventually result in loading
an int32 anyway (4 byte and 8 byte integers are the only sorts of
integers that can be loaded on the CLR stack anyway).

> Also, does the following code in ilasm.m need to be
> modified to also handle `bool'?
> 
>  | 	output_instr(ldc(Type, Const)) -->
>  | 		( { Type = int32, Const = i(IntConst) }  ->
>  | 			...

Would be a good idea since I am changing the above code to generate
ldc(bool, i(1)) and ldc(bool, i(0)).

> 
> Otherwise that change looks fine.

Ok, once I test it with the suggested changes I will commit.

-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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