mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 12:26:29 +00:00
Estimated hours taken: 100
Branches: main
Make definitions of abstract types available when generating
code for importing modules. This is necessary for the .NET
back-end, and for `:- pragma export' on the C back-end.
compiler/prog_data.m:
compiler/modules.m:
compiler/make.dependencies.m:
compiler/recompilation.version.m:
Handle implementation sections in interface files.
There is a new pseudo-declaration `abstract_imported'
which is applied to items from the implementation
section of an interface file. `abstract_imported'
items may not be used in the error checking passes
for the curent module.
compiler/equiv_type_hlds.m:
compiler/notes/compiler_design.html:
New file.
Go over the HLDS expanding all types fully after
semantic checking has been run.
compiler/mercury_compile.m:
Add the new pass.
Don't write the `.opt' file if there are any errors.
compiler/instmap.m:
Add a predicate instmap_delta_map_foldl to apply
a procedure to all insts in an instmap.
compiler/equiv_type.m:
Export predicates for use by equiv_type_hlds.m
Reorder arguments so state variables and higher-order
programming can be used.
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
Handle `:- pragma foreign_type' as a form of type
declaration rather than a pragma.
compiler/hlds_data.m:
compiler/*.m:
Add a field to the type_info_cell_constructor cons_id
to identify the type_ctor, which is needed by
equiv_type_hlds.m.
compiler/module_qual.m:
Donn't allow items from the implementation section of
interface files to match items in the current module.
compiler/*.m:
tests/*/*.m:
Add missing imports which only became apparent with
the bug fixes above.
Remove unnecessary imports which only became apparent with
the bug fixes above.
tests/hard_coded/Mmakefile:
tests/hard_coded/export_test2.{m,exp}:
Test case.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
Test case.
107 lines
3.8 KiB
Mathematica
107 lines
3.8 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2002-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: hlds_code_util.m.
|
|
%
|
|
% various utilities routines for use during hlds generation.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hlds__hlds_code_util.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds__hlds_data.
|
|
:- import_module hlds__hlds_module.
|
|
:- import_module parse_tree__prog_data.
|
|
|
|
% Are equivalence types fully expanded on this backend?
|
|
:- pred are_equivalence_types_expanded(module_info::in) is semidet.
|
|
|
|
% Find out how a function symbol (constructor) is represented
|
|
% in the given type.
|
|
|
|
:- func cons_id_to_tag(cons_id, type, module_info) = cons_tag.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module check_hlds__type_util.
|
|
:- import_module libs__globals.
|
|
:- import_module libs__options.
|
|
|
|
:- import_module bool, char, string, require, list, map, std_util, term.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
are_equivalence_types_expanded(ModuleInfo) :-
|
|
module_info_globals(ModuleInfo, Globals),
|
|
globals__lookup_bool_option(Globals, highlevel_data, HighLevelData),
|
|
HighLevelData = yes,
|
|
globals__get_target(Globals, Target),
|
|
( Target = il ; Target = java).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
cons_id_to_tag(int_const(X), _, _) = int_constant(X).
|
|
cons_id_to_tag(float_const(X), _, _) = float_constant(X).
|
|
cons_id_to_tag(string_const(X), _, _) = string_constant(X).
|
|
cons_id_to_tag(pred_const(P,M,E), _, _) = pred_closure_tag(P,M,E).
|
|
cons_id_to_tag(type_ctor_info_const(M,T,A), _, _) =
|
|
type_ctor_info_constant(M,T,A).
|
|
cons_id_to_tag(base_typeclass_info_const(M,C,_,N), _, _) =
|
|
base_typeclass_info_constant(M,C,N).
|
|
cons_id_to_tag(type_info_cell_constructor(_), _, _) = unshared_tag(0).
|
|
cons_id_to_tag(typeclass_info_cell_constructor, _, _) = unshared_tag(0).
|
|
cons_id_to_tag(tabling_pointer_const(PredId,ProcId), _, _) =
|
|
tabling_pointer_constant(PredId,ProcId).
|
|
cons_id_to_tag(deep_profiling_proc_static(PPId), _, _) =
|
|
deep_profiling_proc_static_tag(PPId).
|
|
cons_id_to_tag(table_io_decl(PPId), _, _) = table_io_decl_tag(PPId).
|
|
cons_id_to_tag(cons(Name, Arity), Type, ModuleInfo) = Tag :-
|
|
(
|
|
% handle the `character' type specially
|
|
Type = term__functor(term__atom("character"), [], _),
|
|
Name = unqualified(ConsName),
|
|
string__char_to_string(Char, ConsName)
|
|
->
|
|
char__to_int(Char, CharCode),
|
|
Tag = int_constant(CharCode)
|
|
;
|
|
% Tuples do not need a tag. Note that unary tuples are not
|
|
% treated as no_tag types. There's no reason why they
|
|
% couldn't be, it's just not worth the effort.
|
|
type_is_tuple(Type, _)
|
|
->
|
|
Tag = single_functor
|
|
;
|
|
% Use the type to determine the type_ctor
|
|
( type_to_ctor_and_args(Type, TypeCtor0, _) ->
|
|
TypeCtor = TypeCtor0
|
|
;
|
|
% the type-checker should ensure that this never happens
|
|
error("cons_id_to_tag: invalid type")
|
|
),
|
|
% Given the type_ctor, lookup up the constructor tag
|
|
% table for that type
|
|
module_info_types(ModuleInfo, TypeTable),
|
|
map__lookup(TypeTable, TypeCtor, TypeDefn),
|
|
hlds_data__get_type_defn_body(TypeDefn, TypeBody),
|
|
(
|
|
ConsTable0 = TypeBody ^ du_type_cons_tag_values
|
|
->
|
|
ConsTable = ConsTable0
|
|
;
|
|
% this should never happen
|
|
error("cons_id_to_tag: type is not d.u. type?")
|
|
),
|
|
% Finally look up the cons_id in the table
|
|
map__lookup(ConsTable, cons(Name, Arity), Tag)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|