SWI-compatible source_file/1 and 2
This commit is contained in:
parent
ba7861b218
commit
16a9c8a807
24
C/cdmgr.c
24
C/cdmgr.c
@ -2975,6 +2975,29 @@ p_is_source(void)
|
|||||||
return(out);
|
return(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_owner_file(void)
|
||||||
|
{ /* '$owner_file'(+P,M,F) */
|
||||||
|
PredEntry *pe;
|
||||||
|
Atom owner;
|
||||||
|
|
||||||
|
pe = get_pred(Deref(ARG1), Deref(ARG2), "$is_source");
|
||||||
|
if (EndOfPAEntr(pe))
|
||||||
|
return FALSE;
|
||||||
|
LOCK(pe->PELock);
|
||||||
|
if (pe->ModuleOfPred == IDB_MODULE) {
|
||||||
|
UNLOCK(pe->PELock);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (pe->PredFlags & MultiFileFlag) {
|
||||||
|
UNLOCK(pe->PELock);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
owner = pe->src.OwnerFile
|
||||||
|
UNLOCK(pe->PELock);
|
||||||
|
return Yap_unify(ARG3, MkAtomTerm(owner));
|
||||||
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
p_mk_d(void)
|
p_mk_d(void)
|
||||||
{ /* '$is_dynamic'(+P) */
|
{ /* '$is_dynamic'(+P) */
|
||||||
@ -5593,6 +5616,7 @@ Yap_InitCdMgr(void)
|
|||||||
Yap_InitCPred("$is_expand_goal_or_meta_predicate", 2, p_is_expandgoalormetapredicate, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
Yap_InitCPred("$is_expand_goal_or_meta_predicate", 2, p_is_expandgoalormetapredicate, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$is_log_updatable", 2, p_is_log_updatable, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
Yap_InitCPred("$is_log_updatable", 2, p_is_log_updatable, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$is_source", 2, p_is_source, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
Yap_InitCPred("$is_source", 2, p_is_source, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
||||||
|
Yap_InitCPred("$owner_file", 3, p_owner_file, SafePredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$mk_d", 2, p_mk_d, SafePredFlag|HiddenPredFlag);
|
Yap_InitCPred("$mk_d", 2, p_mk_d, SafePredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$pred_exists", 2, p_pred_exists, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
Yap_InitCPred("$pred_exists", 2, p_pred_exists, TestPredFlag | SafePredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$number_of_clauses", 3, p_number_of_clauses, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("$number_of_clauses", 3, p_number_of_clauses, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
|
13
docs/yap.tex
13
docs/yap.tex
@ -8159,6 +8159,19 @@ Stream position at the stream currently being read in.
|
|||||||
@cnindex source_location/2
|
@cnindex source_location/2
|
||||||
SWI-compatible predicate. If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file. Please use @code{prolog_load_context/2}.
|
SWI-compatible predicate. If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file. Please use @code{prolog_load_context/2}.
|
||||||
|
|
||||||
|
@item source_file(?@var{File})
|
||||||
|
@findex source_file/1
|
||||||
|
@syindex source_file/1
|
||||||
|
@cnindex source_file/1
|
||||||
|
SWI-compatible predicate. True if @var{File} is a loaded Prolog source file.
|
||||||
|
|
||||||
|
@item source_file(?@var{ModuleAndPred},?@var{File})
|
||||||
|
@findex source_file/2
|
||||||
|
@syindex source_file/2
|
||||||
|
@cnindex source_file/2
|
||||||
|
SWI-compatible predicate. True if the predicate specified by @var{ModuleAndPred} was loaded from file @var{File}, where @var{File} is an absolute path name (see @code{absolute_file_name/2}).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@ -425,6 +425,23 @@ use_module(M,F,Is) :-
|
|||||||
'$skip_unix_comments'(_).
|
'$skip_unix_comments'(_).
|
||||||
|
|
||||||
|
|
||||||
|
source_file(FileName) :-
|
||||||
|
recorded('$lf_loaded','$lf_loaded'(FileName,Mod,_,_),_), Mod \= prolog.
|
||||||
|
|
||||||
|
source_file(Mod:Pred, FileName) :-
|
||||||
|
current_module(Mod),
|
||||||
|
Mod \= prolog,
|
||||||
|
'$current_predicate_no_modules'(Mod,_,Pred),
|
||||||
|
'$owned_by'(Pred, Mod, FileName).
|
||||||
|
|
||||||
|
'$owned_by'(T, Mod, FileName) :-
|
||||||
|
'$is_multifile'(T, Mod),
|
||||||
|
functor(T, Name, Arity),
|
||||||
|
setof(FileName, Ref^recorded('$multifile_defs','$defined'(FileName,Name,Arity,Mod), Ref), L),
|
||||||
|
lists:member(FileName, L).
|
||||||
|
'$owned_by'(T, Mod, FileName) :-
|
||||||
|
'$owner_file'(T, Mod, FileName).
|
||||||
|
|
||||||
source_location(FileName, Line) :-
|
source_location(FileName, Line) :-
|
||||||
prolog_load_context(file, FileName),
|
prolog_load_context(file, FileName),
|
||||||
prolog_load_context(term_position,'$stream_position'(_, Line, _, _, _)).
|
prolog_load_context(term_position,'$stream_position'(_, Line, _, _, _)).
|
||||||
|
Reference in New Issue
Block a user