mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 20:03:44 +00:00
Estimated hours taken: 10 Fix the remaining bugs with the handling of partial qualifiers for nested modules. compiler/module_qual.m: Define a new abstract type partial_qualifier_info, and a predicate mq_info_get_partial_qualifier_info to get this type from the mq_info. Define a new predicate get_partial_qualifiers/3 in module_qual.m which is like the old get_partial_qualifiers/2 predicate from modules.m except that it takes a partial_qualifier_info and uses the information in this to return only the partial qualifiers for modules which are visible, rather than returning all partial qualifier regardless of whether the modules that they refer to are in scope or not. compiler/prog_util.m: Export the `insert_module_qualifier' predicate, for use in the definition of get_partial_qualifiers/3. compiler/hlds_module.m: compiler/make_hlds.m: Change the code for make_hlds__ctors_add and hlds_module__pred_table_insert/5 so that they handles partial qualifiers properly, computing the partial qualifiers by calling get_partial_qualifiers/3 rather than by checking the NeedQual variable and calling get_partial_qualifiers/2. compiler/modules.m: Delete the old get_partial_qualifiers/2 predicate. compiler/hlds_module.m: Add a new field to the HLDS containing the partial_qualifier_info. Add a partial_qualifier_info parameter to pred_table_insert/5. compiler/check_typeclass.m: compiler/make_hlds.m: When calling pred_table_insert/5, get the partial_qualifier_info from the HLDS and pass it as an extra argument. tests/hard_coded/sub-modules/nested.m: tests/hard_coded/sub-modules/nested3.m: tests/hard_coded/sub-modules/parent.m: tests/hard_coded/sub-modules/nested.exp: tests/hard_coded/sub-modules/nested3.exp: tests/hard_coded/sub-modules/parent.exp: Uncomment parts of these test cases which were previously commented out because they were not yet supported. doc/reference_manual.texi: Delete the description of this bug.
91 lines
2.0 KiB
Mathematica
91 lines
2.0 KiB
Mathematica
% "Hello World" in Mercury, using nested modules.
|
|
|
|
:- module nested.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module nested:child.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- type foo ---> bar ; baz(int).
|
|
|
|
:- pred hello(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
hello --> io__write_string("nested:child:hello\n").
|
|
|
|
:- end_module nested:child.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module nested:child2.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- type foo ---> bar ; baz(int).
|
|
|
|
:- pred hello(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
hello --> io__write_string("nested:child2:hello\n").
|
|
|
|
:- end_module nested:child2.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% now we're back in the parent module.
|
|
|
|
:- import_module nested:child.
|
|
:- use_module nested:child2.
|
|
:- import_module std_util, require.
|
|
|
|
:- type t1 == nested:child:foo.
|
|
:- type t2 == child:foo.
|
|
:- type t3 == foo.
|
|
:- type t4 == nested:child2:foo.
|
|
:- type t5 == child2:foo.
|
|
|
|
main -->
|
|
nested:child:hello,
|
|
child:hello,
|
|
hello,
|
|
nested:child2:hello,
|
|
child2:hello,
|
|
|
|
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 = nested:child:bar.
|
|
has_type_t2 = child:bar.
|
|
has_type_t3 = bar.
|
|
has_type_t4 = nested:child2:bar.
|
|
has_type_t5 = child2:bar.
|
|
|
|
:- end_module nested.
|