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

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Oct 12 14:05:09 AEST 2001


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.

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

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.

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) }  ->
 | 			...

Otherwise that change looks fine.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  | "... it seems to me that 15 years of
The University of Melbourne         | email is plenty for one lifetime."
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- Prof. Donald E. Knuth
--------------------------------------------------------------------------
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