mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 23:35:25 +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.
92 lines
1.6 KiB
Mathematica
92 lines
1.6 KiB
Mathematica
% qsort
|
|
%
|
|
% David H. D. Warren
|
|
%
|
|
% quicksort a list of 50 integers
|
|
|
|
:- module qsort.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io, list.
|
|
|
|
:- pred main(io__state, io__state).
|
|
:- mode main(di, uo) is det.
|
|
|
|
:- pred main1(list(int)).
|
|
:- mode main1(out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
|
|
main --> main3(_).
|
|
|
|
main1(Out) :-
|
|
data(Data),
|
|
qsort(Data, Out, []).
|
|
|
|
:- pred main3(list(int), io__state, io__state).
|
|
:- mode main3(out, di, uo) is det.
|
|
|
|
main3(Out) -->
|
|
{ main1(Out) },
|
|
print_list(Out).
|
|
|
|
:- pred data(list(int)).
|
|
:- mode data(out) is det.
|
|
|
|
data([27,74,17,33,94,18,46,83,65,2,32,53,28,85,99,47,28,82,6,11,55,29,39,81,
|
|
90,37,10,0,66,51,7,21,85,27,31,63,75,4,95,99,11,28,61,74,18, 92,40,53,59,8]).
|
|
|
|
:- pred qsort(list(int), list(int), list(int)).
|
|
:- mode qsort(in, out, in) is det.
|
|
|
|
qsort([X|L], R, R0) :-
|
|
partition(L, X, L1, L2),
|
|
qsort(L2, R1, R0),
|
|
qsort(L1, R, [X|R1]).
|
|
qsort([], R, R).
|
|
|
|
:- pred partition(list(int), int, list(int), list(int)).
|
|
:- mode partition(in, in, out, out) is det.
|
|
|
|
partition([], _P, [], []).
|
|
partition([H|T], P, Lo, Hi) :-
|
|
( H =< P ->
|
|
partition(T, P, Lo1, Hi),
|
|
Lo = [H|Lo1]
|
|
;
|
|
partition(T, P, Lo, Hi1),
|
|
Hi = [H|Hi1]
|
|
).
|
|
|
|
:- pred print_list(list(int), io__state, io__state).
|
|
:- mode print_list(in, di, uo) is det.
|
|
|
|
print_list(Xs) -->
|
|
(
|
|
{ Xs = [] }
|
|
->
|
|
io__write_string("[]\n")
|
|
;
|
|
io__write_string("["),
|
|
print_list_2(Xs),
|
|
io__write_string("]\n")
|
|
).
|
|
|
|
:- pred print_list_2(list(int), io__state, io__state).
|
|
:- mode print_list_2(in, di, uo) is det.
|
|
|
|
print_list_2([]) --> [].
|
|
print_list_2([X|Xs]) -->
|
|
io__write_int(X),
|
|
(
|
|
{ Xs = [] }
|
|
->
|
|
[]
|
|
;
|
|
io__write_string(", "),
|
|
print_list_2(Xs)
|
|
).
|