mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 07:15:19 +00:00
Estimated hours taken: 3.5 Branches: main Split the parse tree (currently defined in prog_data.m) into two separate modules. The reason for doing this is that while over 80% of the modules in the compiler import prog_data, very few of them actually require access to the types that define the parse tree (principally the item type). At the moment even small changes to these types can result in recompiles that rebuild almost all of the compiler. This change shifts the item type (and related types) into a new module, prog_item, that is only imported where these types are required (mostly at the frontend of the compiler). This should reduce the size of recompiles required when the parse tree is modified. This diff does not change any algorithms; it just shifts things around. compiler/prog_data.m: Move the item type and any related types that are not needed after the HLDS has been built to the new prog_item module. Fix bitrot in comments. Fix formatting and layout of comments. Use unexpected/2 in place of error/1 in a spot. compiler/prog_item.m: New file. This module contains any parts of the parse tree that are not needed by the rest of the compiler after the HLDS has been built. compiler/check_typeclass.m: s/list(instance_method)/instance_methods/ compiler/equiv_type.m: compiler/hlds_module.m: compiler/intermod.m: compiler/make.module_dep_file.m: compiler/make_hlds.m: compiler/mercury_compile.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/modules.m: compiler/parse_tree.m: compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: compiler/prog_io_util.m: compiler/prog_out.m: compiler/prog_util.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/trans_opt.m: Conform to the above changes. compiler/notes/compiler_design.html: Mention the new module.
176 lines
6.6 KiB
Mathematica
176 lines
6.6 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2005 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: rafe, juliensf
|
|
%
|
|
% Utility predicates for dealing with mutable declarations.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.prog_mutable.
|
|
|
|
:- interface.
|
|
|
|
:- import_module mdbcomp.prim_data.
|
|
:- import_module parse_tree.prog_data.
|
|
:- import_module parse_tree.prog_item.
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Create a predmode declaration for a non-pure mutable get predicate.
|
|
% (This is the default get predicate.)
|
|
%
|
|
:- func nonpure_get_pred_decl(module_name, string, mer_type, mer_inst) = item.
|
|
|
|
% Create a predmode declaration for a non-pure mutable set predicate.
|
|
% (This is the default set predicate.)
|
|
%
|
|
:- func nonpure_set_pred_decl(module_name, string, mer_type, mer_inst) = item.
|
|
|
|
% Create a predmode declaration for a pure mutable get predicate.
|
|
% (This is only created if the `pure' mutable attribute is given.)
|
|
%
|
|
:- func pure_get_pred_decl(module_name, string, mer_type, mer_inst) = item.
|
|
|
|
% Create a predmode declaration for a pure mutable set predicate.
|
|
% (This is only create the `pure' mutable attribute is give.)
|
|
%
|
|
:- func pure_set_pred_decl(module_name, string, mer_type, mer_inst) = item.
|
|
|
|
% Create a predmode declaration for the mutable initialisation
|
|
% predicate.
|
|
%
|
|
:- func init_pred_decl(module_name, string) = item.
|
|
|
|
% Create the foreign_decl for the mutable.
|
|
%
|
|
:- func get_global_foreign_decl(string) = item.
|
|
|
|
% Create the foreign_code that defines the mutable.
|
|
%
|
|
:- func get_global_foreign_defn(string) = item.
|
|
|
|
:- func mutable_get_pred_sym_name(sym_name, string) = sym_name.
|
|
|
|
:- func mutable_set_pred_sym_name(sym_name, string) = sym_name.
|
|
|
|
:- func mutable_init_pred_sym_name(sym_name, string) = sym_name.
|
|
|
|
:- func mutable_c_var_name(sym_name, string) = string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module libs.globals.
|
|
:- import_module parse_tree.prog_foreign.
|
|
:- import_module parse_tree.prog_mode.
|
|
:- import_module list.
|
|
:- import_module std_util.
|
|
:- import_module varset.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
nonpure_get_pred_decl(ModuleName, Name, Type, Inst) = GetPredDecl :-
|
|
VarSet = varset__init,
|
|
InstVarSet = varset__init,
|
|
ExistQVars = [],
|
|
Constraints = constraints([], []),
|
|
GetPredDecl = pred_or_func(VarSet, InstVarSet, ExistQVars, predicate,
|
|
mutable_get_pred_sym_name(ModuleName, Name),
|
|
[type_and_mode(Type, out_mode(Inst))],
|
|
no /* with_type */, no /* with_inst */, yes(det),
|
|
true /* condition */, purity_semipure, Constraints).
|
|
|
|
nonpure_set_pred_decl(ModuleName, Name, Type, Inst) = SetPredDecl :-
|
|
VarSet = varset__init,
|
|
InstVarSet = varset__init,
|
|
ExistQVars = [],
|
|
Constraints = constraints([], []),
|
|
SetPredDecl = pred_or_func(VarSet, InstVarSet, ExistQVars, predicate,
|
|
mutable_set_pred_sym_name(ModuleName, Name),
|
|
[type_and_mode(Type, in_mode(Inst))],
|
|
no /* with_type */, no /* with_inst */, yes(det),
|
|
true /* condition */, purity_impure, Constraints).
|
|
|
|
pure_get_pred_decl(ModuleName, Name, Type, Inst) = GetPredDecl :-
|
|
VarSet = varset__init,
|
|
InstVarSet = varset__init,
|
|
ExistQVars = [],
|
|
Constraints = constraints([], []),
|
|
GetPredDecl = pred_or_func(VarSet, InstVarSet, ExistQVars, predicate,
|
|
mutable_get_pred_sym_name(ModuleName, Name),
|
|
[type_and_mode(Type, out_mode(Inst)),
|
|
type_and_mode(io_state_type, di_mode),
|
|
type_and_mode(io_state_type, uo_mode)],
|
|
no /* with_type */, no /* with_inst */, yes(det),
|
|
true /* condition */, purity_pure, Constraints).
|
|
|
|
pure_set_pred_decl(ModuleName, Name, Type, Inst) = SetPredDecl :-
|
|
VarSet = varset__init,
|
|
InstVarSet = varset__init,
|
|
ExistQVars = [],
|
|
Constraints = constraints([], []),
|
|
SetPredDecl = pred_or_func(VarSet, InstVarSet, ExistQVars, predicate,
|
|
mutable_set_pred_sym_name(ModuleName, Name),
|
|
[type_and_mode(Type, in_mode(Inst)),
|
|
type_and_mode(io_state_type, di_mode),
|
|
type_and_mode(io_state_type, uo_mode)],
|
|
no /* with_type */, no /* with_inst */, yes(det),
|
|
true /* condition */, purity_pure, Constraints).
|
|
|
|
% Return the type io.state.
|
|
% XXX Perhaps this should be in prog_type?
|
|
%
|
|
:- func io_state_type = mer_type.
|
|
|
|
io_state_type = defined(qualified(unqualified("io"), "state"), [], star).
|
|
|
|
init_pred_decl(ModuleName, Name) = InitPredDecl :-
|
|
VarSet = varset__init,
|
|
InstVarSet = varset__init,
|
|
ExistQVars = [],
|
|
Constraints = constraints([], []),
|
|
InitPredDecl = pred_or_func(VarSet, InstVarSet, ExistQVars,
|
|
predicate, mutable_init_pred_sym_name(ModuleName, Name),
|
|
[], no /* with_type */, no /* with_inst */, yes(det),
|
|
true /* condition */, purity_impure, Constraints).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
get_global_foreign_decl(TargetMutableName) =
|
|
pragma(compiler(mutable_decl),
|
|
foreign_decl(c, foreign_decl_is_exported,
|
|
"extern MR_Word " ++ TargetMutableName ++ ";")).
|
|
|
|
get_global_foreign_defn(TargetMutableName) =
|
|
pragma(compiler(mutable_decl),
|
|
foreign_code(c, "MR_Word " ++ TargetMutableName ++ ";")).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
mutable_get_pred_sym_name(ModuleName, Name) =
|
|
qualified(ModuleName, "get_" ++ Name).
|
|
|
|
mutable_set_pred_sym_name(ModuleName, Name) =
|
|
qualified(ModuleName, "set_" ++ Name).
|
|
|
|
mutable_init_pred_sym_name(ModuleName, Name) =
|
|
qualified(ModuleName, "initialise_mutable_" ++ Name).
|
|
|
|
mutable_c_var_name(ModuleName, Name) = MangledCVarName :-
|
|
RawCVarName = "mutable_variable_" ++ Name,
|
|
QualifiedCVarName = qualified(ModuleName, RawCVarName),
|
|
MangledCVarName = sym_name_mangle(QualifiedCVarName).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module prog_mutable.
|
|
%-----------------------------------------------------------------------------%
|