[m-dev.] For review: Bytecode interpreter modification

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jan 17 17:42:46 AEDT 2001


On 17-Jan-2001, Levi Cameron <l.cameron2 at ugrad.unimelb.edu.au> wrote:
> -output_args(call(ModuleId, PredId, Arity, ProcId)) -->
> +output_args(call(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
>  	output_module_id(ModuleId),
>  	output_pred_id(PredId),
>  	output_length(Arity),
> +	output_byte(IsFunc),

Using a whole byte where only a single bit is needed is
somewhat inefficient.  If/when we get around to optimizing
the bytecode interpreter, it may be worth considiering
a more efficient representation
(e.g. combining the arity and the is_pred_or_func flag).
But that is fine for now.

> +debug_args(call(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
>  	debug_module_id(ModuleId),
>  	debug_pred_id(PredId),
> -	debug_length(Arity),
> +	debug_length(Arity), 
> +	( { IsFunc = 0 } ->
> +		debug_string("pred")
> +	;
> +		debug_string("func")
> +	),

It would be better to add some more sanity checking, i.e. to make that
call error/1 for the `IsFunc \= 0, IsFunc \= 1' case.

> +debug_cons_id(pred_const(ModuleId, PredId, Arity, IsFunc, ProcId)) -->
>  	debug_string("pred_const"),
>  	debug_module_id(ModuleId),
>  	debug_pred_id(PredId),
>  	debug_length(Arity),
> +	( { IsFunc = 0 } ->
> +		debug_string("pred")
> +	;
> +		debug_string("func")
> +	),

Those five lines of code should be abstracted out into a separate
procedure.

> +++ bytecode_gen.m	2001/01/12 05:26:58
> @@ -360,6 +360,15 @@
>  	proc_info_arg_info(ProcInfo, ArgInfo),
>  	assoc_list__from_corresponding_lists(ArgVars, ArgInfo, ArgVarsInfos),
>  
> +	module_info_preds(ModuleInfo, PredTable),
> +	map__lookup(PredTable, PredId, PredInfo),
> +	pred_info_get_is_pred_or_func(PredInfo, PredOrFunc),
> +	( PredOrFunc = predicate ->	
> +		IsFunc = 0
> +	;
> +		IsFunc = 1
> +	),

Likewise that code, which occurs several times, should be abstracted
out into a separate procedure.

Apart from that, this looks fine.  Please post another diff once
you've addressed those comments, but feel free to commit the updated
version without waiting for another review.

-- 
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-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list