[m-rev.] for review: fix .maxstack output and update IL instruction set

Fergus Henderson fjh at cs.mu.OZ.AU
Wed May 30 01:34:57 AEST 2001


On 28-May-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> +:- func get_stack_difference(ilds__instr) = int.
> +get_stack_difference(end_block(_, _)) 				= 0.
> +get_stack_difference(comment(_)) 				= 0.
...

A comment explaining the intended meaning of this function would be very
helpful.

What are the units that this is measured in?  Bits?  Bytes?  Words? 
(What's a word in the context?)  Objects?  Stack items?  Something else?

> +	% Remove the params, and remove "this" if it is an instance
> +	% method, but add the return type (if there is one).
> +:- func get_methodref_stack_difference(methodref) = int.
> +get_methodref_stack_difference(MethodRef) = Diff :-
> +	( 
> +		MethodRef = methoddef(CallConv, RetType, _, Params) 
> +	; 
> +		MethodRef = local_method(CallConv, RetType, _, Params)
> +	),
> +	InstanceDiff = ( CallConv = call_conv(yes, _) -> -1 ; 0 ),
> +	RetDiff = ( RetType = void -> 0 ; 1),
> +	Diff = -(length(Params)) + InstanceDiff + RetDiff.
> +
> +	% Remove the params, and remove "this" if it is an instance
> +	% method, but add the return type (if there is one).
> +:- func get_signature_stack_difference(signature) = int.
> +get_signature_stack_difference(signature(CallConv, RetType, Params)) = Diff :-
> +	InstanceDiff = ( CallConv = call_conv(yes, _) -> -1 ; 0 ),
> +	RetDiff = ( RetType = void -> 0 ; 1),
> +	Diff = -(length(Params)) + InstanceDiff + RetDiff.

I found this code a bit confusing.  The names and comments of these
functions are potentially misleading, IMHO.  The functions don't actually
remove anything, they just return a count of what is added/removed.
Also, a signature or methodref by itself doesn't add or remove anything;
this is just counting what is added/removed when a signature or methodref
is used in a call/calli instruction.

I think it might help to name the functions get_call_stack_difference
and get_calli_stack_difference, and to change the comments to say
"A `call(i)' instruction will ...", to make it clear that the comment
is about what the call/calli instruction does, not about what the
get_*_stack_difference function does.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  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