[m-rev.] for review: java back-end fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Wed May 14 21:20:42 AEST 2003


Estimated hours taken: 24
Branches: main

Various fixes to make the Java back-end work better.

compiler/ml_code_gen.m:
	Make sure that no module in the generated MLDS
	tries to import itself.

	Also, add some XXX comments about the handling of
	model_semi foreign_procs for Java and IL.

compiler/ml_code_util.m:
	Fix a bug with the handling of `top_unused' modes with `--det-copy-out'.

compiler/mlds_to_java.m:
	Add an XXX comment about the problem with type names clashing
	with constructor names.
	Add an XXX comment about ignoring `pragma foreign_import'
	and `pragma export' for Java.

	Fix the code so that we handle `foreign_decl' and `foreign_code'
	for Java properly -- previously, we were generating code for
	`foreign_decl' in the wrong place, and `foreign_code' was just
	ignored.

	Handle procedures defined as `external' by calling `extern_Foo',
	rather than generating a declaration with no body, because
	Java syntax doesn't allow that.

	Fix a bug where some names weren't getting mangled properly.

library/Mmakefile:
	Add support for the `java' grade.
	This involved adding new targets `javas' and `classes',
	and making the main `library' target depend on these if
	the grade is `java'.

library/builtin.m:
	Add (stub) Java implementations of various builtins:
	- the type_ctor_infos for the builtin types int, string, character
	- builtin.unify/2 and builtin.compare/3
library/private_builtin.m:
	Add (stub) Java implementations of various builtins:
	- the type_ctor_info for private_builtin.type_info/1
	- builtin_compare_int/3, builtin_compare_string/3,
	  builtin_strcmp/3

library/math.m:
	Fix a couple of bugs in the Mercury code for "log" and "log2".

library/std_util.m:
	Provide a Java implementation for cc_multi_equal/2.
	Avoid a compiler warning for the Mercury implementation
	of semidet_succeed and semidet_fail.

library/store.m:
	Rename the constructor for the `store/1' type,
	to work around a bug in the Java back-end.

library/string.m:
	Fix bugs in the Mercury implementation of string__contains_char
	and string__split.
	Provide a Java implementation of string__length.

library/type_desc.m:
	Provide Java implementations of type_of/1 and has_type/2.
	Provide (stub) implementations of the builtin types type_desc/0
	and type_ctor_desc/0.

Workspace: /home/ceres/fjh/mercury
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.129
diff -u -d -r1.129 ml_code_gen.m
--- compiler/ml_code_gen.m	18 Mar 2003 02:43:38 -0000	1.129
+++ compiler/ml_code_gen.m	14 May 2003 08:48:10 -0000
@@ -865,9 +865,14 @@
 
 ml_gen_imports(ModuleInfo, MLDS_ImportList) :-
 		% Determine all the mercury imports.
+		% XXX This is overly conservative,
+		% i.e. we import more than we really need.
 	module_info_globals(ModuleInfo, Globals),
 	globals__get_target(Globals, Target),
-	module_info_get_all_deps(ModuleInfo, AllImports),
+	module_info_get_all_deps(ModuleInfo, AllImports0),
+		% No module needs to import itself.
+	module_info_name(ModuleInfo, ThisModule),
+	AllImports = set__delete(AllImports0, ThisModule),
 	P = (func(Name) = mercury_import(
 				compiler_visible_interface,
 				mercury_module_name_to_mlds(Name))),
@@ -1163,7 +1168,6 @@
 		% value (rather than being passed by reference) and remove
 		% them from the byref_output_vars field in the ml_gen_info.
 		( CodeModel = model_non ->
-		
  			ml_set_up_initial_succ_cont(ModuleInfo, 
 				CopiedOutputVars, MLDSGenInfo0, MLDSGenInfo1)
  		;
@@ -2437,6 +2441,8 @@
 			AssignOutputsList, ConvDecls, ConvStatements),
 	%
 	% Put it all together
+	% XXX FIXME need to handle model_semi code here,
+	%     i.e. provide some equivalent to SUCCESS_INDICATOR.
 	%
 	{ Java_Code = list__condense([
 			ArgDeclsList,
@@ -2554,6 +2560,11 @@
 ml_gen_ordinary_pragma_il_proc(_CodeModel, Attributes,
 	PredId, ProcId, ArgVars, ArgDatas, OrigArgTypes,
 	ForeignCode, Context, MLDS_Decls, MLDS_Statements) -->
+
+	% XXX FIXME need to handle model_semi code here,
+	%     i.e. provide some equivalent to SUCCESS_INDICATOR.
+
+	% XXX FIXME do we handle top_unused mode correctly?
 
 	{ MLDSContext = mlds__make_context(Context) },
 
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.70
diff -u -d -r1.70 ml_code_util.m
--- compiler/ml_code_util.m	28 Mar 2003 06:42:48 -0000	1.70
+++ compiler/ml_code_util.m	14 May 2003 08:49:51 -0000
@@ -2767,7 +2767,7 @@
 	; HeadVars = [Var|Vars], HeadModes = [Mode|Modes] ->
 		map__lookup(VarTypes, Var, VarType),
 		(
-			\+ mode_to_arg_mode(ModuleInfo, Mode, VarType, top_in)
+			mode_to_arg_mode(ModuleInfo, Mode, VarType, top_out)
 		->
 			OutputVars1 = select_output_vars(ModuleInfo,
 					Vars, Modes, VarTypes),
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.39
diff -u -d -r1.39 mlds_to_java.m
--- compiler/mlds_to_java.m	9 May 2003 00:45:09 -0000	1.39
+++ compiler/mlds_to_java.m	14 May 2003 08:49:52 -0000
@@ -23,6 +23,10 @@
 %	handle foreign code written in Java
 %
 % TODO: 
+% 	Support for Java in Mmake and mmc --make
+% 	Fix problem with type names and constructor names that are the same
+% 		(Java does not allow the name of a nested class to be
+% 		the same as its enclosing class)
 %	General code cleanup
 %	handle static ground terms
 %	RTTI (requires static ground terms)
@@ -383,19 +387,21 @@
 	{ Defns = WrapperDefns ++ Defns0 },
 	%
 	% Get the foreign code for Java
+	% XXX We should not ignore _RevImports and _ExportDefns
 	%
 	{ ForeignCode = mlds_get_java_foreign_code(AllForeignCode) },
 	{ ForeignCode = mlds__foreign_code(RevForeignDecls, _RevImports,
-		_RevBodyCode, _ExportDefns) },
+		RevBodyCode, _ExportDefns) },
 	{ ForeignDecls = list__reverse(RevForeignDecls) },
+	{ ForeignBodyCode = list__reverse(RevBodyCode) },
 	%
 	% Output transformed MLDS as Java source.  
 	%
-	output_src_start(Indent, ModuleName, Imports, Defns), 
+	output_src_start(Indent, ModuleName, Imports, ForeignDecls, Defns), 
 	{ list__filter(defn_is_rtti_data, Defns, _RttiDefns, NonRttiDefns) },
 	% XXX Need to output RTTI data at this point.
 	% Output Java foreign code declarations.
-	io__write_list(ForeignDecls, "\n", output_java_decl(Indent)),
+	io__write_list(ForeignBodyCode, "\n", output_java_body_code(Indent)),
 	{ CtorData = none },  % Not a constructor.
 	output_defns(Indent + 1, MLDS_ModuleName, CtorData, NonRttiDefns),
 	output_src_end(Indent, ModuleName).
@@ -419,6 +425,17 @@
 		{ sorry(this_file, "foreign code other than Java") }
 	).
 
+:- pred output_java_body_code(indent, user_foreign_code, io__state, io__state).
+:- mode output_java_body_code(in, in, di, uo) is det.
+
+output_java_body_code(Indent, user_foreign_code(Lang, Code, Context)) -->
+	% only output Java code
+	( { Lang = java } ->
+		indent_line(make_context(Context), Indent),
+		io__write_string(Code), io__nl
+	;
+		{ sorry(this_file, "foreign code other than Java") }
+	).
 
 :- func mlds_get_java_foreign_code(map(foreign_language, mlds__foreign_code))
 		= mlds__foreign_code.
@@ -428,8 +445,6 @@
 	( map__search(AllForeignCode, java, ForeignCode0) ->
 		ForeignCode = ForeignCode0
 	;
-		% This can occur when compiling to a non-C target
-		% using "--mlds-dump all"
 		ForeignCode = foreign_code([], [], [], [])
 	).
 
@@ -940,11 +955,11 @@
 % 
 
 :- pred output_src_start(indent, mercury_module_name, mlds__imports, 
-	mlds__defns, io__state, io__state).
+	list(foreign_decl_code), mlds__defns, io__state, io__state).
 
-:- mode output_src_start(in, in, in, in, di, uo) is det.
+:- mode output_src_start(in, in, in, in, in, di, uo) is det.
 
-output_src_start(Indent, ModuleName, Imports, Defns) -->
+output_src_start(Indent, ModuleName, Imports, ForeignDecls, Defns) -->
 	{ JavaSafeModuleName = valid_module_name(ModuleName) },
 	output_auto_gen_comment(ModuleName),
 	indent_line(Indent),
@@ -953,6 +968,7 @@
 	io__write_string(". */\n\n"),
 	output_package_info(JavaSafeModuleName),	
 	output_imports(Imports), 
+	io__write_list(ForeignDecls, "\n", output_java_decl(Indent)),
 	io__write_string("public class "),
 	prog_out__write_sym_name(JavaSafeModuleName),
 	io__write_string(" {\n"),
@@ -1443,9 +1459,6 @@
 		-->
 	output_func_decl(Indent, Name, CtorData, Context, Signature),
 	(
-		{ MaybeBody = external },
-		io__write_string(";\n")
-	;
 		{ MaybeBody = defined_here(Body) },
 		io__write_string("\n"),
 		indent_line(Context, Indent),
@@ -1454,6 +1467,18 @@
 		output_statement(Indent + 1, FuncInfo, Body, _ExitMethods),
 		indent_line(Context, Indent),
 		io__write_string("}\n")	% end the function
+	;
+		{ MaybeBody = external },
+		% Java requires that all function definitions have a body.
+		% So for each external function "Foo", we emit a body
+		% which is just a call to "extern_Foo" with the same
+		% parameters.
+		io__write_string("\n"),
+		indent_line(Context, Indent),
+		io__write_string("{\n"),
+		output_extern_call(Indent + 1, Name, Context, Signature),
+		indent_line(Context, Indent),
+		io__write_string("}\n")	% end the function
 	).
 
 :- pred output_func_decl(indent, qualified_entity_name, ctor_data,
@@ -1482,8 +1507,6 @@
 	output_name(Name),	
 	output_params(Indent, ModuleName, Context, Parameters).
 
-
-
 :- pred output_params(indent, mlds_module_name, mlds__context,
 		mlds__arguments, io__state, io__state).
 :- mode output_params(in, in, in, in, di, uo) is det.
@@ -1511,6 +1534,55 @@
 	output_fully_qualified_name(qual(ModuleName, Name)).
 
 %-----------------------------------------------------------------------------%
+
+	% Java requires that all function declarations have a body.
+	% So for each function "Foo" which is declared as "external",
+	% we emit a body which is just a call to "extern_Foo" with the same
+	% parameters.
+
+:- pred output_extern_call(indent, qualified_entity_name,
+		mlds__context, func_params, io__state, io__state).
+:- mode output_extern_call(in, in, in, in, di, uo) is det.
+
+output_extern_call(Indent, QualifiedName, Context, Signature) -->
+	{ Signature = mlds__func_params(Parameters, RetTypes) },
+	{ QualifiedName = qual(ModuleName, Name) },
+	indent_line(Context, Indent),
+	( { RetTypes \= [] } ->
+		io__write_string("return ")
+	;
+		[]
+	),
+	io__write_string("extern_"),
+	output_name(Name),
+	output_extern_call_args(Indent, ModuleName, Context, Parameters),
+	io__write_string(";\n").
+
+:- pred output_extern_call_args(indent, mlds_module_name, mlds__context,
+		mlds__arguments, io__state, io__state).
+:- mode output_extern_call_args(in, in, in, in, di, uo) is det.
+
+output_extern_call_args(Indent, ModuleName, Context, Parameters) -->
+	io__write_char('('),
+	( { Parameters = [] } ->
+		[]
+	;
+		io__nl,
+		io__write_list(Parameters, ",\n",
+			output_extern_call_arg(Indent + 1, ModuleName, Context))
+	),
+	io__write_char(')').
+
+:- pred output_extern_call_arg(indent, mlds_module_name, mlds__context,
+		mlds__argument, io__state, io__state).
+:- mode output_extern_call_arg(in, in, in, in, di, uo) is det.
+
+output_extern_call_arg(Indent, ModuleName, Context, Arg) -->
+	{ Arg = mlds__argument(Name, _Type, _GC_TraceCode) },
+	indent_line(Context, Indent),
+	output_fully_qualified_name(qual(ModuleName, Name)).
+
+%-----------------------------------------------------------------------------%
 %
 % Code to output names of various entities
 % XXX Much of the code in this section will not work when we 
@@ -2741,7 +2813,9 @@
 :- mode output_mangled_name(in, di, uo) is det.
 
 output_mangled_name(Name) -->
-	io__write_string(name_mangle(Name)).
+	{ MangledName = name_mangle(Name) },
+	{ JavaSafeName = valid_symbol_name(MangledName) },
+	io__write_string(JavaSafeName).
 
 :- pred mlds_output_bracketed_lval(mlds__lval, io__state, io__state).
 :- mode mlds_output_bracketed_lval(in, di, uo) is det.
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.113
diff -u -d -r1.113 Mmakefile
--- library/Mmakefile	27 Mar 2003 05:32:07 -0000	1.113
+++ library/Mmakefile	14 May 2003 11:14:29 -0000
@@ -193,14 +193,33 @@
 ss: $($(STD_LIB_NAME).ss)
 pic_ss: $($(STD_LIB_NAME).pic_ss)
 ils: $($(STD_LIB_NAME).ils)
+javas: $($(STD_LIB_NAME).javas)
 else
 os: $(STD_LIB_NAME).os
 cs: $(STD_LIB_NAME).cs
 ss: $(STD_LIB_NAME).ss
 pic_ss: $(STD_LIB_NAME).pic_ss
 ils: $(STD_LIB_NAME).ils
+javas: $(STD_LIB_NAME).javas
 endif
 
+# The names `int', `float', and `char' can't be used as class names,
+# because they are Java keywords.  So we use `mr_int', `mr_float', and
+# `mr_char' instead.  Since Java implementations often assume that
+# a class foo is located in a file foo.java, we similarly mangle the
+# Java file names for these standard library modules.
+JAVAS = ` echo $($(STD_LIB_NAME).javas) | sed \
+		-e 's/ int.java/ mr_int.java/' \
+		-e 's/ float.java/ mr_float.java/' \
+		-e 's/ char.java/ mr_char.java/' `
+
+# We need to invoke javac on all of the classes at the same time,
+# rather than compiling them separately.  This is needed because
+# otherwise javac doesn't handle cyclic dependencies between different
+# modules.
+classes: javas
+	$(JAVAC) $(JAVACFLAGS) $(JAVAS)
+
 #-----------------------------------------------------------------------------#
 
 .PHONY: lib_std
@@ -271,7 +290,17 @@
 exception__csharp_code.dll : exception__cpp_code.dll
 CSHARP_ASSEMBLY_REFS-exception__csharp_code += /addmodule:exception__cpp_code.dll
 
-else	# GRADE != il
+endif
+#-----------------------------------------------------------------------------#
+ifeq ("$(findstring java,$(GRADE))","java")
+# XXX Mmake should add this dependency automatically
+lib_std: classes
+endif
+#-----------------------------------------------------------------------------#
+#
+# Some extra rules that we need for the C and asm back-ends
+#
+ifeq ("$(findstring il,$(GRADE))$(findstring java,$(GRADE))","")
 
 # The following dependency is just there to improve compilation speed;
 # making tree234.$O first improves effective parallelism with parallel makes.
@@ -297,9 +326,9 @@
 			grep '^INIT ' $$$${module}.m; \
 			true; \
 		done"
-endif
+endif	# 
 
-endif	# GRADE != il
+endif	# GRADE != il && GRADE != java
 #-----------------------------------------------------------------------------#
 
 # Ensure we recompile library__version if VERSION is changed.
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.89
diff -u -d -r1.89 builtin.m
--- library/builtin.m	3 Mar 2003 14:45:27 -0000	1.89
+++ library/builtin.m	14 May 2003 08:41:53 -0000
@@ -1091,6 +1091,42 @@
 }
 ").
 
+:- pragma foreign_code("Java", "
+	public static class void_0
+	{
+		// Make the constructor private to ensure that we can
+		// never create an instance of this class.
+		private void_0()
+		{
+		}
+	}
+").
+
+%-----------------------------------------------------------------------------%
+
+:- pragma foreign_code("Java", "
+
+    public static mercury.private_builtin.type_info_1 builtin__type_ctor_info_int_0 = new mercury.private_builtin.type_info_1();
+    
+    public static mercury.private_builtin.type_info_1 builtin__type_ctor_info_string_0 = new mercury.private_builtin.type_info_1();
+
+    public static mercury.private_builtin.type_info_1 builtin__type_ctor_info_character_0 = new mercury.private_builtin.type_info_1();
+
+    public static boolean unify_2_p_0(mercury.private_builtin.type_info_1 ti,
+		    java.lang.Object x, java.lang.Object y)
+    {
+      throw new java.lang.Error(""unify/3 not implemented"");
+    }
+
+    public static comparison_result_0 compare_3_p_0(
+	mercury.private_builtin.type_info_1 ti,
+	java.lang.Object x, java.lang.Object y)
+    {
+      throw new java.lang.Error(""compare/3 not implemented"");
+    }
+
+").
+
 :- end_module builtin.
 
 %-----------------------------------------------------------------------------%
Index: library/math.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/math.m,v
retrieving revision 1.42
diff -u -d -r1.42 math.m
--- library/math.m	22 Feb 2003 11:17:35 -0000	1.42
+++ library/math.m	14 May 2003 08:42:12 -0000
@@ -548,7 +548,7 @@
 		[thread_safe, promise_pure], "
 	Log2 = System.Math.Log(X) / ML_FLOAT_LN2;
 ").
-math__log10_2(X) = math__ln_2(X) / math__ln_2(2.0).
+math__log2_2(X) = math__ln_2(X) / math__ln_2(2.0).
 
 %
 % math__log(B, X) = Log is true if Log is the logarithm to
@@ -582,7 +582,7 @@
 		[thread_safe, promise_pure], "
 	Log = System.Math.Log(X, B);
 ").
-math__log_2(X, B) = math__ln_2(X) / math__log_2(B).
+math__log_2(X, B) = math__ln_2(X) / math__ln_2(B).
 
 %
 % math__sin(X) = Sin is true if Sin is the sine of X.
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.118
diff -u -d -r1.118 private_builtin.m
--- library/private_builtin.m	13 May 2003 08:51:59 -0000	1.118
+++ library/private_builtin.m	14 May 2003 08:49:57 -0000
@@ -1220,4 +1220,56 @@
 "").
 
 %-----------------------------------------------------------------------------%
+
+:- pragma foreign_code("Java", "
+//    public static class type_info_1
+//     {
+//	public int                              arity;
+//	public int                              type_ctor_version;
+//	public mercury.runtime.TypeCtorRep      type_ctor_rep;
+//	public int                              type_ctor_num_ptags; // if DU
+//	public mercury.runtime.MethodPtr        unify_pred;
+//	public mercury.runtime.MethodPtr        compare_pred;
+//	public java.lang.String                 type_ctor_module_name;
+//	public java.lang.String                 type_ctor_name;
+//	public mercury.runtime.TypeFunctors     type_functors;
+//	public mercury.runtime.TypeLayout       type_layout;
+//	public int 			        type_ctor_num_functors;
+//   }
+   
+    public static mercury.builtin.comparison_result_0 builtin_compare_int_3_p_0(int val1, int val2)
+     {
+        if(val1 == val2)
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_equal);
+	else if(val1 < val2)
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_less_than);
+	else
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_greater_than);
+	
+     }
+
+    public static mercury.builtin.comparison_result_0 builtin_compare_string_3_p_0(java.lang.String string1, java.lang.String string2)
+     {
+	int value = string1.compareTo(string2);
+	
+        if(value == 0)
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_equal);
+	else if(value < 0)
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_less_than);
+	else
+	     return new mercury.builtin.comparison_result_0(mercury.builtin.comparison_result_0.f_greater_than);
+     }
+    
+    public static int builtin_strcmp_3_p_0(java.lang.String string1, java.lang.String string2)
+     {
+        return string1.compareTo(string2);
+     }
+    
+    public static void compare_error_0_p_0()
+     {
+	throw new java.lang.Error(""internal error in compare/3"");
+     }
+").
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.283
diff -u -d -r1.283 std_util.m
--- library/std_util.m	3 Mar 2003 09:03:13 -0000	1.283
+++ library/std_util.m	14 May 2003 08:45:23 -0000
@@ -1420,10 +1420,27 @@
 	[will_not_call_mercury, thread_safe, promise_pure],
 	"Y = X;").
 
+:- pragma foreign_proc("Java",
+	cc_multi_equal(X::in, Y::out),
+	[will_not_call_mercury, thread_safe, promise_pure],
+	"Y = X;").
+:- pragma foreign_proc("Java",
+	cc_multi_equal(X::di, Y::uo),
+	[will_not_call_mercury, thread_safe, promise_pure],
+	"Y = X;").
+
+% We can't just use "true" and "fail" here, because that provokes warnings
+% from determinism analysis, and the library is compiled with --halt-at-warn.
+% So instead we use 0+0 = (or \=) 0.
+% This is guaranteed to succeed or fail (respectively),
+% and with a bit of luck will even get optimized by constant propagation.
+% But this optimization won't happen until after determinism analysis,
+% which doesn't know anything about integer arithmetic,
+% so this code won't provide a warning from determinism analysis.
 semidet_succeed :-
-	true.
+	0 + 0 = 0.
 semidet_fail :-
-	fail.
+	0 + 0 \= 0.
 
 :- pragma promise_pure(cc_multi_equal/2).
 cc_multi_equal(X, X).
Index: library/store.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/store.m,v
retrieving revision 1.37
diff -u -d -r1.37 store.m
--- library/store.m	22 Feb 2003 11:17:35 -0000	1.37
+++ library/store.m	14 May 2003 08:42:49 -0000
@@ -246,7 +246,10 @@
 % The store type itself is just a dummy type,
 % with no real representation.
 
-:- type store(S) ---> store(c_pointer).
+	% XXX we use `mkstore' here rather than `store' to work
+	%     around a bug with the Java back-end: it generates
+	%     invalid Java code if we use `store'.
+:- type store(S) ---> mkstore(c_pointer).
 
 % Mutvars and references are each represented as a pointer to a single word
 % on the heap.
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.198
diff -u -d -r1.198 string.m
--- library/string.m	9 May 2003 09:10:37 -0000	1.198
+++ library/string.m	14 May 2003 08:49:57 -0000
@@ -2963,7 +2963,7 @@
 	SUCCESS_INDICATOR = (Str->IndexOf(Ch) != -1);
 ").
 string__contains_char(String, Char) :-
-	string__contains_char(String, Char, 0, string__length(Char)).
+	string__contains_char(String, Char, 0, string__length(String)).
 
 :- pred string__contains_char(string::in, char::in,
 		int::in, int::in) is semidet.
@@ -2998,7 +2998,6 @@
 
 :- pred string__index_check(int, int).
 :- mode string__index_check(in, in) is semidet.
-:- pragma promise_pure(string__index_check/2).
 /* We should consider making this routine a compiler built-in. */
 :- pragma foreign_proc("C",
 	string__index_check(Index::in, Length::in),
@@ -3215,6 +3214,12 @@
 "
 	Length = Str->get_Length();
 ").
+:- pragma foreign_proc("Java",
+	string__length(Str::in, Length::uo),
+		[will_not_call_mercury, promise_pure, thread_safe], "
+	Length = Str.length();
+").
+
 
 /*
 :- pred string__length(string, int).
@@ -3232,6 +3237,11 @@
 "
 	Length = Str->get_Length();
 ").
+:- pragma foreign_proc("Java",
+	string__length(Str::ui, Length::uo),
+		[will_not_call_mercury, promise_pure, thread_safe], "
+	Length = Str.length();
+").
 
 :- pragma promise_pure(string__length/2).
 string__length(Str0, Len) :-
@@ -3526,7 +3536,7 @@
 string__split(Str, Count, Left, Right) :-
 	( Count =< 0 ->
 		Left = "",
-		Right = Str
+		copy(Str, Right)
 	;
 		string__to_char_list(Str, List),
 		Len = string__length(Str),
Index: library/type_desc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/type_desc.m,v
retrieving revision 1.19
diff -u -d -r1.19 type_desc.m
--- library/type_desc.m	3 Mar 2003 14:45:27 -0000	1.19
+++ library/type_desc.m	14 May 2003 08:45:25 -0000
@@ -321,6 +321,14 @@
 	TypeInfo = TypeInfo_for_T;
 ").
 
+:- pragma foreign_proc("Java",
+	type_of(_Value::unused) = (TypeInfo::out),
+	[will_not_call_mercury, thread_safe, promise_pure],
+"
+	TypeInfo = TypeInfo_for_T;
+").
+
+
 :- pragma foreign_proc("C", 
 	has_type(_Arg::unused, TypeInfo::in),
 	[will_not_call_mercury, thread_safe, promise_pure],
@@ -335,6 +343,14 @@
 	TypeInfo_for_T = TypeInfo;
 ").
 
+:- pragma foreign_proc("Java", 
+	has_type(_Arg::unused, TypeInfo::in),
+	[will_not_call_mercury, thread_safe, promise_pure],
+"
+	TypeInfo_for_T = TypeInfo;
+").
+
+
 % Export this function in order to use it in runtime/mercury_trace_external.c
 :- pragma export(type_name(in) = out, "ML_type_name").
 
@@ -593,5 +609,16 @@
 get_type_info_for_type_info = TypeDesc :-
 	Type = type_of(1),
 	TypeDesc = type_of(Type).
+
+%-----------------------------------------------------------------------------%
+
+:- pragma foreign_code("Java", "
+	public class type_desc_0 {
+		// ...
+	}
+	public class type_ctor_desc_0 {
+		// ...
+	}
+").
 
 %-----------------------------------------------------------------------------%

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