diff --git a/compiler/make_hlds.m b/compiler/make_hlds.m index 8df2df02c..a352c629a 100644 --- a/compiler/make_hlds.m +++ b/compiler/make_hlds.m @@ -1261,7 +1261,7 @@ module_add_class_method(Method, Name, Vars, Status, MaybePredIdProcId, di, uo) is det. module_add_instance_defn(Module0, Constraints, Name, Types, Interface, VarSet, - Status, _Context, Module) --> + Status, Context, Module) --> { module_info_classes(Module0, Classes) }, { module_info_instances(Module0, Instances0) }, { list__length(Types, ClassArity) }, @@ -1277,8 +1277,16 @@ module_add_instance_defn(Module0, Constraints, Name, Types, Interface, VarSet, Instances) }, { module_info_set_instances(Module0, Instances, Module) } ; - % XXX give an error since the class has not been - % XXX defined + io__stderr_stream(StdErr), + io__set_output_stream(StdErr, OldStream), + prog_out__write_context(Context), + io__write_string("Error: typeclass `"), + prog_out__write_sym_name(Name), + io__write_char('/'), + io__write_int(ClassArity), + io__write_string("' not defined.\n"), + io__set_exit_status(1), + io__set_output_stream(OldStream, _), { Module = Module0 } ). diff --git a/compiler/notes/compiler_design.html b/compiler/notes/compiler_design.html index ab08d22d3..c235fc562 100644 --- a/compiler/notes/compiler_design.html +++ b/compiler/notes/compiler_design.html @@ -313,12 +313,13 @@ in an HLDS goal. check_typeclass.m checks that, each instance declaration, that the types, modes and determinism of each predicate/function that is a method of the class is correct (ie. that it matches the typeclass - declaration). In this pass, pred_ids and proc_ids are assigned to - the methods for each instance. In addition, while checking that the - superclasses of a class are satisfied by the instance declaration, a - set of constraint_proofs are built up for the superclass constraints. - These are used by polymorphism.m when generating the - base_typeclass_info for the instance. + declaration). This pass is performed at the end of semantic analysis + because it needs mode and determinism information. In this pass, + pred_ids and proc_ids are assigned to the methods for each instance. In + addition, while checking that the superclasses of a class are satisfied + by the instance declaration, a set of constraint_proofs are built up + for the superclass constraints. These are used by polymorphism.m when + generating the base_typeclass_info for the instance.
simplification (simplify.m) @@ -792,6 +793,6 @@ Some of them are obsolete; other are work-in-progress.
-Last update was $Date: 1998-01-02 00:11:10 $ by $Author: fjh $@cs.mu.oz.au.
+Last update was $Date: 1998-01-07 06:09:44 $ by $Author: dgj $@cs.mu.oz.au.
diff --git a/compiler/prog_io.m b/compiler/prog_io.m index e9a1aadce..58e41abbe 100644 --- a/compiler/prog_io.m +++ b/compiler/prog_io.m @@ -102,6 +102,15 @@ :- pred parse_item(string, varset, term, maybe_item_and_context). :- mode parse_item(in, in, in, out) is det. + % parse_decl(ModuleName, VarSet, Term, Result) + % + % parse Term as a declaration. If successful, Result is bound to the + % parsed item, otherwise it is bound to an appropriate error message. + % Qualify appropriate parts of the item, with ModuleName as the module + % name. +:- pred parse_decl(string, varset, term, maybe_item_and_context). +:- mode parse_decl(in, in, in, out) is det. + %-----------------------------------------------------------------------------% %-----------------------------------------------------------------------------% @@ -436,11 +445,10 @@ convert_item(error(M, T), error(M, T)). parse_item(ModuleName, VarSet, Term, Result) :- ( %%% some [Decl, DeclContext] - Term = term__functor(term__atom(":-"), [Decl], DeclContext) + Term = term__functor(term__atom(":-"), [Decl], _DeclContext) -> % It's a declaration - parse_decl(ModuleName, VarSet, Decl, R), - add_context(R, DeclContext, Result) + parse_decl(ModuleName, VarSet, Decl, Result) ; %%% some [DCG_H, DCG_B, DCG_Context] % It's a DCG clause Term = term__functor(term__atom("-->"), [DCG_H, DCG_B], @@ -503,18 +511,14 @@ process_func_clause(error(ErrMessage, Term), _, _, _, error(ErrMessage, Term)). %-----------------------------------------------------------------------------% - % parse a declaration - -:- pred parse_decl(string, varset, term, maybe1(item)). -:- mode parse_decl(in, in, in, out) is det. parse_decl(ModuleName, VarSet, F, Result) :- ( - F = term__functor(term__atom(Atom), As, _Context) + F = term__functor(term__atom(Atom), As, Context) -> ( process_decl(ModuleName, VarSet, Atom, As, R) -> - Result = R + add_context(R, Context, Result) ; Result = error("unrecognized declaration", F) ) diff --git a/compiler/prog_io_typeclass.m b/compiler/prog_io_typeclass.m index 4850a06ff..0f35ae372 100644 --- a/compiler/prog_io_typeclass.m +++ b/compiler/prog_io_typeclass.m @@ -1,5 +1,5 @@ %-----------------------------------------------------------------------------% -% Copyright (C) 1997 University of Melbourne. +% Copyright (C) 1998 University of Melbourne. % This file may only be copied under the terms of the GNU General % Public License - see the file COPYING in the Mercury distribution. %-----------------------------------------------------------------------------% @@ -151,7 +151,7 @@ parse_class_methods(ModuleName, Methods, VarSet, Result) :- list__map(lambda([MethodTerm::in, Method::out] is det, ( % Turn the term into an item - parse_item(ModuleName, VarSet, MethodTerm, Item), + parse_decl(ModuleName, VarSet, MethodTerm, Item), % Turn the item into a class_method item_to_class_method(Item, MethodTerm, Method) )),