for review: begin type_ctor_* simplification

Tyson Dowd trd at cs.mu.OZ.AU
Tue Apr 6 20:03:55 AEST 1999


Hi,

Anyone who has read the RTTI paper can review this.

===================================================================


Estimated hours taken: 7

Start the changes needed to simplify type_ctor_*.

This simplification involves lifting the most important information
about the type representation out of type_ctor_layout and
type_ctor_functors and putting it into type_ctor_info.  In many
cases this will mean we can do without type_ctor_layout altogether,
and we will be able to remove the "functors indicator" from
type_ctor_functors.  The type_ctor_layout can be simplified quite a bit
because it only needs to describe discriminated unions.

compiler/base_type_info.m:
compiler/base_type_layout.m:
compiler/dead_proc_elim.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/polymorphism.m:
	Add code to generate the new MR_TypeCtorRepresentation
	field.
	Don't actually generate it yet, we need to bootstrap this
	change.  So we create two references to type_info_layouts
	instead.  When the compiler has bootstrapped we can change
	the runtime to use the later reference, and convert the
	earlier reference into MR_TypeCtorRepresentation.

library/builtin.m:
library/private_builtin.m:
runtime/mercury_bootstrap.c:
runtime/mercury_type_info.c:
	Add the new field to type_ctor_infos defined in C.
	Fix a few minor bugs with these type_ctor_infos (incorrect
	lengths of string constants, lingering references to
	term_to_type preds.

runtime/mercury_type_info.h:
	Move the offset for type name and module name down one.
	This won't cause any bootstrapping problems because the compiler
	barely uses such names.

	Add new types:
		MR_TypeCtorInfo
			This struct will replace MR_TYPE_CTOR_INFO_*
			macros and offsets.

		MR_TypeCtorRepresentation
		MR_DiscUnionTagRepresentation
			Will replace the more expensive to compute
			MR_DataRepresentation.


Index: compiler/base_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_info.m,v
retrieving revision 1.22
diff -u -r1.22 base_type_info.m
--- base_type_info.m	1999/03/22 08:07:02	1.22
+++ base_type_info.m	1999/04/06 09:55:12
@@ -96,7 +96,8 @@
 				Elim = yes(NumSpecials)
 			),
 			Info = base_gen_info(TypeId, ModuleName,
-				TypeName, TypeArity, Status, Elim, Procs),
+				TypeName, TypeArity, Status, Elim, Procs,
+				TypeDefn),
 			BaseGenInfos = [Info | BaseGenInfos1]
 		;
 			BaseGenInfos = BaseGenInfos1
@@ -138,7 +139,7 @@
 base_type_info__construct_type_ctor_infos([BaseGenInfo | BaseGenInfos],
 		ModuleInfo, [CModule | CModules]) :-
 	BaseGenInfo = base_gen_info(_TypeId, ModuleName, TypeName, TypeArity,
-		_Status, Elim, Procs),
+		_Status, Elim, Procs, HldsDefn),
 	base_type_info__construct_pred_addrs(Procs, Elim, ModuleInfo, 
 		PredAddrArgs),
 	ArityArg = yes(const(int_const(TypeArity))),
@@ -161,11 +162,20 @@
 			TypeArity, LayoutArg),
 		base_type_info__construct_functors(ModuleInfo, TypeName,
 			TypeArity, FunctorsArg),
+		base_type_info__construct_type_ctor_representation(HldsDefn,
+			_TypeCtorArg),
+			% XXX we put the layout argument twice.
+			% this is just temporary for bootstrapping
+			% purposes.  We will replace the LayoutArg with
+			% TypeCtorArg when the installed compiler
+			% generates the layout in a later slot, and
+			% change the #defines runtime/mercury_type_info.h
+			% to use the later slot.
 		prog_out__sym_name_to_string(ModuleName, ModuleNameString),
 		NameArg = yes(const(string_const(TypeName))),
 		ModuleArg = yes(const(string_const(ModuleNameString))),
-		list__append(PredAddrArgs, [LayoutArg, FunctorsArg, ModuleArg,
-			NameArg], FinalArgs)
+		list__append(PredAddrArgs, [LayoutArg, FunctorsArg, LayoutArg,
+			ModuleArg, NameArg], FinalArgs)
 	;
 		FinalArgs = PredAddrArgs
 	),
@@ -235,3 +245,79 @@
 	code_util__make_entry_label(ModuleInfo, PredId, ProcId, no, PredAddr),
 	PredAddrArg = yes(const(code_addr_const(PredAddr))),
 	base_type_info__construct_pred_addrs2(Procs, ModuleInfo, PredAddrArgs).
+
+
+:- type type_ctor_representation 
+	--->	enum
+	;	du
+	;	notag
+	;	equiv
+	;	int
+	;	char
+	;	float
+	;	string
+	;	(pred)
+	;	univ
+	;	void
+	;	c_pointer
+	;	typeinfo
+	;	typeclassinfo
+	;	array
+	;	unknown.
+
+:- pred base_type_info__type_ctor_rep_to_int(type_ctor_representation::in,
+	int::out) is det.
+base_type_info__type_ctor_rep_to_int(enum, 0).
+base_type_info__type_ctor_rep_to_int(du, 1).
+base_type_info__type_ctor_rep_to_int(notag, 2).
+base_type_info__type_ctor_rep_to_int(equiv, 3).
+base_type_info__type_ctor_rep_to_int(int, 4).
+base_type_info__type_ctor_rep_to_int(char, 5).
+base_type_info__type_ctor_rep_to_int(float, 6).
+base_type_info__type_ctor_rep_to_int(string, 7).
+base_type_info__type_ctor_rep_to_int(pred, 8).
+base_type_info__type_ctor_rep_to_int(univ, 9).
+base_type_info__type_ctor_rep_to_int(void, 10).
+base_type_info__type_ctor_rep_to_int(c_pointer, 11).
+base_type_info__type_ctor_rep_to_int(typeinfo, 12).
+base_type_info__type_ctor_rep_to_int(typeclassinfo, 13).
+base_type_info__type_ctor_rep_to_int(array, 14).
+base_type_info__type_ctor_rep_to_int(unknown, 15).
+
+
+:- pred base_type_info__construct_type_ctor_representation(hlds_type_defn,
+		maybe(rval)).
+:- mode base_type_info__construct_type_ctor_representation(in, out) is det.
+
+base_type_info__construct_type_ctor_representation(HldsType, Rvals) :-
+	hlds_data__get_type_defn_body(HldsType, TypeBody),
+	(
+		TypeBody = uu_type(_Alts),
+		error("base_type_info__construct_type_ctor_representation: sorry, undiscriminated union unimplemented\n")
+	;
+		TypeBody = eqv_type(_Type),
+		TypeCtorRep = equiv
+	;
+		TypeBody = abstract_type,
+		TypeCtorRep = unknown
+	;
+		TypeBody = du_type(Ctors, _ConsTagMap, Enum, _EqualityPred),
+		(
+			Enum = yes,
+			TypeCtorRep = enum
+		;
+			Enum = no,
+			( 
+				type_is_no_tag_type(Ctors, _Name, _TypeArg)
+			->
+				TypeCtorRep = notag
+			;
+				TypeCtorRep = du
+			)
+		)
+	),
+	base_type_info__type_ctor_rep_to_int(TypeCtorRep, TypeCtorRepInt),
+	Rvals = yes(const(int_const(TypeCtorRepInt))).
+
+
+
Index: compiler/base_type_layout.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_type_layout.m,v
retrieving revision 1.40
diff -u -r1.40 base_type_layout.m
--- base_type_layout.m	1999/03/24 03:11:12	1.40
+++ base_type_layout.m	1999/04/06 09:55:17
@@ -234,6 +234,7 @@
 :- pred base_type_layout__construct_pseudo_type_info(type, rval, int, int).
 :- mode base_type_layout__construct_pseudo_type_info(in, out, in, out) is det.
 
+
 :- implementation.
 
 :- import_module hlds_data, hlds_pred, hlds_out, type_util.
Index: compiler/dead_proc_elim.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/dead_proc_elim.m,v
retrieving revision 1.44
diff -u -r1.44 dead_proc_elim.m
--- dead_proc_elim.m	1999/03/22 08:07:06	1.44
+++ dead_proc_elim.m	1999/04/06 09:55:19
@@ -176,7 +176,7 @@
 dead_proc_elim__initialize_base_gen_infos([BaseGenInfo | BaseGenInfos],
 		Queue0, Queue, Needed0, Needed) :-
 	BaseGenInfo = base_gen_info(_TypeId, ModuleName, TypeName,
-		Arity, _Status, _Elim, _Procs),
+		Arity, _Status, _Elim, _Procs, _HldsDefn),
 	(
 		% XXX: We'd like to do this, but there are problems.
 		% status_is_exported(Status, yes)
@@ -322,7 +322,7 @@
 		[BaseGenInfo | BaseGenInfos], Refs) :-
 	(
 		BaseGenInfo = base_gen_info(_TypeId, ModuleName, TypeName,
-			TypeArity, _Status, _Elim, Refs0)
+			TypeArity, _Status, _Elim, Refs0, _HldsDefn)
 	->
 		Refs = Refs0
 	;
@@ -626,7 +626,7 @@
 	dead_proc_elim__eliminate_base_gen_infos(BaseGenInfos0, Needed,	
 		BaseGenInfos1),
 	BaseGenInfo0 = base_gen_info(TypeId, ModuleName, TypeName,
-		Arity, Status, Elim0, Procs),
+		Arity, Status, Elim0, Procs, HldsDefn),
 	(
 		Entity = base_gen_info(ModuleName, TypeName, Arity),
 		map__search(Needed, Entity, _)
@@ -645,7 +645,8 @@
 			NumProcs = ProcsLength
 		),
 		NeuteredBaseGenInfo = base_gen_info(TypeId, ModuleName, 
-			TypeName, Arity, Status, yes(NumProcs), []),
+			TypeName, Arity, Status, yes(NumProcs), [],
+			HldsDefn),
 		BaseGenInfos = [NeuteredBaseGenInfo | BaseGenInfos1]
 	).
 
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_data.m,v
retrieving revision 1.32
diff -u -r1.32 hlds_data.m
--- hlds_data.m	1999/03/22 08:07:11	1.32
+++ hlds_data.m	1999/04/06 09:55:21
@@ -207,7 +207,7 @@
 
 	% An `hlds_type_body' holds the body of a type definition:
 	% du = discriminated union, uu = undiscriminated union,
-	% eqv_type = equivalence type (a type defined to be equivalen
+	% eqv_type = equivalence type (a type defined to be equivalent
 	% to some other type)
 
 :- type hlds_type_body
Index: compiler/hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.41
diff -u -r1.41 hlds_module.m
--- hlds_module.m	1999/03/22 08:07:13	1.41
+++ hlds_module.m	1999/04/06 09:55:28
@@ -63,10 +63,11 @@
 			import_status,	% of the type
 			maybe(int),	% eliminated procs?
 					% and how many if so
-			list(pred_proc_id)
+			list(pred_proc_id),
 					% the ids of the procs
 					% referred to from the
 					% type_ctor_info
+			hlds_type_defn	% defn of type
 		).
 
 	% This structure contains the information we need to generate
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.161
diff -u -r1.161 polymorphism.m
--- polymorphism.m	1999/03/24 03:11:13	1.161
+++ polymorphism.m	1999/04/06 09:55:33
@@ -44,12 +44,13 @@
 %	word 1		<=/2 predicate for type>
 %	word 2		<index/2 predicate for type>
 %	word 3		<compare/3 predicate for type>
-%	word 4		<type_ctor_layout for type>
+%	word 4		<MR_TypeCtorRepresentation for type constructor>
 %	word 5		<type_ctor_functors for type>
-%	word 6		<string name of type constructor>
+%	word 6		<type_ctor_layout for type>
+%	word 7		<string name of type constructor>
 %			e.g. "int" for `int', "list" for `list(T)',
 %			"map" for `map(K,V)'
-%	word 7		<string name of module>
+%	word 8		<string name of module>
 %
 % The other cell is the type_info structure, laid out like this:
 %
cvs server: Diffing compiler/notes
cvs server: Diffing debian
cvs server: Diffing doc
cvs server: Diffing extras
cvs server: Diffing extras/aditi
cvs server: Diffing extras/cgi
cvs server: Diffing extras/complex_numbers
cvs server: Diffing extras/complex_numbers/samples
cvs server: Diffing extras/complex_numbers/tests
cvs server: Diffing extras/dynamic_linking
cvs server: Diffing extras/exceptions
cvs server: Diffing extras/graphics
cvs server: Diffing extras/graphics/mercury_opengl
cvs server: Diffing extras/graphics/mercury_tcltk
cvs server: Diffing extras/graphics/samples
cvs server: Diffing extras/graphics/samples/calc
cvs server: Diffing extras/graphics/samples/maze
cvs server: Diffing extras/graphics/samples/pent
cvs server: Diffing extras/lazy_evaluation
cvs server: Diffing extras/odbc
cvs server: Diffing extras/references
cvs server: Diffing extras/references/samples
cvs server: Diffing extras/references/tests
cvs server: Diffing extras/trailed_update
cvs server: Diffing extras/trailed_update/samples
cvs server: Diffing extras/trailed_update/tests
cvs server: Diffing library
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.10
diff -u -r1.10 builtin.m
--- builtin.m	1999/03/22 08:08:41	1.10
+++ builtin.m	1999/04/06 09:55:36
@@ -362,6 +362,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 #endif
 } mercury_data___type_ctor_info_int_0 = {
 	((Integer) 0),
@@ -371,7 +372,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_int_0,
 	(const Word *) & mercury_data___type_ctor_functors_int_0,
-	(const Word *) string_const(""builtin"", 15),
+	(const Word *) & mercury_data___type_ctor_layout_int_0,
+	(const Word *) string_const(""builtin"", 7),
 	(const Word *) string_const(""int"", 3)
 #endif
 };
@@ -392,6 +394,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 #endif
 } mercury_data___type_ctor_info_character_0 = {
 	((Integer) 0),
@@ -401,7 +404,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_character_0,
 	(const Word *) & mercury_data___type_ctor_functors_character_0,
-	(const Word *) string_const(""builtin"", 15),
+	(const Word *) & mercury_data___type_ctor_layout_character_0,
+	(const Word *) string_const(""builtin"", 7),
 	(const Word *) string_const(""character"", 9)
 #endif
 };
@@ -421,6 +425,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 #endif
 } mercury_data___type_ctor_info_string_0 = {
 	((Integer) 0),
@@ -430,7 +435,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_string_0,
 	(const Word *) & mercury_data___type_ctor_functors_string_0,
-	(const Word *) string_const(""builtin"", 15),
+	(const Word *) & mercury_data___type_ctor_layout_string_0,
+	(const Word *) string_const(""builtin"", 7),
 	(const Word *) string_const(""string"", 6)
 #endif
 };
@@ -450,6 +456,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 #endif
 } mercury_data___type_ctor_info_float_0 = {
 	((Integer) 0),
@@ -459,7 +466,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_float_0,
 	(const Word *) & mercury_data___type_ctor_functors_float_0,
-	(const Word *) string_const(""builtin"", 15),
+	(const Word *) & mercury_data___type_ctor_layout_float_0,
+	(const Word *) string_const(""builtin"", 7),
 	(const Word *) string_const(""float"", 5)
 #endif
 };
@@ -477,6 +485,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 #endif
 } mercury_data___type_ctor_info_void_0 = {
 	((Integer) 0),
@@ -486,7 +495,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_void_0,
 	(const Word *) & mercury_data___type_ctor_functors_void_0,
-	(const Word *) string_const(""builtin"", 15),
+	(const Word *) & mercury_data___type_ctor_layout_void_0,
+	(const Word *) string_const(""builtin"", 7),
 	(const Word *) string_const(""void"", 4)
 #endif
 };
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.17
diff -u -r1.17 private_builtin.m
--- private_builtin.m	1999/03/22 08:08:43	1.17
+++ private_builtin.m	1999/04/06 09:55:40
@@ -1335,6 +1335,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 } mercury_data_private_builtin__type_ctor_info_type_ctor_info_1 = {
 	((Integer) 1),
 	MR_MAYBE_STATIC_CODE(ENTRY(
@@ -1347,6 +1348,8 @@
 		mercury_data_private_builtin__type_ctor_layout_type_info_1,
 	(const Word *) &
 		mercury_data_private_builtin__type_ctor_functors_type_info_1,
+	(const Word *) &
+		mercury_data_private_builtin__type_ctor_layout_type_info_1,
 	(const Word *) string_const(""private_builtin"", 15),
 	(const Word *) string_const(""type_ctor_info"", 14)
 };
@@ -1361,6 +1364,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 } mercury_data_private_builtin__type_ctor_info_type_info_1 = {
 	((Integer) 1),
 	MR_MAYBE_STATIC_CODE(ENTRY(
cvs server: Diffing lp_solve
cvs server: Diffing lp_solve/lp_examples
cvs server: Diffing profiler
cvs server: Diffing readline
cvs server: Diffing readline/doc
cvs server: Diffing readline/examples
cvs server: Diffing readline/shlib
cvs server: Diffing readline/support
cvs server: Diffing runtime
Index: runtime/mercury_bootstrap.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_bootstrap.c,v
retrieving revision 1.7
diff -u -r1.7 mercury_bootstrap.c
--- mercury_bootstrap.c	1999/03/22 08:09:00	1.7
+++ mercury_bootstrap.c	1999/04/06 09:55:40
@@ -49,6 +49,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 } mercury_data_private_builtin__type_ctor_info_base_typeclass_info_1 = {
 	((Integer) 1),
 	MR_MAYBE_STATIC_CODE(ENTRY(
@@ -61,6 +62,8 @@
 	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	(const Word *) &
 	    mercury_data_private_builtin__type_ctor_functors_typeclass_info_1,
+	(const Word *) &
+	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	(const Word *) string_const("private_builtin", 15),
 	(const Word *) string_const("base_typeclass_info", 19)
 };
@@ -75,6 +78,7 @@
 	const Word *f6;
 	const Word *f7;
 	const Word *f8;
+	const Word *f9;
 } mercury_data_private_builtin__type_ctor_info_typeclass_info_1 = {
 	((Integer) 1),
 	MR_MAYBE_STATIC_CODE(ENTRY(
@@ -87,6 +91,8 @@
 	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	(const Word *) &
 	    mercury_data_private_builtin__type_ctor_functors_typeclass_info_1,
+	(const Word *) &
+	    mercury_data_private_builtin__type_ctor_layout_typeclass_info_1,
 	(const Word *) string_const("private_builtin", 15),
 	(const Word *) string_const("typeclass_info", 14)
 };
Index: runtime/mercury_type_info.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.c,v
retrieving revision 1.17
diff -u -r1.17 mercury_type_info.c
--- mercury_type_info.c	1999/03/22 08:09:07	1.17
+++ mercury_type_info.c	1999/04/06 09:55:41
@@ -55,11 +55,9 @@
 	Code *f2;
 	Code *f3;
 	Code *f4;
-#ifdef USE_TYPE_TO_TERM
-	Code *f5;
-	Code *f6;
-#endif
 #ifdef USE_TYPE_LAYOUT
+	const Word *f5;
+	const Word *f6;
 	const Word *f7;
 	const Word *f8;
 	const Word *f9;
@@ -72,6 +70,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_pred_0,
 	(const Word *) & mercury_data___type_ctor_functors_pred_0,
+	(const Word *) & mercury_data___type_ctor_layout_pred_0,
+	(const Word *) string_const("builtin", 7),
 	(const Word *) string_const("func", 4)
 #endif
 };
@@ -89,11 +89,9 @@
 	Code *f2;
 	Code *f3;
 	Code *f4;
-#ifdef USE_TYPE_TO_TERM
-	Code *f5;
-	Code *f6;
-#endif
 #ifdef USE_TYPE_LAYOUT
+	const Word *f5;
+	const Word *f6;
 	const Word *f7;
 	const Word *f8;
 	const Word *f9;
@@ -106,6 +104,8 @@
 #ifdef  USE_TYPE_LAYOUT
 	(const Word *) & mercury_data___type_ctor_layout_pred_0,
 	(const Word *) & mercury_data___type_ctor_functors_pred_0,
+	(const Word *) & mercury_data___type_ctor_layout_pred_0,
+	(const Word *) string_const("builtin", 7),
 	(const Word *) string_const("pred", 4)
 #endif
 };
Index: runtime/mercury_type_info.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_type_info.h,v
retrieving revision 1.16
diff -u -r1.16 mercury_type_info.h
--- mercury_type_info.h	1999/03/22 08:09:08	1.16
+++ mercury_type_info.h	1999/04/06 09:55:43
@@ -38,8 +38,8 @@
 #define OFFSET_FOR_COMPARE_PRED 3
 #define OFFSET_FOR_BASE_TYPE_LAYOUT 4
 #define OFFSET_FOR_BASE_TYPE_FUNCTORS 5
-#define OFFSET_FOR_TYPE_MODULE_NAME 6
-#define OFFSET_FOR_TYPE_NAME 7
+#define OFFSET_FOR_TYPE_MODULE_NAME 7
+#define OFFSET_FOR_TYPE_NAME 8
 
 /*
 ** Define offsets of fields in the type_info structure.
@@ -116,7 +116,7 @@
 /*
 ** Definitions and macros for type_ctor_layout definition.
 **
-** See compiler/type_ctor_layout.m for more information.
+** See compiler/base_type_layout.m for more information.
 **
 ** If we don't have enough tags, we have to encode layouts
 ** less densely. The make_typelayout macro does this, and
@@ -230,7 +230,7 @@
 ** used for anything.
 **
 ** Changes in this type may need to be reflected in
-** compiler/type_ctor_layout.m.
+** compiler/base_type_layout.m.
 **
 */
 
@@ -665,6 +665,7 @@
 
 /*---------------------------------------------------------------------------*/
 
+
 	/* 
 	** Macros for retreiving things from type_infos and
 	** type_ctor_infos
@@ -699,7 +700,7 @@
 #if 0
 
 	/* XXX: We should use structs to represent the various
-	** data structures in the functors and layouts.
+	** data structures in the type_ctor_*
 	**
 	** To implement this: 
 	** 	1. The code that uses the data in the library and
@@ -717,12 +718,31 @@
 
         /*
         **         ** IMPORTANT: the layout in memory of the following
-        **         struct must match the way that the Mercury compiler
-        **         generates code for it.
+        **         structs must match the way that the Mercury compiler
+        **         generates code for them.
         */         
 
 
+	/*
+	** Structs defining the structure of type_ctor_infos.
+	**
+	** XXX this is not used yet but we are aiming towards
+	** this structure.
+	*/
+
 typedef struct {
+	int arity;
+	Code *unify_pred;
+	Code *index_pred;
+	Code *compare_pred;
+	MR_TypeCtorRepresentation type_ctor_rep;
+	MR_TypeCtorFunctors type_ctor_functors;
+	MR_TypeCtorLayout type_ctor_layout;
+	String type_ctor_name;
+	String type_ctor_module_name;
+} MR_TypeCtorInfo;
+
+typedef struct {
 	Word arity;
 	Word arg1;		
 /* other arguments follow, there are arity of them,
@@ -801,11 +821,58 @@
 ** defintions and functions for categorizing data representations.
 */
 
+/*
+** MR_DataRepresentation is the representation for a particular type
+** constructor.  For the cases of MR_TYPE_CTOR_REP_DU the exact
+** representation depends on the tag value -- lookup the tag value in
+** type_ctor_layout to find out this information.
+**
+** 
+*/
+enum MR_TypeCtorRepresentation {
+	MR_TYPE_CTOR_REP_ENUM,
+	MR_TYPE_CTOR_REP_DU,
+	MR_TYPE_CTOR_REP_NOTAG,
+	MR_TYPE_CTOR_REP_EQUIV,
+	MR_TYPE_CTOR_REP_EQUIV_VAR,
+	MR_TYPE_CTOR_REP_INT,
+	MR_TYPE_CTOR_REP_CHAR,
+	MR_TYPE_CTOR_REP_FLOAT,
+	MR_TYPE_CTOR_REP_STRING,
+	MR_TYPE_CTOR_REP_PRED,
+	MR_TYPE_CTOR_REP_UNIV,
+	MR_TYPE_CTOR_REP_VOID,
+	MR_TYPE_CTOR_REP_C_POINTER,
+	MR_TYPE_CTOR_REP_TYPEINFO,
+	MR_TYPE_CTOR_REP_TYPECLASSINFO,
+	MR_TYPE_CTOR_REP_ARRAY,
+	MR_TYPE_CTOR_REP_UNKNOWN
+};
+
+/*
+** If the MR_TypeCtorRepresentation is MR_TYPE_CTOR_REP_DU, we have a
+** discriminated union type (other than a no-tag or enumeration).  Each
+** tag may have a different representation.
+*/
+enum MR_DiscUnionTagRepresentation {
+	MR_DISCUNIONTAG_SHARED_LOCAL,
+	MR_DISCUNIONTAG_UNSHARED,
+	MR_DISCUNIONTAG_SHARED_REMOTE
+};
 
 /*
+** MR_DataRepresentation is the representation for a particular value
+** of a type with this constructor.  It is similar to the
+** MR_TypeCtorRepresentaion but you need to know the primary tag value
+** (and, therefore, must have the data around to examine) to tell the
+** different cases for discriminated unions apart.
+**
 ** These have been ordered so that the most similar cases are next
 ** to each other, so a switch on this type can exploit fallthrough
 ** to cut down on code duplication.
+** 
+** XXX this type will be replaced by a combination of MR_TypeCtorRepresentaion
+** and MR_DiscUnionTagRepresentation.
 */
 enum MR_DataRepresentation {
 	MR_DATAREP_ENUM,
@@ -828,6 +895,7 @@
 	MR_DATAREP_UNKNOWN,
 	MR_DATAREP_TYPECLASSINFO
 };
+
 
 /*
 ** Return the data representation used by the data with the given
cvs server: Diffing runtime/GETOPT
cvs server: Diffing runtime/machdeps
cvs server: Diffing samples
cvs server: Diffing samples/c_interface
cvs server: Diffing samples/c_interface/c_calls_mercury
cvs server: Diffing samples/c_interface/cplusplus_calls_mercury
cvs server: Diffing samples/c_interface/mercury_calls_c
cvs server: Diffing samples/c_interface/mercury_calls_cplusplus
cvs server: Diffing samples/c_interface/mercury_calls_fortran
cvs server: Diffing samples/c_interface/simpler_c_calls_mercury
cvs server: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs server: Diffing samples/diff
cvs server: Diffing samples/muz
cvs server: Diffing samples/rot13
cvs server: Diffing scripts
cvs server: Diffing tests
cvs server: Diffing tests/benchmarks
cvs server: Diffing tests/debugger
cvs server: Diffing tests/dppd
cvs server: Diffing tests/general
cvs server: Diffing tests/hard_coded
cvs server: Diffing tests/hard_coded/sub-modules
cvs server: Diffing tests/hard_coded/typeclasses
cvs server: Diffing tests/invalid
cvs server: Diffing tests/misc_tests
cvs server: Diffing tests/tabling
cvs server: Diffing tests/term
cvs server: Diffing tests/valid
cvs server: Diffing tests/warnings
cvs server: Diffing tools
cvs server: Diffing trace
cvs server: Diffing trial
cvs server: Diffing util


-- 
The quantum sort: 
	while (!sorted) { do_nothing(); }
Tyson Dowd   <tyson at tyse.net>   http://tyse.net/



More information about the developers mailing list