[m-rev.] for review: read .opt files transitively

Tyson Dowd trd at cs.mu.OZ.AU
Thu Apr 19 22:06:34 AEST 2001


On 18-Apr-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Here's (a first draft of) a change to read in the `.opt' files transitively.
> See my post to mercury-developers for detailed rationale.
> 
> With this change, `tools/bootcheck --grade il' gets as far as building all
> the `.opt' and `.trans_opt' files, but dies when compiling benchmarking.m;
> the problem there is an unrelated one, namely that the IL back-end doesn't
> support nested classes.


Here's an initial "fix" for the nested classes problem in IL.
This will allow the nested classes to be generated (so the compiler
should continue to run), although the code that is generated for the
nested classes is not yet quite right (due to a few lingering
assumptions that any non top-level classes will be continuation
environments).

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


Estimated hours taken: 1
Branches: main

Add initial support for nested classes.

compiler/ilasm.m:
	Add code to allow nested classes in the IL assembler.
	

compiler/mlds_to_il.m:
	Add a simple definition to generate nested classes.


Index: compiler/ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ilasm.m,v
retrieving revision 1.7
diff -u -r1.7 ilasm.m
--- compiler/ilasm.m	2001/04/11 10:17:22	1.7
+++ compiler/ilasm.m	2001/04/19 11:17:52
@@ -117,6 +117,15 @@
 			maybe(int32),		% offset for explicit layout
 			field_initializer	% initializer
 		)
+		% .class (a nested class)
+	;	nested_class(
+			list(classattr),	% attributes for the class
+			ilds__id,		% name of the class
+			extends,		% what is the parent class
+			implements, 		% what interfaces are 
+						% implemented
+			list(classdecl)		% methods and fields
+		)
 		% comments
 	;	comment_term(term)
 	;	comment(string)
@@ -417,6 +426,11 @@
 	io__write_string(" "),
 	output_id(IlId),
 	output_field_initializer(Initializer).
+
+ilasm__output_classdecl(nested_class(Attrs, Id, Extends, Implements, Contents),
+		Info0, Info) --> 
+	ilasm__output_decl(class(Attrs, Id, Extends, Implements, Contents),
+		Info0, Info).
 
 ilasm__output_classdecl(comment(CommentStr), Info, Info) --> 
 	globals__io_lookup_bool_option(auto_comments, PrintComments),
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.18
diff -u -r1.18 mlds_to_il.m
--- compiler/mlds_to_il.m	2001/04/11 10:17:22	1.18
+++ compiler/mlds_to_il.m	2001/04/19 11:57:04
@@ -663,12 +663,19 @@
 	mlds__function(_PredProcId, _Params, _MaybeStatements)), ILClassDecl) :-
 		ILClassDecl = comment("unimplemented: functions in classes").
 
-	% XXX this might not need to be implemented (nested classes)
-	% since it will probably be flattened earlier.
-defn_to_class_decl(mlds__defn(_Name, _Context, _DeclFlags,
-		mlds__class(_)), _ILClassDecl) :-
-	error("nested data definition not expected here").
-
+defn_to_class_decl(mlds__defn(EntityName, _Context, _DeclFlags,
+		mlds__class(ClassDefn)), ILClassDecl) :-
+	( EntityName = type(TypeName, _Arity) ->
+		ClassDefn = mlds__class_defn(_ClassType, _Imports, 
+			_Inherits, _Implements, Defns),
+		FullClassName = structured_name("", [TypeName]),
+		list__map(defn_to_class_decl, Defns, ILDefns),
+		make_constructor(FullClassName, ClassDefn, ConstructorILDefn),
+		ILClassDecl = nested_class([public], TypeName, extends_nothing,
+			implements([]), [ConstructorILDefn | ILDefns])
+	;
+		error("expected type entity name for a nested class")
+	).
 
 %-----------------------------------------------------------------------------%
 %
@@ -1780,13 +1787,8 @@
 	% see comments about function types above.
 mlds_type_to_ilds_type(mlds__cont_type(_ArgTypes)) = ilds__type([], int32).
 
-mlds_type_to_ilds_type(mlds__class_type(Class, _Arity, _Kind)) = ILType :-
-	Class = qual(MldsModuleName, MldsClassName),
-	structured_name(Assembly, ClassName) = 
-		mlds_module_name_to_class_name(MldsModuleName),
-	list__append(ClassName, [MldsClassName], FullClassName),
-	ILType = ilds__type([], class(
-		structured_name(Assembly, FullClassName))).
+mlds_type_to_ilds_type(mlds__class_type(Class, _Arity, _Kind)) = 
+	ilds__type([], class(mlds_class_name_to_ilds_class_name(Class))).
 
 mlds_type_to_ilds_type(mlds__commit_type) = il_commit_type.
 
@@ -1842,6 +1844,14 @@
 
 mlds_type_to_ilds_type(mlds__unknown_type) = _ :-
 	unexpected(this_file, "mlds_type_to_ilds_type: unknown_type").
+
+
+:- func mlds_class_name_to_ilds_class_name(mlds__class) = ilds__class_name.
+
+mlds_class_name_to_ilds_class_name(qual(MldsModuleName, MldsClassName)) = 
+	append_class_name(mlds_module_name_to_class_name(MldsModuleName),
+		[MldsClassName]).
+
 %-----------------------------------------------------------------------------
 %
 % Name mangling.


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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