[m-dev.] diff: fix typeclasses in jump/fast grades

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 4 15:20:31 AEDT 1999


Estimated hours taken: 2

Fix a bug which meant that type classes didn't work
in jump/fast grades.

compiler/llds_out.m:
	If we don't have static code addresses, then initialize
	the method pointers in base_typeclass_infos dynamically
	rather than statically.

Workspace: /home/mercury0/fjh/mercury
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.128
diff -u -d -r1.128 llds_out.m
--- llds_out.m	1999/11/04 03:26:47	1.128
+++ llds_out.m	1999/11/04 04:10:44
@@ -591,6 +591,13 @@
 		io__write_int(Arity),
 		io__write_string("_0);\n")
 	;
+		{ Data = comp_gen_c_data(ModuleName, DataName, _, ArgRvals, _, _) },
+		{ DataName = base_typeclass_info(_ClassName, _ClassArity) }
+	->
+		io__write_string("#ifndef MR_STATIC_CODE_ADDRESSES\n"),
+		output_init_method_pointers(1, ArgRvals, DataName, ModuleName),
+		io__write_string("#endif /* MR_STATIC_CODE_ADDRESSES */\n")
+	;
 		{ Data = comp_gen_c_data(ModuleName, DataName, _, _, _, _) },
 		{ DataName = module_layout }
 	->
@@ -604,6 +611,23 @@
 	),
 	output_c_data_init_list(Datas).
 
+:- pred output_init_method_pointers(int, list(maybe(rval)), data_name, module_name,
+	io__state, io__state).
+:- mode output_init_method_pointers(in, in, in, in, di, uo) is det.
+
+output_init_method_pointers(_, [], _, _) --> [].
+output_init_method_pointers(ArgNum, [Arg|Args], DataName, ModuleName) -->
+	( { Arg = yes(const(code_addr_const(CodeAddr))) } ->
+		io__write_string("\t\t"),
+		output_data_addr(ModuleName, DataName),
+		io__format(".f%d =\n\t\t\t", [i(ArgNum)]),
+		output_code_addr(CodeAddr),
+		io__write_string(";\n")
+	;
+		[]
+	),
+	output_init_method_pointers(ArgNum + 1, Args, DataName, ModuleName).
+
 	% Output a comment to tell mkinit what functions to
 	% call from <module>_init.c.
 :- pred output_init_comment(module_name, io__state, io__state).
@@ -2477,11 +2501,27 @@
 output_uniform_cons_args([Arg | Args], MaybeType, Indent) -->
 	( { Arg = yes(Rval) } ->
 		io__write_string(Indent),
-		( { MaybeType = yes(_) } ->
-			output_static_rval(Rval)
+		globals__io_get_globals(Globals),
+		(
+			%
+			% Don't output code_addr_consts if they are not 
+			% actually const; instead just output `NULL' here in
+			% the static initializer.  The value will be supplied
+			% by the dynamic initialization code.
+			%
+			{ Rval = const(code_addr_const(_)) },
+			{ globals__have_static_code_addresses(Globals,
+				StaticCode) },
+			{ StaticCode = no }
+		->
+			io__write_string("NULL")
 		;
-			llds_out__rval_type_as_arg(Rval, Type),
-			output_rval_as_type(Rval, Type)
+			( { MaybeType = yes(_) } ->
+				output_static_rval(Rval)
+			;
+				llds_out__rval_type_as_arg(Rval, Type),
+				output_rval_as_type(Rval, Type)
+			)
 		),
 		( { Args \= [] } ->
 			io__write_string(",\n"),

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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