[m-rev.] for review: More modifications to the Java back-end

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Feb 6 19:41:11 AEDT 2002


On 06-Feb-2002, Michael Wybrow <mjwybrow at students.cs.mu.oz.au> wrote:
> 
> mercury/java/ProcAddr.java:
> mercury/java/Compare.java:
> mercury/java/Unify.java:
> 	Removed these files, they're now obsolete as they all use the standard 
> 	interface for method pointers provided by MethodPtr.java.

It's not OK to remove Compare.java and Unify.java, because other files
in the mercury/java directory (in particular TypeCtorInfo.java) still
contain references to the types defined in these files.

> Index: compiler/mlds_to_java.m
> +output_stmt(Indent, FuncInfo, try_commit(_Ref, Stmt, Handler), _) -->
...
> +	io__write_string("// java.util.Stack.pop();\n"),

What's that for?

Either add a comment explaining it, or just delete it.

> +:- func remove_dummy_vars(list(mlds__rval)) = list(mlds__rval).
> +:- mode remove_dummy_vars(in) = out is det.
> +
> +remove_dummy_vars([]) = [].
> +remove_dummy_vars([Var|Vars0]) = VarList :-
> +	Vars = remove_dummy_vars(Vars0),
> +	( 
> +   		Var = mlds__lval(Lval),
> +   		Lval = var(VarName, _),
> +   		VarName = qual(_, UnqualName),
> +   		UnqualName = var_name("dummy_var", no) 
> +	->
> +		VarList = Vars
> +	;
> +		VarList = [Var|Vars]	
> +	).

It's not right to just remove the dummy variables like this.
Instead, you need to substitute an appropriate dummy value.
Otherwise the number of return values won't match up in the
caller and callee.

Anyway, this should be handled in output_lval, not in output_stmt.

The right way to handle it is to check for `dummy_var' in the `var'
clause for output_lval, and output a reference to a static variable
`dummy_var' defined in a fixed class (e.g. some class in the
mercury/java directory, or mercury.private_builtin).

> +output_init_args([Arg|Args], [ArgType|ArgTypes], ArgNum) -->
> +	(
> +		{ ArgNum = 0 },
> +		{ ArgType = native_int_type },
> +		{ Arg = const(int_const(_Val)) }
> +	->
> +		% This first argument is a `data_tag', It is set by
> +		% the class constructor so this argument can be discarded.

That's not the right way to test for a secondary tag.
The right way is to check for `ArgNum = 0' and `HasSecTag = yes',
where `HasSecTag' is the field from the `new_object' instruction.

> @@ -2340,11 +2422,14 @@
>  		% must be something that maps to MR_Box.
>  		{ error("unexpected field type") }
>  	),
> -	io__write_string("("),
> +	% XXX We shouldn't need this cast here, but there are cases where 
> +	%     it is needed and the MLDS doesn't seem to generate it.
> +	io__write_string("((java.lang.Object[]) "),
>  	output_rval(Rval),
> -	io__write_string("["),
> +	io__write_string(")["),
>  	output_rval(OffsetRval),
> -	io__write_string("]))").
> +	io__write_string(" - 1]").   % " - 1" because the field indexes begin
> +				     % from 1, but array indexes from 0.

The `- 1' here is wrong -- the OffsetRval is an offset,
not a field index, and offsets start from zero.

> @@ -2553,6 +2638,10 @@
...
> +java_builtin_type(Type, "int", "java.lang.Integer", "intValue") :-
> +	Type = mlds__mercury_type(term__functor(term__atom(":"), _, _), _, _),
> +	Type = mlds__mercury_type(MercuryType, _, _),
> +	type_util__is_dummy_argument_type(MercuryType).

Please add a comment here explaining why this is needed.

> @@ -2680,7 +2769,9 @@
>  	mlds_output_code_addr(CodeAddr, IsCall).
>  
>  output_rval_const(data_addr_const(DataAddr)) -->
> -	mlds_output_data_addr(DataAddr).
> +	io__write_string("new "),
> +	mlds_output_data_addr(DataAddr),
> +	io__write_string("()").

That looks wrong.  The argument of `data_addr_const' is supposed to 
represent a static variable name, not a type.

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