37
51
52:- module(pce,
53 [ new/2, free/1, 54
55 send/2, send/3, send/4, send/5, send/6, send/7,
56 send/8,
57
58 get/3, get/4, get/5, get/6, get/7, get/8,
59
60 send_class/3,
61 get_class/4,
62 object/1, object/2,
63
64 pce_global/2, 65 pce_autoload/2, 66 pce_autoload_all/0,
67
68 pce_term_expansion/2,
69 pce_compiling/1, 70 pce_compiling/2, 71 pce_begin_recording/1,
72 pce_end_recording/0,
73
74 pce_register_class/1,
75 pce_extended_class/1,
76 pce_begin_class_definition/4,
77 pce_prolog_class/1,
78 pce_prolog_class/2,
79
80 pce_catch_error/2, 81 pce_open/3,
82 in_pce_thread/1, 83 in_pce_thread_sync/1, 84 set_pce_thread/0,
85 pce_thread/1, 86 pce_dispatch/0,
87
88 op(200, fy, @),
89 op(250, yfx, ?),
90 op(800, xfx, :=)
91 ]). 92
93:- multifile
94 on_load/0. 95
96:- set_prolog_flag(generate_debug_info, false). 97
98:- meta_predicate
99 in_pce_thread_sync(0). 100
101 104
105:- multifile user:file_search_path/2. 106
107user:file_search_path(pce_boot, pce(prolog/boot)).
108
109:- load_files([ pce_boot(pce_expand),
110 pce_boot(pce_pl),
111 pce_boot(pce_principal),
112 pce_boot(pce_error),
113 pce_boot(pce_global),
114 pce_boot(pce_expansion),
115 pce_boot(pce_realise),
116 pce_boot(pce_goal_expansion),
117 pce_boot(pce_autoload),
118 pce_boot(pce_editor),
119 pce_boot(pce_keybinding),
120 pce_boot(pce_portray),
121 'english/pce_messages'
122 ],
123 [ qcompile(part), 124 silent(true)
125 ]). 126:- if(current_prolog_flag(threads, true)). 127:- use_module(pce_dispatch). 128:- endif. 129
136
137:- current_prolog_flag(threads, HasThreads),
138 create_prolog_flag(xpce_threaded, HasThreads, [keep(true)]). 139
140:- dynamic
141 pce_thread/1. 142
152
153in_pce_thread_sync(Goal) :-
154 thread_self(Me),
155 pce_thread(Me),
156 !,
157 Goal,
158 !.
159in_pce_thread_sync(Goal) :-
160 term_variables(Goal, Vars),
161 pce_principal:in_pce_thread_sync2(Goal-Vars, Vars).
162
163:- if(current_prolog_flag(threads, true)). 164start_dispatch :-
165 ( current_predicate(pce_dispatch:start_dispatch/0)
166 -> pce_dispatch:start_dispatch
167 ; true
168 ).
169
170:- initialization
171 start_dispatch. 172:- endif. 173
174set_version :-
175 current_prolog_flag(version_data, swi(Major, Minor, Patch, _)),
176 format(string(PlId),
177 'SWI-Prolog version ~w.~w.~w', [Major, Minor, Patch]),
178 send(@prolog, system, PlId).
179
180:- initialization set_version. 181
182get_pce_version :-
183 ( current_prolog_flag(xpce_version, _)
184 -> true
185 ; get(@pce, version, name, Version),
186 create_prolog_flag(xpce_version, Version, [])
187 ).
188
189:- initialization get_pce_version. 190
191run_on_load :-
192 forall(on_load, true).
193
194:- initialization run_on_load. 195
196
197 200
202
203
204 207
208:- multifile
209 user:file_search_path/2. 210
211user:file_search_path(demo, pce('prolog/demo')).
212user:file_search_path(contrib, pce('prolog/contrib')).
213user:file_search_path(image, pce(bitmaps)).
214
215
216 219
220:- use_module(library(swi_hooks)). 221
222 225
227
228:- multifile
229 prolog_edit:load/0,
230 prolog:locate_clauses/2. 231
232prolog_edit:load :-
233 ensure_loaded(library(swi_edit)).
234
235 238
245
246prolog:locate_clauses(Term, Refs) :-
247 ( Term = ->(_,_)
248 ; Term = <-(_,_)
249 ),
250 !,
251 findall(R, method_clause(Term, R), Refs).
252
253match_id(->(Class, Method), Id) :-
254 atomic(Class), atomic(Method),
255 !,
256 atomic_list_concat([Class, (->), Method], Id).
257match_id(->(_Class, _Method), _Id).
258match_id(<-(Class, Method), Id) :-
259 atomic(Class), atomic(Method),
260 !,
261 atomic_list_concat([Class, (<-), Method], Id).
262match_id(<-(_Class, _Method), _Id).
263
264method_clause(->(Class, Send), Ref) :-
265 match_id((Class->Send), Id),
266 clause(pce_principal:send_implementation(Id, _M, _O), _B, Ref),
267 atom(Id),
268 atomic_list_concat([Class,Send], '->', Id).
269method_clause(<-(Class, Get), Ref) :-
270 match_id(<-(Class, Get), Id),
271 clause(pce_principal:get_implementation(Id, _M, _O, _R), _B, Ref),
272 atom(Id),
273 atomic_list_concat([Class,Get], '->', Id).
274
275
276 279
280:- multifile
281 prolog:message/3. 282
283prolog:message(Spec) -->
284 pce_message(Spec).
285prolog:message(context_error(Goal, Context, What)) -->
286 [ '~w: ~w '-[Goal, What] ],
287 pce_message_context(Context).
288prolog:message(type_error(Goal, ArgN, Type, _Value)) -->
289 [ '~w: argument ~w must be a ~w'-[Goal, ArgN, Type], nl ]