root/trunk/configs/ifprolog.config

Revision 4580, 11.8 KB (checked in by pmoura, 13 days ago)

Added a "prolog" read-only compiler flag whose value is the name of the back-end Prolog compiler (an atom). This flag can be used for conditional compilation of Prolog specific code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%
3%  Logtalk - Open source object-oriented logic programming language
4%  Release 2.33.3
5%
6%  Copyright (c) 1998-2008 Paulo Moura.        All Rights Reserved.
7%  Logtalk is free software.  You can redistribute it and/or modify
8%  it under the terms of the "Artistic License 2.0" as published by
9%  The Perl Foundation. Consult the "LICENSE.txt" file for details.
10%
11%
12%  configuration file for IF/Prolog 5.1
13%
14%  last updated: November 7, 2008
15%
16%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18
19
20
21%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22%
23%  ISO Prolog Standard predicates that we must define because they are
24%  not built-in
25%
26%  add a clause for lgt_iso_predicate/1 declaring each ISO predicate that
27%  we must define; there must be at least one clause for this predicate
28%  whose call should fail if we don't define any ISO predicates
29%
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
32
33% '$lgt_iso_predicate'(?callable).
34
35'$lgt_iso_predicate'(_) :-
36    fail.
37
38
39
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41%
42%  predicate properties
43%
44%  this predicate must return at least static, dynamic, and built_in
45%  properties for an existing predicate
46%
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48
49
50% '$lgt_predicate_property'(+callable, ?predicate_property)
51
52'$lgt_predicate_property'(Pred, Prop) :-
53    predicate_property(Pred, Prop).
54
55
56
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58%
59%  meta-predicates
60%
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
63
64% call_cleanup(+callable, +callble)
65
66call_cleanup(_, _) :-
67    throw(not_supported(call_cleanup/2)).
68
69
70% forall(+callable, +callble) -- built-in
71
72forall(Generate, Test) :-
73    \+ (Generate, \+ Test).
74
75
76% retractall(+callable)
77
78retractall(Head) :-
79    retract((Head :- _)),
80    fail.
81
82retractall(_).
83
84
85% call_with_args/2-9
86%
87% use these definitions only if your compiler does
88% not provide call_with_args/2-9 as built-in predicates
89
90call_with_args(F, A) :-
91    Call =.. [F, A],
92    call(Call).
93
94call_with_args(F, A1, A2) :-
95    Call =.. [F, A1, A2],
96    call(Call).
97
98call_with_args(F, A1, A2, A3) :-
99    Call =.. [F, A1, A2, A3],
100    call(Call).
101
102call_with_args(F, A1, A2, A3, A4) :-
103    Call =.. [F, A1, A2, A3, A4],
104    call(Call).
105
106call_with_args(F, A1, A2, A3, A4, A5) :-
107    Call =.. [F, A1, A2, A3, A4, A5],
108    call(Call).
109
110call_with_args(F, A1, A2, A3, A4, A5, A6) :-
111    Call =.. [F, A1, A2, A3, A4, A5, A6],
112    call(Call).
113
114call_with_args(F, A1, A2, A3, A4, A5, A6, A7) :-
115    Call =.. [F, A1, A2, A3, A4, A5, A6, A7],
116    call(Call).
117
118call_with_args(F, A1, A2, A3, A4, A5, A6, A7, A8) :-
119    Call =.. [F, A1, A2, A3, A4, A5, A6, A7, A8],
120    call(Call).
121
122
123
124%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125%
126%  Prolog built-in meta-predicates
127%
128%  (excluding ISO Prolog Standard meta-predicates)
129%
130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131
132
133% '$lgt_pl_meta_predicate'(?callable, ?atom).
134
135'$lgt_pl_meta_predicate'(_, _) :-
136    fail.
137
138
139
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141%
142%  file extension predicates
143%
144%  these extensions are used by Logtalk load/compile predicates
145%
146%  you may want to change the extension for Prolog files to match
147%  the one expected by your Prolog compiler
148%
149%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
151
152% '$lgt_file_extension'(?atom, ?atom)
153
154'$lgt_file_extension'(logtalk, '.lgt').
155'$lgt_file_extension'(prolog, '.pl').
156'$lgt_file_extension'(xml, '.xml').
157
158
159
160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161%
162%  default flag values
163%
164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
166
167% '$lgt_default_flag'(?atom, ?atom)
168%
169% default values for all flags
170
171'$lgt_default_flag'(prolog, if).
172
173'$lgt_default_flag'(xmldocs, on).
174'$lgt_default_flag'(xslfile, 'lgtxml.xsl').
175'$lgt_default_flag'(xmlspec, dtd).
176'$lgt_default_flag'(xmlsref, local).
177
178'$lgt_default_flag'(unknown, warning).
179'$lgt_default_flag'(misspelt, warning).
180'$lgt_default_flag'(singletons, warning).
181'$lgt_default_flag'(lgtredef, warning).
182'$lgt_default_flag'(plredef, silent).
183'$lgt_default_flag'(portability, silent).
184
185'$lgt_default_flag'(report, on).
186
187'$lgt_default_flag'(smart_compilation, off).
188'$lgt_default_flag'(reload, always).
189
190'$lgt_default_flag'(startup_message, flags(verbose)).
191
192'$lgt_default_flag'(underscore_variables, singletons).
193
194'$lgt_default_flag'(code_prefix, '').
195
196'$lgt_default_flag'(debug, off).
197'$lgt_default_flag'(break_predicate, supported).
198
199'$lgt_default_flag'(complements, off).
200'$lgt_default_flag'(dynamic_declarations, off).
201'$lgt_default_flag'(events, off).
202
203'$lgt_default_flag'(altdirs, off).
204'$lgt_default_flag'(tmpdir, 'lgt_tmp/').
205'$lgt_default_flag'(xmldir, 'xml_docs/').
206
207'$lgt_default_flag'(encoding_directive, unsupported).
208'$lgt_default_flag'(multifile_directive, supported).
209'$lgt_default_flag'(threads, unsupported).
210
211'$lgt_default_flag'(context_switching_calls, allow).
212
213
214
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216%
217%  list predicates
218%
219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220
221
222'$lgt_append'([], List, List).
223'$lgt_append'([Head| Tail], List, [Head| Tail2]) :-
224    '$lgt_append'(Tail, List, Tail2).
225
226
227'$lgt_member'(Head, [Head| _]).
228'$lgt_member'(Head, [_| Tail]) :-
229    '$lgt_member'(Head, Tail).
230
231
232'$lgt_member_var'(V, [H| _]) :-
233    V == H.
234'$lgt_member_var'(V, [_| T]) :-
235    '$lgt_member_var'(V, T).
236
237
238'$lgt_is_list'([]) :-
239    !.
240'$lgt_is_list'([_| Tail]) :-
241    '$lgt_is_list'(Tail).
242
243
244'$lgt_is_proper_list'(List) :-
245    List == [], !.
246'$lgt_is_proper_list'([_| Tail]) :-
247    nonvar(Tail),
248    '$lgt_is_proper_list'(Tail).
249
250
251
252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253%
254%  file predicates
255%
256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
258
259% '$lgt_file_exists'(+atom)
260%
261% checks if a file exist in the current directory
262
263'$lgt_file_exists'(File) :-
264    file_test(File, read).
265
266
267% '$lgt_directory_exists'(+atom)
268%
269% checks if a directory exists
270
271'$lgt_directory_exists'(Directory) :-
272    file_test(Directory, read),
273    get_file_info(Directory, mode, ifdir).
274
275
276% '$lgt_current_directory'(-atom)
277%
278% gets current working directory
279
280'$lgt_current_directory'(Directory) :-
281    getcwd(Directory).
282
283
284% '$lgt_change_directory'(+atom)
285%
286% changes current working directory
287
288'$lgt_change_directory'(Directory) :-
289    cd(Directory).
290
291
292% '$lgt_make_directory'(+atom)
293%
294% makes a new directory; succeeds if the directory already exists
295
296'$lgt_make_directory'(_) :-
297    throw(not_supported('$lgt_make_directory'/1)).
298
299
300% '$lgt_load_prolog_code'(+atom, +atom, +list)
301%
302% compile and load a Prolog file, resulting from a
303% Logtalk source file, given a list of options
304
305'$lgt_load_prolog_code'(File, _, _) :-
306    reconsult(File).
307
308
309% '$lgt_compare_file_mtimes'(?atom, +atom, +atom)
310%
311% compare file modification times
312
313'$lgt_compare_file_mtimes'(Result, File1, File2) :-
314    get_file_info(File1, mtime, Time1),
315    get_file_info(File2, mtime, Time2),
316    compare(Result, Time1, Time2).
317
318
319
320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321%
322%  sorting predicates
323%
324%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325
326
327% '$lgt_keysort'(+list, -list)
328
329'$lgt_keysort'(_, _) :-
330    throw(error(not_implemented, keysort/2)).
331
332
333% '$lgt_sort'(+list, -list)
334
335'$lgt_sort'(List, Sorted) :-
336    sort(List, Sorted).
337
338
339
340%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341%
342%  time and date predicates
343%
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345
346
347% '$lgt_current_date'(?Year, ?Month, ?Day)
348
349'$lgt_current_date'(Year, Month, Day) :-
350    localtime(time, Year, Month, Day, _, _, _, _, _).
351
352
353% '$lgt_current_time'(?Hours, ?Mins, ?Secs)
354
355'$lgt_current_time'(Hours, Mins, Secs) :-
356    localtime(time, _, _, _, _, _, Hours, Mins, Secs).
357
358
359
360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361%
362%  timing predicate
363%
364%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365
366
367% '$lgt_cpu_time'(-Seconds)
368
369'$lgt_cpu_time'(Seconds) :-
370    Seconds is cputime.
371
372
373
374%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375%
376%  comparison predicate
377%
378%  the usual compare/3 definition
379%
380%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381
382
383% compare(?atom, @term, @term) -- built-in
384
385
386
387%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388%
389%  callable predicate
390%
391%  the usual callable/1 definition
392%
393%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394
395
396% callable(@term)
397
398callable(Term) :-
399    nonvar(Term),
400    functor(Term, Functor, _),
401    atom(Functor).
402
403
404
405%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406%
407%  read character predicate
408%
409%  read a single character echoing it and writing a newline after
410%
411%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412
413
414'$lgt_read_single_char'(Char) :-
415    get_char(Char),
416    (   peek_code(10) ->    % hack to workaround the lack of built-in
417        get_code(_)         % support for unbuffered character input
418    ;   true
419    ).
420
421
422
423%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424%
425%  pretty print a term by naming its free variables
426%  (avoid instantiating variables in term by using double negation if necessary)
427%
428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429
430
431'$lgt_pretty_print_vars'(Stream, Term) :-
432    \+ \+ (
433        numbervars(Term, 0, _),
434        write_term(Stream, Term, [numbervars(true)])).
435
436
437'$lgt_pretty_print_vars_quoted'(Stream, Term) :-
438    \+ \+ (
439        numbervars(Term, 0, _),
440        write_term(Stream, Term, [numbervars(true), quoted(true)])).
441
442
443
444%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
445%
446%  getting stream current line number
447%  (needed for improved compiler error messages)
448%
449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450
451
452% '$lgt_stream_current_line_number'(@stream, -integer)
453
454'$lgt_stream_current_line_number'(_, _) :-
455    fail.
456
457
458
459%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460%
461%  customized version of the read_term/3 predicate for returning the line
462%  where the term starts (needed for improved compiler error messages)
463%
464%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
465
466
467% '$lgt_read_term'(@stream, -term, +list, -integer)
468
469'$lgt_read_term'(Stream, Term, Options, -1) :-
470    read_term(Stream, Term, Options).
471
472
473
474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475%
476%  handling of Prolog-proprietary directives on Logtalk source files
477%
478%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479
480
481% '$lgt_ignore_pl_directive'(@callable)
482
483'$lgt_ignore_pl_directive'(_) :-
484    fail.
485
486
487% '$lgt_rewrite_and_copy_pl_directive'(@callable, -callable)
488
489'$lgt_rewrite_and_copy_pl_directive'(_, _) :-
490    fail.
491
492
493% '$lgt_rewrite_and_recompile_pl_directive'(@callable, -callable)
494
495'$lgt_rewrite_and_recompile_pl_directive'(_, _) :-
496    fail.
497
498
499
500%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501%
502%  Shortcut to the Logtalk built-in predicate logtalk_load/1
503%
504%  defined in the config files in order to be able to comment it out in case
505%  of conflict with some Prolog native feature; it implies conformance with
506%  the ISO Prolog standard regarding the definition of the {}/1 syntax
507%
508%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509
510{File, Files} :-
511    !,
512    logtalk_load(File),
513    {Files}.
514{File} :-
515    logtalk_load(File).
516
517
518
519%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520%
521%  end!
522%
523%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracBrowser for help on using the browser.