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

70 lines
2.0 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-11 19:26:02 +01:00