diff: add contexts to instance methods
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Wed Jul 29 20:27:51 AEST 1998
Hi Fergus,
Could you please review this?
------------------------------------------------------------------------
Estimated hours taken: 2
Remember the term__context of where we read an instance method from so that
we can give more accurate error messages. Also (slightly) improve the text of
the error message for instance methods.
check_typeclass.m:
Use the term__context of the instance method declaration as the
term__context for the introduced pred.
hlds_out.m:
If the pred is one introduced as an instance method, give a
(slightly) better error message.
mercury_to_mercury.m:
Ignore the term context.
module_qual.m:
Pass along the term context.
prog_data.m:
Add a term__context to the instance_method
prog_io_typeclass.m:
Store the term__context in the instance_method
cvs diff: Diffing .
Index: check_typeclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/check_typeclass.m,v
retrieving revision 1.12
diff -u -t -r1.12 check_typeclass.m
--- check_typeclass.m 1998/07/08 20:55:47 1.12
+++ check_typeclass.m 1998/07/29 07:54:06
@@ -174,10 +174,8 @@
tvarset,
import_status, % Import status of
% instance decl.
- pred_or_func, % Is method pred or
+ pred_or_func % Is method pred or
% func?
- term__context % Context of instance
- % decl.
).
%----------------------------------------------------------------------------%
@@ -233,10 +231,6 @@
ProcIds,
ArgModes),
- % XXX The correct context should be added to the
- % XXX hlds_instance_defn
- term__context_init(Context),
-
InstanceDefn0 = hlds_instance_defn(Status, _, InstanceTypes,
_, _, _, _),
@@ -247,14 +241,14 @@
Info0 = instance_method_info(ModuleInfo0, PredName, PredArity,
ExistQVars, ArgTypes, ClassContext, ArgModes, Errors0,
- ArgTypeVars, Status, PredOrFunc, Context),
+ ArgTypeVars, Status, PredOrFunc),
check_instance_pred_procs(ClassVars, MethodName,
InstanceDefn0, InstanceDefn, Info0, Info),
Info = instance_method_info(ModuleInfo, _PredName, _PredArity,
_ExistQVars, _ArgTypes, _ClassContext, _ArgModes, Errors,
- _ArgTypeVars, _Status, _PredOrFunc, _Context).
+ _ArgTypeVars, _Status, _PredOrFunc).
:- pred check_instance_pred_procs(list(var), sym_name,
hlds_instance_defn, hlds_instance_defn,
@@ -268,16 +262,16 @@
MaybeInstancePredProcs, InstanceVarSet, F),
Info0 = instance_method_info(ModuleInfo, PredName, PredArity,
ExistQVars, ArgTypes, ClassContext, ArgModes, Errors0,
- ArgTypeVars, Status, PredOrFunc, Context),
+ ArgTypeVars, Status, PredOrFunc),
get_matching_instance_names(InstanceInterface, PredOrFunc, MethodName,
PredArity, InstanceNames),
(
- InstanceNames = [InstancePredName]
+ InstanceNames = [InstancePredName - Context]
->
produce_auxiliary_procs(ClassVars,
InstanceTypes, InstanceConstraints,
InstanceVarSet,
- InstancePredName,
+ InstancePredName, Context,
InstancePredId, InstanceProcIds, Info0, Info),
MakeClassProc =
@@ -315,7 +309,7 @@
Errors = [NewError|Errors0],
Info = instance_method_info(ModuleInfo, PredName, PredArity,
ExistQVars, ArgTypes, ClassContext, ArgModes, Errors,
- ArgTypeVars, Status, PredOrFunc, Context)
+ ArgTypeVars, Status, PredOrFunc)
;
% another kind of error
% XXX still room for improvement in the error message
@@ -331,11 +325,11 @@
Errors = [NewError|Errors0],
Info = instance_method_info(ModuleInfo, PredName, PredArity,
ExistQVars, ArgTypes, ClassContext, ArgModes, Errors,
- ArgTypeVars, Status, PredOrFunc, Context)
+ ArgTypeVars, Status, PredOrFunc)
).
:- pred get_matching_instance_names(list(instance_method), pred_or_func,
- sym_name, arity, list(sym_name)).
+ sym_name, arity, list(pair(sym_name, term__context))).
:- mode get_matching_instance_names(in, in, in, in, out) is det.
get_matching_instance_names(InstanceInterface, PredOrFunc, PredName,
@@ -343,22 +337,26 @@
(
PredOrFunc = predicate,
solutions(
- lambda([SymName::out] is nondet,
+ lambda([Pair::out] is nondet,
(
list__member(Method, InstanceInterface),
Method = pred_instance(PredName,
- SymName, PredArity)
+ SymName, PredArity,
+ Context),
+ Pair = SymName - Context
)),
InstanceNames)
;
PredOrFunc = function,
FuncArity is PredArity - 1,
solutions(
- lambda([SymName::out] is nondet,
+ lambda([Pair::out] is nondet,
(
list__member(Method, InstanceInterface),
Method = func_instance(PredName,
- SymName, FuncArity)
+ SymName, FuncArity,
+ Context),
+ Pair = SymName - Context
)),
InstanceNames)
).
@@ -367,19 +365,19 @@
:- type triple(T1, T2, T3) ---> triple(T1, T2, T3).
:- pred produce_auxiliary_procs(list(var),
- list(type), list(class_constraint), varset, sym_name,
+ list(type), list(class_constraint), varset, sym_name, term__context,
pred_id, list(proc_id), instance_method_info, instance_method_info).
-:- mode produce_auxiliary_procs(in, in, in, in, in, out, out,
+:- mode produce_auxiliary_procs(in, in, in, in, in, in, out, out,
in, out) is det.
produce_auxiliary_procs(ClassVars,
InstanceTypes0, InstanceConstraints0, InstanceVarSet,
- InstancePredName, PredId,
+ InstancePredName, Context, PredId,
InstanceProcIds, Info0, Info) :-
Info0 = instance_method_info(ModuleInfo0, PredName, PredArity,
ExistQVars0, ArgTypes0, ClassContext0, ArgModes, Errors,
- ArgTypeVars0, Status, PredOrFunc, Context),
+ ArgTypeVars0, Status, PredOrFunc),
% Rename the instance variables apart from the class variables
varset__merge_subst(ArgTypeVars0, InstanceVarSet, ArgTypeVars1,
@@ -487,7 +485,7 @@
Info = instance_method_info(ModuleInfo, PredName, PredArity,
ExistQVars, ArgTypes, ClassContext, ArgModes, Errors,
- ArgTypeVars, Status, PredOrFunc, Context).
+ ArgTypeVars, Status, PredOrFunc).
:- pred apply_substitution_to_var_list(list(var), map(var, term), list(var)).
:- mode apply_substitution_to_var_list(in, in, out) is det.
Index: hlds_out.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_out.m,v
retrieving revision 1.197
diff -u -t -r1.197 hlds_out.m
--- hlds_out.m 1998/07/08 20:56:19 1.197
+++ hlds_out.m 1998/07/29 06:31:58
@@ -262,6 +262,8 @@
;
{ error("special_pred_get_type failed!") }
)
+ ; { string__prefix(Name, "Introduced predicate for") }->
+ io__write_string("type class method implementation")
;
hlds_out__write_pred_or_func(PredOrFunc),
io__write_string(" `"),
Index: mercury_to_mercury.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.139
diff -u -t -r1.139 mercury_to_mercury.m
--- mercury_to_mercury.m 1998/07/08 20:56:50 1.139
+++ mercury_to_mercury.m 1998/07/29 06:41:16
@@ -452,10 +452,10 @@
output_instance_method(Method) -->
io__write_char('\t'),
(
- { Method = func_instance(Name1, Name2, Arity) },
+ { Method = func_instance(Name1, Name2, Arity, _Context) },
io__write_string("func(")
;
- { Method = pred_instance(Name1, Name2, Arity) },
+ { Method = pred_instance(Name1, Name2, Arity, _Context) },
io__write_string("pred(")
),
mercury_output_bracketed_sym_name(Name1, next_to_graphic_token),
Index: module_qual.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/module_qual.m,v
retrieving revision 1.37
diff -u -t -r1.37 module_qual.m
--- module_qual.m 1998/07/08 20:56:58 1.37
+++ module_qual.m 1998/07/29 06:40:46
@@ -802,13 +802,13 @@
sym_name_get_module_name(ClassName, unqualified(""), Module),
Qualify = lambda([M0::in, M::out] is det,
(
- M0 = pred_instance(Method0, A, B),
+ M0 = pred_instance(Method0, A, B, C),
add_module_qualifier(Module, Method0, Method),
- M = pred_instance(Method, A, B)
+ M = pred_instance(Method, A, B, C)
;
- M0 = func_instance(Method0, A, B),
+ M0 = func_instance(Method0, A, B, C),
add_module_qualifier(Module, Method0, Method),
- M = func_instance(Method, A, B)
+ M = func_instance(Method, A, B, C)
)),
list__map(Qualify, M0s, Ms)
).
Index: prog_data.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/prog_data.m,v
retrieving revision 1.37
diff -u -t -r1.37 prog_data.m
--- prog_data.m 1998/07/08 20:57:09 1.37
+++ prog_data.m 1998/07/29 06:38:14
@@ -286,10 +286,14 @@
% Context
.
-:- type instance_method ---> func_instance(sym_name, sym_name, arity)
- ; pred_instance(sym_name, sym_name, arity)
- % Method, Instance, Arity
- .
+:- type instance_method
+ ---> func_instance(sym_name, sym_name, arity, term__context)
+ % Method, Instance, Arity,
+ % Line number of declaration
+ ; pred_instance(sym_name, sym_name, arity, term__context)
+ % Method, Instance, Arity,
+ % Line number of declaration
+ .
:- type instance_interface == list(instance_method).
Index: prog_io_typeclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/prog_io_typeclass.m,v
retrieving revision 1.8
diff -u -t -r1.8 prog_io_typeclass.m
--- prog_io_typeclass.m 1998/07/08 20:57:19 1.8
+++ prog_io_typeclass.m 1998/07/29 06:39:34
@@ -496,7 +496,7 @@
term_to_instance_method(_ModuleName, MethodTerm, Result) :-
(
MethodTerm = term__functor(term__atom("is"), [ClassMethodTerm,
- InstanceMethod], _)
+ InstanceMethod], TermContext)
->
(
ClassMethodTerm = term__functor(term__atom("pred"),
@@ -517,7 +517,8 @@
ok(InstanceMethodName, []))
->
Result = ok(pred_instance(ClassMethodName,
- InstanceMethodName, ArityInt))
+ InstanceMethodName, ArityInt,
+ TermContext))
;
Result = error(
"expected `pred(<Name> / <Arity>) is <InstanceMethod>'",
@@ -542,7 +543,8 @@
ok(InstanceMethodName, []))
->
Result = ok(func_instance(ClassMethodName,
- InstanceMethodName, ArityInt))
+ InstanceMethodName, ArityInt,
+ TermContext))
;
Result = error(
"expected `func(<Name> / <Arity>) is <InstanceMethod>'",
cvs diff: Diffing notes
------------------------------------------------------------------------
love and cuddles,
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | Marge: Did you just call everyone "chicken"?
PhD student, | Homer: Noooo. I swear on this Bible!
Department of Computer Science | Marge: That's not a Bible; that's a book of
University of Melbourne | carpet samples!
Australia | Homer: Ooooh... Fuzzy.
More information about the developers
mailing list