34
35:- module('$qlf',
36 [ qcompile/1, 37 qcompile/2, 38 '$qload_file'/5, 39 '$qload_stream'/5 40 ]). 41
42
43 46
47:- meta_predicate
48 qcompile(:),
49 qcompile(:, +).
56qcompile(M:Files) :-
57 qcompile_(Files, M, []).
58qcompile(M:Files, Options) :-
59 qcompile_(Files, M, Options).
60
61qcompile_([], _, _) :- !.
62qcompile_([H|T], M, Options) :-
63 !,
64 qcompile_(H, M, Options),
65 qcompile_(T, M, Options).
66qcompile_(FileName, Module, Options) :-
67 absolute_file_name(FileName,
68 [ file_type(prolog),
69 access(read),
70 file_errors(fail),
71 solutions(all)
72 ], Absolute),
73 file_name_extension(ABase, PlExt, Absolute),
74 \+ user:prolog_file_type(PlExt, qlf),
75 !,
76 once(user:prolog_file_type(QlfExt, qlf)),
77 file_name_extension(ABase, QlfExt, Qlf),
78 load_files(Module:Absolute, ['$qlf'(Qlf)|Options]).
79qcompile_(FileName, _Module, _Options) :-
80 absolute_file_name(FileName,
81 [ file_type(prolog),
82 access(read)
83 ], Absolute),
84 file_name_extension(_ABase, PlExt, Absolute),
85 user:prolog_file_type(PlExt, qlf),
86 throw(error(permission_error(compile, qlf, Absolute),
87 context(qcompile/1, 'No Prolog source file'))).
93'$qload_file'(File, Module, Action, LoadedModule, Options) :-
94 setup_call_cleanup(
95 open(File, read, In, [type(binary)]),
96 setup_call_cleanup(
97 '$save_lex_state'(LexState, Options),
98 '$qload_stream'(In, Module,
99 Action, LoadedModule, Options),
100 '$restore_lex_state'(LexState)),
101 close(In)).
102
103'$qload_stream'(In, Module, loaded, LoadedModule, Options) :-
104 '$qlf_load'(Module:In, LM),
105 check_is_module(LM, In, Options),
106 ( atom(LM)
107 -> LoadedModule = LM
108 ; LoadedModule = Module
109 ).
110
111check_is_module(LM, In, Options) :-
112 \+ atom(LM),
113 '$option'(must_be_module(true), Options, false),
114 !,
115 stream_property(In, file_name(File)),
116 throw(error(domain_error(module_file, File), _)).
117check_is_module(_, _, _)