Files
mercury/compiler/transform.m
Zoltan Somogyi 9c9c610f5a This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
Estimated hours taken: 6
Branches: main

This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
to read and to maintain, but contains no changes in algorithms whatsoever.

compiler/modes.m:
compiler/unique_modes.m:
compiler/mode_info.m:
	Convert these modules to our current coding standards. Use state
	variable notation when appropriate, reordering arguments as necessary.
	Delete predicates whose only purpose was to ease programming with DCGs.

	Remove the IO state from the mode_info structure, and pass it
	separately to the (relatively few) predicates that need it. This
	avoids using complicated (and as yet unsupported) modes or lying
	to the compiler (we used to do the latter), and we are no longer
	forced into that choice by being limited to a single hidden (DCG)
	variable.

	Use more expressive variable names and factor out code as appropriate.

compiler/*.m:
	Conform to the changes in the above two modules.
2003-11-06 03:42:36 +00:00

90 lines
3.0 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1995-1998, 2003 The 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.
%-----------------------------------------------------------------------------%
% File: transform.m
% Main author: bromage.
%
% This module defines the primitive operations that may be performed
% on a logic program. These include:
%
% - unfold (NYI)
% Replaces a goal with its possible expansions.
%
% - fold (NYI)
% Opposite of unfold (not surprisingly).
%
% - definition (NYI)
% Define a new predicate with a given goal.
%
% - identity (NYI)
% Apply an identity (such as the associative law for
% addition) to a goal.
%
% These operations form the basis of most high-level transformations.
%
% Also included is a conjunction rescheduler. Useful just in case
% your transformer upset the ordering in a conjunction.
%-----------------------------------------------------------------------------%
:- module transform_hlds__transform.
:- interface.
:- import_module check_hlds__mode_info.
:- import_module hlds__hlds_goal.
:- import_module list.
%:- pred unfold__in_proc(pred_id, proc_id, hlds_goal_expr,
% mode_info, mode_info).
%:- mode unfold__in_proc(in, in, out, in, out) is det.
:- pred transform__reschedule_conj(list(hlds_goal), list(hlds_goal),
mode_info, mode_info).
:- mode transform__reschedule_conj(in, out, in, out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module check_hlds__delay_info.
:- import_module check_hlds__mode_util.
:- import_module ll_backend__code_aux.
:- import_module parse_tree__prog_data.
:- import_module map, set, std_util.
:- import_module term, require.
:- import_module varset.
:- import_module hlds__instmap.
%-----------------------------------------------------------------------------%
% unfold__in_proc(
%-----------------------------------------------------------------------------%
transform__reschedule_conj([], []) --> [].
transform__reschedule_conj([Goal0 | Goals0], Goals) -->
=(ModeInfo0),
{ mode_info_get_instmap(ModeInfo0, InstMap0) },
{ mode_info_get_delay_info(ModeInfo0, DelayInfo0) },
{ delay_info__wakeup_goals(DelayInfo0, WokenGoals, DelayInfo1) },
mode_info_set_delay_info(DelayInfo1),
( { WokenGoals \= [] } ->
{ list__append(WokenGoals, [Goal0 | Goals0], Goals1) },
transform__reschedule_conj(Goals1, Goals)
;
{ Goal0 = _Goal0Goal - Goal0Info },
{ goal_info_get_instmap_delta(Goal0Info, InstMapDelta) },
{ instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap1) },
mode_info_set_instmap(InstMap1),
transform__reschedule_conj(Goals0, Goals1),
{ Goals = [Goal0 | Goals1] }
).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%