Files
mercury/compiler/tree.m
Fergus Henderson 7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00

87 lines
2.7 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1993-2001 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.
%-----------------------------------------------------------------------------%
%
% Main authors: conway, fjh.
%
% This file provides a 'tree' data type.
% The code generater uses this to build a tree of instructions and
% then flatten them into a list.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module libs__tree.
%-----------------------------------------------------------------------------%
:- interface.
:- import_module list.
:- type tree(T) ---> empty
; node(T)
; tree(tree(T), tree(T)).
:- func tree__flatten(tree(T)) = list(T).
% Make a tree from a list of trees.
:- func tree__list(list(tree(T))) = tree(T).
:- pred tree__flatten(tree(T), list(T)).
:- mode tree__flatten(in, out) is det.
:- pred tree__is_empty(tree(T)).
:- mode tree__is_empty(in) is semidet.
:- pred tree__tree_of_lists_is_empty(tree(list(T))).
:- mode tree__tree_of_lists_is_empty(in) is semidet.
:- func tree__map(func(T) = U, tree(T)) = tree(U).
%-----------------------------------------------------------------------------%
:- implementation.
tree__flatten(T) = L :- tree__flatten(T, L).
tree__list([]) = empty.
tree__list([X | Xs]) = tree(X, tree__list(Xs)).
tree__flatten(T, L) :-
tree__flatten_2(T, [], L).
:- pred tree__flatten_2(tree(T), list(T), list(T)).
:- mode tree__flatten_2(in, in, out) is det.
% flatten_2(T, L0, L) is true iff L is the list that results from
% traversing T left-to-right depth-first, and then appending L0.
tree__flatten_2(empty, L, L).
tree__flatten_2(node(T), L, [T|L]).
tree__flatten_2(tree(T1,T2), L0, L) :-
tree__flatten_2(T2, L0, L1),
tree__flatten_2(T1, L1, L).
%-----------------------------------------------------------------------------%
tree__is_empty(empty).
tree__is_empty(tree(L, R)) :-
tree__is_empty(L),
tree__is_empty(R).
%-----------------------------------------------------------------------------%
tree__tree_of_lists_is_empty(empty).
tree__tree_of_lists_is_empty(node([])).
tree__tree_of_lists_is_empty(tree(L, R)) :-
tree__tree_of_lists_is_empty(L),
tree__tree_of_lists_is_empty(R).
%-----------------------------------------------------------------------------%
tree__map(_F, empty) = empty.
tree__map(F, node(T)) = node(F(T)).
tree__map(F, tree(L, R)) = tree(tree__map(F, L), tree__map(F, R)).
%-----------------------------------------------------------------------------%