mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 05:13:48 +00:00
Estimated hours taken: 8
Add support for the use of partial module qualifiers,
e.g. using `child:foo' to refer to `parent🧒foo'.
Previously we only allowed names to be fully-qualified
or completely unqualified.
Note that we still don't yet keep track of which modules are visible,
so this change does not properly handle the distinction between
`import_module' and `use_module' declarations for parent modules.
It basically assumes that `child:foo' is allowed iff plain `foo'
would be allowed (i.e. iff `parent:child' has been imported)
whereas it ought to be allowed iff `parent' has been imported.
compiler/modules.m:
Add get_partial_qualifiers/2, for use by make_hlds.m
and hlds_module.m.
compiler/make_hlds.m:
Insert partially-qualified symbols into the cons_table.
compiler/hlds_module.m:
Insert partially-qualified symbols into the pred_table.
compiler/module_qual.m:
When searching the symbol tables used for types, insts, modes,
and typeclasses, search for partially-qualified symbols.
compiler/modecheck_unify.m:
When module-qualifying cons_ids, make sure that we fully module
qualify them even if they're already partially qualified.
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.child2.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Uncomment the previously-failed test of using partially-qualified
symbol names. Add a new child module, `parent.child2', and import it
using `use_module', so that we test `use_module' as well as
`import_module'. Add code to test importing of types and
constructors.
61 lines
1.6 KiB
Mathematica
61 lines
1.6 KiB
Mathematica
% "Hello World" in Mercury, using nested modules.
|
|
|
|
:- module parent.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- include_module child, child2.
|
|
|
|
:- import_module parent:child.
|
|
:- use_module parent:child2.
|
|
:- import_module std_util, require.
|
|
|
|
:- type t1 == parent:child:foo.
|
|
:- type t2 == child:foo.
|
|
:- type t3 == foo.
|
|
:- type t4 == parent:child2:foo.
|
|
% :- type t5 == child2:foo. % XXX mixing of use_module and import_module
|
|
% is not yet supported.
|
|
:- type t5 == parent:child2:foo.
|
|
|
|
main -->
|
|
parent:child:hello,
|
|
child:hello,
|
|
hello,
|
|
parent:child2:hello,
|
|
% child2:hello, % XXX mixing of use_module and import_module
|
|
% is not yet supported.
|
|
|
|
print("t1 = "), print(type_of(has_type_t1)), nl,
|
|
print("t2 = "), print(type_of(has_type_t2)), nl,
|
|
print("t3 = "), print(type_of(has_type_t3)), nl,
|
|
print("t4 = "), print(type_of(has_type_t4)), nl,
|
|
print("t5 = "), print(type_of(has_type_t5)), nl,
|
|
|
|
print("has_type_t1 = "), print(has_type_t1), nl,
|
|
print("has_type_t2 = "), print(has_type_t2), nl,
|
|
print("has_type_t3 = "), print(has_type_t3), nl,
|
|
print("has_type_t4 = "), print(has_type_t4), nl,
|
|
print("has_type_t5 = "), print(has_type_t5), nl,
|
|
|
|
{ true }.
|
|
|
|
:- func has_type_t1 = t1.
|
|
:- func has_type_t2 = t2.
|
|
:- func has_type_t3 = t3.
|
|
:- func has_type_t4 = t4.
|
|
:- func has_type_t5 = t5.
|
|
|
|
has_type_t1 = parent:child:bar.
|
|
has_type_t2 = child:bar.
|
|
has_type_t3 = bar.
|
|
has_type_t4 = parent:child2:bar.
|
|
% has_type_t5 = child2:bar. % XXX mixing of use_module and import_module
|
|
% is not yet supported.
|
|
has_type_t5 = parent:child2:bar.
|
|
|