34
35:- module(compilation_module,
36 [ compilation_module/1,
37 compilation_module/2,
38 compile_time_called/3,
39 (compilation_predicate)/1,
40 op(1150, fx, compilation_predicate)
41 ]). 42
43:- use_module(library(apply)). 44:- use_module(library(lists)). 45:- use_module(library(sequence_list)). 46:- reexport(library(compound_expand)). 47:- init_expansors. 48
49:- meta_predicate
50 compilation_module(:),
51 compilation_module(:,+),
52 compilation_predicate(:). 53
54:- multifile compile_time_called/3. 55
56compilation_module(A) :- use_module(A).
57
58compilation_module(A, B) :- use_module(A, B).
59
60compilation_predicate(_).
61
62compilation_predicate_clause(F/A) --> ['$compilation_predicate'(F, A)].
63
64term_expansion((:- compilation_module(Alias)),
65 [(:- discontiguous '$compilation_module'/2),
66 '$compilation_module'(Alias, all),
67 (:- use_module(Alias))]).
68term_expansion((:- compilation_module(Alias, Exports)),
69 [(:- discontiguous '$compilation_module'/2),
70 '$compilation_module'(Alias, Exports),
71 (:- use_module(Alias, Exports))]).
72term_expansion((:- compilation_predicate(Seq)),
73 [(:- discontiguous '$compilation_predicate'/2)|ClauseL]) :-
74 sequence_list(Seq, List, []),
75 foldl(compilation_predicate_clause, List, ClauseL, []).
76term_expansion(end_of_file, ClauseL) :-
77 prolog_load_context(module, Context),
78 prolog_load_context(source, Source),
79 module_property(Context, file(Source)),
80 findall(@(Context, Module:F/A),
81 ( current_predicate(Context:'$compilation_module'/2),
82 Context:'$compilation_module'(Alias, Exports),
83 absolute_file_name(Alias, File, [file_type(prolog), access(read)]),
84 module_property(Module, file(File)),
85 current_export(Exports, Context, Module, F, A)
86 ; current_predicate(Context:'$compilation_predicate'/2),
87 Context:'$compilation_predicate'(F, A)
88 ), CompileTimeCalledL),
89 abolish(Context:'$compilation_module'/2),
90 abolish(Context:'$compilation_predicate'/2),
91 findall(compilation_module:compile_time_called(H, Module, Context),
92 ( member(@(Context, Module:F/A), CompileTimeCalledL),
93 functor(H, F, A),
94 abolish(Context:F/A)
95 ), ClauseL, [end_of_file]).
96
97current_export([E|L], _, _, F, A) :- member(F/A, [E|L]).
98current_export(all, Context, Module, F, A) :-
99 current_predicate(Context:F/A),
100 functor(H, F, A),
101 predicate_property(Context:H, imported_from(Module))