diff: move some useful code out of dnf.m

Simon Taylor stayl at cs.mu.oz.au
Wed Oct 15 09:55:31 AEST 1997


Hi Zoltan,

Is this what you wanted?

Simon.


Estimated hours taken: 0.5

compiler/dnf.m
	Shifted some code to create a new predicate for a given goal from 
	dnf.m to hlds_pred__define_new_pred/12 because it is generally useful.

compiler/hlds_pred.m
	Added predicates proc_info_add_variable and proc_info_add_variables
	to add a new variable or list of variables given the types.

Index: dnf.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/dnf.m,v
retrieving revision 1.22
diff -u -r1.22 dnf.m
--- dnf.m	1997/09/01 14:01:21	1.22
+++ dnf.m	1997/10/14 23:37:26
@@ -375,32 +375,12 @@
 		ModuleInfo0, ModuleInfo, PredId) :-
 	DnfInfo = dnf_info(TVarSet, VarTypes, VarSet, Markers),
 	Goal0 = _GoalExpr - GoalInfo,
-	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
-	instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
-
-	goal_info_get_context(GoalInfo, Context),
-	goal_info_get_determinism(GoalInfo, Detism),
 	goal_info_get_nonlocals(GoalInfo, NonLocals),
 	set__to_sorted_list(NonLocals, ArgVars),
-	dnf__compute_arg_types_modes(ArgVars, VarTypes, InstMap0, InstMap,
-		ArgTypes, ArgModes),
-
-	module_info_name(ModuleInfo0, ModuleName),
-	SymName = qualified(ModuleName, PredName),
-	map__init(TVarMap), % later, polymorphism.m will fill this in. 
-	proc_info_create(VarSet, VarTypes, ArgVars, ArgModes, Detism,
-		Goal0, Context, TVarMap, ProcInfo),
-	pred_info_create(ModuleName, SymName, TVarSet, ArgTypes, true,
-		Context, local, Markers, predicate, ProcInfo, ProcId, PredInfo),
-
-	module_info_get_predicate_table(ModuleInfo0, PredTable0),
-	predicate_table_insert(PredTable0, PredInfo, PredId,
-		PredTable),
-	module_info_set_predicate_table(ModuleInfo0, PredTable,
-		ModuleInfo),
-
-	GoalExpr = call(PredId, ProcId, ArgVars, not_builtin, no, SymName),
-	Goal = GoalExpr - GoalInfo.
+	hlds_pred__define_new_pred(Goal0, Goal, ArgVars, InstMap0, PredName,
+		TVarSet, VarTypes, VarSet, Markers, 
+		ModuleInfo0, ModuleInfo, PredProcId),
+	PredProcId = proc(PredId, _).
 
 :- pred dnf__compute_arg_types_modes(list(var)::in, map(var, type)::in,
 	instmap::in, instmap::in, list(type)::out, list(mode)::out) is det.
Index: hlds_pred.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_pred.m,v
retrieving revision 1.36
diff -u -r1.36 hlds_pred.m
--- hlds_pred.m	1997/10/09 09:38:44	1.36
+++ hlds_pred.m	1997/10/14 06:30:36
@@ -199,7 +199,7 @@
 				% Used for pragma(inline).
 				% Since the transformation affects *other*
 				% predicates, the `done' status is not
-				% meaningful
+				% meaningful.
 	;	no_inline	% Requests that this be predicate not be 
 				% inlined.
 				% Used for pragma(no_inline).
@@ -245,6 +245,19 @@
 	--->	request(marker)
 	;	done(marker).
 
+
+	% hlds_pred__define_new_pred(Goal, CallGoal, Args, InstMap, PredName,
+	% 	TVarSet, VarTypes, VarSet, Markers, ModuleInfo0, ModuleInfo,
+	% 	PredProcId)
+	%
+	% Create a new predicate for the given goal, returning a goal to 
+	% call the created predicate.
+:- pred hlds_pred__define_new_pred(hlds_goal, hlds_goal, list(var),
+		instmap, string, tvarset, map(var, type), varset, 
+		list(marker_status), module_info, module_info, pred_proc_id).
+:- mode hlds_pred__define_new_pred(in, out, in, in, in, 
+		in, in, in, in, in, out, out) is det.
+
 	% Various predicates for accessing the information stored in the
 	% pred_id and pred_info data structures.
 
@@ -591,6 +604,51 @@
 			IsPredOrFunc).
 
 %-----------------------------------------------------------------------------%
+
+hlds_pred__define_new_pred(Goal0, Goal, ArgVars, InstMap0, PredName, TVarSet, 
+		VarTypes, VarSet, Markers, ModuleInfo0,
+		ModuleInfo, PredProcId) :-
+	Goal0 = _GoalExpr - GoalInfo,
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
+
+	goal_info_get_context(GoalInfo, Context),
+	goal_info_get_determinism(GoalInfo, Detism),
+	compute_arg_types_modes(ArgVars, VarTypes, InstMap0, InstMap,
+		ArgTypes, ArgModes),
+
+	module_info_name(ModuleInfo0, ModuleName),
+	SymName = qualified(ModuleName, PredName),
+	map__init(TVarMap), % later, polymorphism.m will fill this in. 
+	proc_info_create(VarSet, VarTypes, ArgVars, ArgModes, Detism,
+		Goal0, Context, TVarMap, ProcInfo),
+	pred_info_create(ModuleName, SymName, TVarSet, ArgTypes, true,
+		Context, local, Markers, predicate, ProcInfo, ProcId, PredInfo),
+
+	module_info_get_predicate_table(ModuleInfo0, PredTable0),
+	predicate_table_insert(PredTable0, PredInfo, PredId,
+		PredTable),
+	module_info_set_predicate_table(ModuleInfo0, PredTable,
+		ModuleInfo),
+
+	GoalExpr = call(PredId, ProcId, ArgVars, not_builtin, no, SymName),
+	Goal = GoalExpr - GoalInfo,
+	PredProcId = proc(PredId, ProcId).
+
+:- pred compute_arg_types_modes(list(var)::in, map(var, type)::in,
+	instmap::in, instmap::in, list(type)::out, list(mode)::out) is det.
+
+compute_arg_types_modes([], _, _, _, [], []).
+compute_arg_types_modes([Var | Vars], VarTypes, InstMap0, InstMap,
+		[Type | Types], [Mode | Modes]) :-
+	map__lookup(VarTypes, Var, Type),
+	instmap__lookup_var(InstMap0, Var, Inst0),
+	instmap__lookup_var(InstMap, Var, Inst),
+	Mode = (Inst0 -> Inst),
+	compute_arg_types_modes(Vars, VarTypes, InstMap0, InstMap,
+		Types, Modes).
+
+%-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 	% Various predicates for accessing the proc_info data structure.
@@ -742,6 +800,14 @@
 :- pred proc_info_ensure_unique_names(proc_info, proc_info).
 :- mode proc_info_ensure_unique_names(in, out) is det.
 
+	% Create a new variable of the given type to the procedure.
+:- pred proc_info_add_variable(proc_info, type, var, proc_info).
+:- mode proc_info_add_variable(in, in, out, out) is det.
+
+	% Create a new variable for each element of the list of types.
+:- pred proc_info_add_variables(proc_info, list(type), list(var), proc_info).
+:- mode proc_info_add_variables(in, in, out, out) is det.
+
 :- implementation.
 
 :- type proc_info
@@ -1064,6 +1130,24 @@
 	proc_info_variables(ProcInfo0, VarSet0),
 	varset__ensure_unique_names(AllVars, "p", VarSet0, VarSet),
 	proc_info_set_variables(ProcInfo0, VarSet, ProcInfo).
+
+proc_info_add_variable(ProcInfo0, Type, NewVar, ProcInfo) :-
+	proc_info_variables(ProcInfo0, VarSet0),
+	proc_info_vartypes(ProcInfo0, VarTypes0),
+	varset__new_var(VarSet0, NewVar, VarSet),
+	map__det_insert(VarTypes0, NewVar, Type, VarTypes),
+	proc_info_set_variables(ProcInfo0, VarSet, ProcInfo1),
+	proc_info_set_vartypes(ProcInfo1, VarTypes, ProcInfo).
+
+proc_info_add_variables(ProcInfo0, Types, NewVars, ProcInfo) :-
+	list__length(Types, NumVars),
+	proc_info_variables(ProcInfo0, VarSet0),
+	proc_info_vartypes(ProcInfo0, VarTypes0),
+	varset__new_vars(VarSet0, NumVars, NewVars, VarSet),
+	map__det_insert_from_corresponding_lists(VarTypes0, 
+		NewVars, Types, VarTypes),
+	proc_info_set_variables(ProcInfo0, VarSet, ProcInfo1),
+	proc_info_set_vartypes(ProcInfo1, VarTypes, ProcInfo).
 
 %-----------------------------------------------------------------------------%
 



More information about the developers mailing list