-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathload.pro
More file actions
97 lines (75 loc) · 2.9 KB
/
Copy pathload.pro
File metadata and controls
97 lines (75 loc) · 2.9 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
% Deprecated: Use load0.pro instead.
:- consult("debug.pro").
:- include("imperative.pro").
:- include("genmod.pro").
:- debug(load). % DEBUG
%:- debug(import_expansion). % DEBUG
% -------------------- process import/2 directives
system:term_expansion(:- import(Src,Imps), Exps) :-
load_source_once(Src, Mod),
findall(Exp, (member(Imp,Imps), import_expansion(Mod,Imp,Exp)), Exps).
% -------------------- actual loading of sources
% Keep track of loaded files.
:- dynamic module_file/2.
load_source_once(file(Rel), Mod) :- !,
prolog_load_context(file, Src),
absolute_file_name(Rel, Abs, [relative_to(Src)]),
(module_file(Mod, Abs)
-> true
; generate_module_name(Abs, Mod),
debug(load, "abs_load_once: loading file ~w into ~w", [Abs,Mod]),
'@'(system:load_files(Abs,[module(Mod)]), Mod),
assertz(module_file(Mod,Abs))
).
load_source_once(A, _) :- !, type_error(import_source, A).
% -------------------- import_expansion/2
import_expansion(Mod, Name/Arity, Exp) :- !,
check_predicate(defined(Mod:Name/Arity)),
Exp = (Head :- Mod:Head),
functor(Head, Name, Arity),
debug(import_expansion, "import_expansion: ~w", [Exp]).
import_expansion(Mod, Name//DcgArity, Exp) :- !,
Arity is DcgArity + 2,
import_expansion(Mod, Name/Arity, Exp).
import_expansion(Mod, Name/Arity as Alias, Exp) :- !,
check_predicate(defined(Mod:Name/Arity)),
Exp = (Renamed :- Mod:Orig),
functor(Orig, Name, Arity),
functor(Renamed, Alias, Arity),
foreach(between(1,Arity,N), arg_unify(N,Orig,Renamed)),
debug(import_expansion, "import_expansion: ~w", [Exp]).
import_expansion(Mod, multifile(Name/Arity), Exp) :- !,
check_predicate(multifile(Mod:Name/Arity)),
Exp = (Mod:Head :- Head),
functor(Head, Name, Arity),
debug(import_expansion, "import_expansion: ~w", [Exp]).
import_expansion(Mod, multifiles(List), Exps) :- !,
findall(
Exp,
(member(Spec,List), import_expansion(Mod,multifile(Spec),Exp)),
Exps
).
import_expansion(_, A, _) :- !,
type_error(import_spec, A).
check_predicate(defined(Module:Name/Arity)) :- !,
functor(Head, Name, Arity),
(predicate_property(Module:Head, defined)
-> true
; existence_error(predicate, Module:Name/Arity)).
check_predicate(multifile(Module:Name/Arity)) :- !,
check_predicate(defined(Module:Name/Arity)),
functor(Head, Name, Arity),
(predicate_property(Module:Head, multifile)
-> true
; type_error(multifile_predicate, Module:Name/Arity)).
check_predicate(Exp) :- !,
type_error(check_predicate_exp, Exp).
%% arg_unify(?N, ?Functor1, ?Functor2) is nondet.
% Unify argument N of Functor1 and argument N of Functor2.
arg_unify(N,F,G) :- arg(N,F,A), arg(N,G,A).
% -------------------- load files specified on command-line arguments
:- current_prolog_flag(argv, Argv),
forall(
member(Arg, Argv),
consult(Arg)
).