This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/pl/imports.yap

138 lines
4.1 KiB
Plaintext
Raw Normal View History

2018-06-05 20:51:49 +01:00
/**
** @file imports.yapi
*
* @brief Module systemm code to import predicates
*
* This code does not provide visible builtins.
*/
/**
* @ingroup ModuleBuiltins
* @{
2018-07-11 19:26:02 +01:00
*
* YAP follows the following protovol:
* - predicate is in current module;
* - predicate is in user
* - predicate will be autoloaded, SWI style.
2018-06-05 20:51:49 +01:00
*/
2018-01-18 14:47:27 +00:00
:- '$mk_dynamic'('$parent_module'(_,_),prolog).
2018-03-19 15:41:06 +00:00
2018-01-18 14:47:27 +00:00
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :-
recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_),
'$continue_imported'(ExportingMod, ExportingModI, G0, G0I).
% SWI builtin
'$get_undefined_predicates'(G, _ImportingMod, G, user) :-
nonvar(G),
'$pred_exists'(G, user).
% autoload
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :-
prolog_flag(autoload, true),
prolog_flag(unknown, OldUnk, fail),
(
'$autoload'(G, ImportingMod, ExportingModI, swi)
->
prolog_flag(unknown, _, OldUnk)
;
prolog_flag(unknown, _, OldUnk),
fail
),
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
% parent module mechanism
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :-
'$parent_module'(ImportingMod,ExportingModI),
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
2018-07-11 19:26:02 +01:00
'$get_undefined_predicates'(G, _ImportingMod, G0, ExportingMod) :-
2018-07-03 12:42:33 +01:00
yap_flag(default_parent_module,ExportingModI),
'$continue_imported'(ExportingMod, ExportingModI, G0, G).
2018-01-18 14:47:27 +00:00
'$get_undefined_pred'(G, ImportingMod, G0, ExportingMod) :-
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod),
!.
% be careful here not to generate an undefined exception.
'$imported_predicate'(G, _ImportingMod, G, prolog) :-
nonvar(G), '$is_system_predicate'(G, prolog), !.
'$imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
( var(G) -> true ;
var(ImportingMod) -> true ;
'$undefined'(G, ImportingMod)
),
'$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod),
2018-06-05 20:51:49 +01:00
ExportingMod \= ImportingMod.
2018-07-17 11:43:57 +01:00
% be careful here not to generate an undefined exception.
'$generate_imported_predicate'(G, ImportingMod, G0, ExportingMod) :-
(
recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
;
'$parent_module'(ImportingMod,ExportingModI),
\+ recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_)
),
ImportingMod \= ExportingModI,
(
'$undefined'(G, ExportingModI)
->
'$generate_imported_predicate'(G, ExportingModI, G0, ExportingMod)
;
G=G0,
ExportingModI=ExportingMod
).
/**
*
* @pred '$continue_imported'(+ModIn, +ModOut, +PredIn ,+PredOut)
*
* @return
*/
'$continue_imported'(Mod,Mod,Pred,Pred) :-
'$pred_exists'(Pred, Mod),
!.
'$continue_imported'(FM,Mod,FPred,Pred) :-
recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_),
'$continue_imported'(FM, IM, FPred, IPred), !.
'$continue_imported'(FM,Mod,FPred,Pred) :-
prolog:'$parent_module'(Mod,IM),
'$continue_imported'(FM, IM, FPred, Pred).
'$autoload'(G, _ImportingMod, ExportingMod, Dialect) :-
functor(G, Name, Arity),
'$pred_exists'(index(Name,Arity,ExportingMod,_),Dialect),
call(Dialect:index(Name,Arity,ExportingMod,_)),
!.
'$autoload'(G, ImportingMod, ExportingMod, _Dialect) :-
functor(G, N, K),
functor(G0, N, K),
'$autoloader_find_predicate'(G0,ExportingMod),
ExportingMod \= ImportingMod,
(recordzifnot('$import','$import'(ExportingMod,ImportingMod,G0,G0, N ,K),_) -> true ; true ).
'$autoloader_find_predicate'(G,ExportingModI) :-
'__NB_getval__'('$autoloader_set', true, false), !,
autoloader:find_predicate(G,ExportingModI).
'$autoloader_find_predicate'(G,ExportingModI) :-
yap_flag(autoload, true, false),
yap_flag( unknown, Unknown, fail),
yap_flag(debug, Debug, false), !,
load_files([library(autoloader),
autoloader:library('INDEX'),
swi:library('dialect/swi/INDEX')],
[autoload(true),if(not_loaded)]),
nb_setval('$autoloader_set', true),
yap_flag(autoload, _, true),
yap_flag( unknown, _, Unknown),
yap_flag( debug, _, Debug),
autoloader:find_predicate(G,ExportingModI).
2018-06-05 20:51:49 +01:00
/**
*
* @}
*/