/* File: flrsystem.flr ** ** Author(s): Michael Kifer ** Contact: flora-users@lists.sourceforge.net ** ** Copyright (C) The Research Foundation of SUNY, 2001 ** ** FLORA-2 is free software; you can redistribute it and/or modify it under the ** terms of the GNU Library General Public License as published by the Free ** Software Foundation; either version 2 of the License, or (at your option) ** any later version. ** ** FLORA-2 is distributed in the hope that it will be useful, but WITHOUT ANY ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ** FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for ** more details. ** ** You should have received a copy of the GNU Library General Public License ** along with FLORA-2; if not, write to the Free Software Foundation, ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** ** $Id: flrsystem.flr,v 1.17 2003/06/18 07:01:27 kifer Exp $ ** */ #include "standard.h" #include "flora_exceptions.flh" libpath[#add(Path)] :- flora_file_op(expand,Path,ExpandedPath)@prolog(flrporting), ( flora_module_path_get(ExpandedPath)@prolog(flrporting) -> true ; flora_module_path_add(ExpandedPath)@prolog(flrporting) ). libpath[#remove(Path)] :- flora_file_op(expand,Path,ExpandedPath)@prolog(flrporting), flora_module_path_remove(ExpandedPath)@prolog(flrporting). libpath[#query(Path)] :- atom(Path)@prolog(), !, flora_file_op(expand,Path,ExpandedPath)@prolog(flrporting), flora_module_path_get(ExpandedPath)@prolog(flrporting). libpath[#query(Path)] :- var(Path)@prolog(), !, flora_module_path_get(Path)@prolog(flrporting). libpath[#query(_Path)] :- abort('libpath[#query(Path)]@flora(sys): Argument must be atom or variable')@flora(sys). tables[#abolish] :- abolish_all_tables@prolog(). abort(X) :- p2h{PX,X}, flora_abort(PX). warning(X) :- p2h{PX,X}, flora_warning_heading@prolog(flrprint), %%flora_stderr_string('[Runtime] ')@prolog(flrprint), message(PX,STDERR)@prolog(standard), flora_stderr_nl@prolog(flrprint). %% Put a message on stderr message(X) :- p2h{PX,X}, message(PX,STDERR)@prolog(standard), flora_stderr_nl@prolog(flrprint). debug[#check_undefined(Flag)] :- var(Flag)@prolog(), !, ( flora_in_debug_mode(_)@prolog(flrregistry), Flag=on, ! ; Flag=off ). debug[#check_undefined(on)] :- !, (flora_in_debug_mode(_)@prolog(flrregistry),!; assert(flora_in_debug_mode(1)@prolog(flrregistry))@prolog(), findall(M, (flora_module_registry(M), \+ flora_debug_module_registry(M))@prolog(flrregistry), ML)@prolog(), turn_on_debug_all(ML)). debug[#check_undefined(off)] :- !, retractall(flora_in_debug_mode(_)@prolog(flrregistry))@prolog(), findall(M,flora_debug_module_registry(M)@prolog(flrregistry),ML)@prolog(), turn_off_debug_all(ML). debug[#check_undefined(InvalidOpt)] :- %% Note: this abort is defined in this module abort(('Invalid option in #check_undefined: ', InvalidOpt)), fail. debug[#check_undefined(_Flag,Module)] :- ( var(Module)@prolog(), %% Note: this abort defined in this module abort(('Invalid module name in #check_undefined: ', Module)) ; Module\=flora(_), \+ flora_module_registry(Module)@prolog(flrregistry), %% Note: this abort defined in this module abort(('Unloaded module name in #check_undefined: ', Module)) ). debug[#check_undefined(Flag,Module)] :- var(Flag)@prolog(), !, ( Module=flora(SysModId), Mname=..[flora,SysModId], (flora_module_registry(Mname)@prolog(flrregistry), ! ; flora_load_system_module_internal(SysModId)@prolog(flrutils) ) ; Module\=flora(_), Mname=Module ), ( flora_debug_module_registry(Mname)@prolog(flrregistry), Flag=on, ! ; Flag=off ). debug[#check_undefined(on,Module)] :- !, ( Module=flora(SysModId), Mname=..[flora,SysModId], (flora_module_registry(Mname)@prolog(flrregistry), ! ; flora_load_system_module_internal(SysModId)@prolog(flrutils) ) ; Module\=flora(_), Mname=Module ), (flora_debug_module_registry(Mname)@prolog(flrregistry),! ; turn_on_debug(Mname) ). debug[#check_undefined(off,Module)] :- !, ( Module=flora(SysModId), Mname=..[flora,SysModId], (flora_module_registry(Mname)@prolog(flrregistry), ! ; flora_load_system_module_internal(SysModId)@prolog(flrutils) ) ; Module\=flora(_), Mname=Module ), (\+ flora_debug_module_registry(Mname)@prolog(flrregistry), ! ; turn_off_debug(Mname) ). debug[#check_undefined(InvalidOpt,_Module)] :- %% Note: this abort is defined in this module abort(('Invalid option in #check_undefined: ', InvalidOpt)). turn_on_debug_all([]) :- !. turn_on_debug_all([H|L]) :- turn_on_debug(H), turn_on_debug_all(L). turn_on_debug(Module) :- assert(flora_debug_module_registry(Module)@prolog(flrregistry))@prolog(). turn_off_debug_all([]) :- !. turn_off_debug_all([H|L]) :- turn_off_debug(H), turn_off_debug_all(L). turn_off_debug(Module) :- retractall(flora_debug_module_registry(Module)@prolog(flrregistry))@prolog(). %% Takes a call, P. If P is false then fails. If P is true or %% undefined, succeeds. If P is true, then List is []. If P is %% undefined, then List is the residual of P. table_state(Pred,List) :- flora_decode_predicate(Pred,hilog,Module,_Prefix,PName,AList)@prolog(flrwrapper), flora_tabled_hilog_module_predicate_symbol(Module,Wrapper)@prolog(flrwrapper), P =.. [Wrapper,0,PName|AList], complete_table(P), !, NewP =.. [Wrapper,_RN,PName|AList], get_residual(NewP,List)@prolog(tables). complete_table(P) :- P, fail. complete_table(_) :- !.