-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.pro
More file actions
77 lines (57 loc) · 2.18 KB
/
Copy pathdatabase.pro
File metadata and controls
77 lines (57 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
:- annotate(file,[
purpose-"remember loaded things"
, note-"internal state of the loader"
]).
:- section("relations populated by observing the external world").
:- annotate(relation(unit_module/2),[cardinality=1:1]).
:- annotate(predicate(file_term/3),[
meaning = "The Index-th read term from File is Term (original term after read before any expansion)"
]).
%% file_predicate(?File, ?Pred) is nondet.
:- annotate(predicate(file_predicate/2),[
meaning = "File defines NameArity"
]).
% We make file_term_expanded/3 dynamic because
% we assume that repeating term expansion
% is more time-expensive than space-expensive.
:- dynamic file_visited/1. % File
:- dynamic file_term/3. % File, Index, Term
:- dynamic file_term_expanded/3. % File, Index, Term
:- dynamic file_predicate/2. % File, NameArity
:- dynamic file_include/2. % File, Include
:- dynamic unit/1. % File
:- dynamic unit_linked/1. % File
:- dynamic unit_module/2. % File, Module
:- dynamic unit_term/4. % File, Index, Term, Origin
:- dynamic unit_import_list/3. % Importer, Exporter, Imports
:- dynamic unit_export_list/2. % Exporter, Exports
:- dynamic object_annotation/2. % Object, Annotation
:- end_section.
:- section("derived relations").
unit_predicate(Unit, Pred) :-
unit(Unit),
file_predicate_trans(Unit, Pred).
file_predicate_trans(File, Pred) :-
file_predicate(File, Pred).
file_predicate_trans(File, Pred) :-
file_include(File, That),
file_predicate(That, Pred).
get_unit_module(Unit, Module) :-
get_unit_module_or(Unit, Module, throw).
get_unit_module_or(Unit, Module, Alt) :-
unit_module(Unit, Module)
-> true
; case(Alt,[
throw ->
throw_error(unit_module_failed(Unit)),
fail ->
fail,
_ ->
throw_error(invalid_alternative(Alt))
]).
:- end_section.
:- section("dynamic predicates").
assertz_once(G) :-
must_be(ground, G),
call(G) -> true ; assertz(G).
:- end_section.