This commit is contained in:
Vitor Santos Costa 2018-03-14 00:41:05 +00:00
parent 1a8c26b886
commit c33a0d72db
15 changed files with 264 additions and 298 deletions

View File

@ -125,7 +125,7 @@ static void init_globals(YAP_init_args *yap_init) {
has been overwritten .... has been overwritten ....
*/ */
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
yap_init->HaltAfterConsult); yap_init->HaltAfterBoot);
} }
if (yap_init->PrologTopLevelGoal) { if (yap_init->PrologTopLevelGoal) {
Yap_PutValue(AtomTopLevelGoal, Yap_PutValue(AtomTopLevelGoal,
@ -699,7 +699,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
goto GetSize; goto GetSize;
} }
iap->QuietMode = TRUE; iap->QuietMode = TRUE;
iap->HaltAfterConsult = TRUE; iap->HaltAfterBoot = true;
case 'l': case 'l':
p++; p++;
if (!*++argv) { if (!*++argv) {
@ -759,6 +759,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
argv++; argv++;
iap->PrologTopLevelGoal = add_end_dot(*argv); iap->PrologTopLevelGoal = add_end_dot(*argv);
} }
iap->HaltAfterBoot = true;
break; break;
case 'n': case 'n':
if (!strcmp("nosignals", p)) { if (!strcmp("nosignals", p)) {
@ -967,10 +968,10 @@ static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) {
#endif #endif
} }
static YAP_file_type_t end_init(YAP_init_args *yap_init, YAP_file_type_t rc) { static void end_init(YAP_init_args *iap) {
YAP_initialized = true; YAP_initialized = true;
if (iap->HaltAfterBoot) Yap_exit(0);
LOCAL_PrologMode &= ~BootMode; LOCAL_PrologMode &= ~BootMode;
return rc;
} }
static void start_modules(void) { static void start_modules(void) {
@ -986,14 +987,14 @@ static void start_modules(void) {
/* this routine is supposed to be called from an external program /* this routine is supposed to be called from an external program
that wants to control Yap */ that wants to control Yap */
X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { X_API void YAP_Init(YAP_init_args *yap_init) {
YAP_file_type_t restore_result = yap_init->boot_file_type; bool try_restore = yap_init->boot_file_type == YAP_QLY;
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE); bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL;
struct ssz_t minfo; struct ssz_t minfo;
if (YAP_initialized) if (YAP_initialized)
/* ignore repeated calls to YAP_Init */ /* ignore repeated calls to YAP_Init */
return YAP_FOUND_BOOT_ERROR; return;
if (!LOCAL_TextBuffer) if (!LOCAL_TextBuffer)
LOCAL_TextBuffer = Yap_InitTextAllocator(); LOCAL_TextBuffer = Yap_InitTextAllocator();
@ -1007,7 +1008,7 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
// //
CACHE_REGS CACHE_REGS
if (Yap_embedded)
if (yap_init->QuietMode) { if (yap_init->QuietMode) {
setVerbosity(TermSilent); setVerbosity(TermSilent);
} }
@ -1017,29 +1018,34 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
restore will print out messages .... restore will print out messages ....
*/ */
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
yap_init->HaltAfterConsult); yap_init->HaltAfterBoot);
} }
/* tell the system who should cope with interrupts */ /* tell the system who should cope with interrupts */
Yap_ExecutionMode = yap_init->ExecutionMode; Yap_ExecutionMode = yap_init->ExecutionMode;
Yap_set_locations(yap_init); Yap_set_locations(yap_init);
if (!do_bootstrap && Yap_INPUT_STARTUP && if (do_bootstrap ||
yap_init->boot_file_type != YAP_BOOT_PL && !try_restore ||
Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack, !Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
&minfo.Heap) && &minfo.Heap) ) {
Yap_Restore(Yap_INPUT_STARTUP)) {
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
CurrentModule = LOCAL_SourceModule = USER_MODULE;
init_globals(yap_init);
YAP_RunGoalOnce(TermInitProlog);
start_modules();
return end_init(yap_init, YAP_QLY);
} else {
init_globals(yap_init); init_globals(yap_init);
start_modules(); start_modules();
consult(Yap_BOOTSTRAP PASS_REGS); consult(Yap_BOOTSTRAP PASS_REGS);
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
} else {
Yap_Restore(Yap_INPUT_STARTUP);
init_globals(yap_init);
start_modules();
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
}
YAP_RunGoalOnce(TermInitProlog);
if (yap_init->install && Yap_OUTPUT_STARTUP) { if (yap_init->install && Yap_OUTPUT_STARTUP) {
Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP)); Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP));
Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1), Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1),
@ -1047,11 +1053,7 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
YAP_RunGoalOnce(g); YAP_RunGoalOnce(g);
} }
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, end_init(yap_init);
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
return end_init(yap_init, YAP_BOOT_PL);
}
} }
#if (DefTrailSpace < MinTrailSpace) #if (DefTrailSpace < MinTrailSpace)
@ -1073,15 +1075,14 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
#define DEFAULT_SCHEDULERLOOP 10 #define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3 #define DEFAULT_DELAYEDRELEASELOAD 3
X_API YAP_file_type_t YAP_FastInit(char *saved_state, int argc, char *argv[]) { X_API void YAP_FastInit(char *saved_state, int argc, char *argv[]) {
YAP_init_args init_args; YAP_init_args init_args;
YAP_file_type_t out; YAP_file_type_t out;
if ((out = Yap_InitDefaults(&init_args, saved_state, argc, argv)) != if ((out = Yap_InitDefaults(&init_args, saved_state, argc, argv)) !=
YAP_FOUND_BOOT_ERROR) YAP_FOUND_BOOT_ERROR)
out = YAP_Init(&init_args); YAP_Init(&init_args);
if (out == YAP_FOUND_BOOT_ERROR) { if (out == YAP_FOUND_BOOT_ERROR) {
Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause); Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
} }
return out;
} }

View File

@ -243,6 +243,7 @@ Term &YAPTerm::operator[](arity_t i) {
Yap_Error(TYPE_ERROR_COMPOUND, t0, ""); Yap_Error(TYPE_ERROR_COMPOUND, t0, "");
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return (tf);
} }
Term &YAPListTerm::operator[](arity_t i) { Term &YAPListTerm::operator[](arity_t i) {
@ -842,11 +843,12 @@ void Yap_displayWithJava(int c) {
#endif #endif
void YAPEngine::doInit(YAP_file_type_t BootMode, YAPEngineArgs *engineArgs) { void YAPEngine::doInit(YAP_file_type_t BootMode, YAPEngineArgs *engineArgs) {
if ((BootMode = YAP_Init(engineArgs)) == YAP_FOUND_BOOT_ERROR) { if (BootMode == YAP_FOUND_BOOT_ERROR) {
std::cerr << "Exception received by " << __func__ << "( " std::cerr << "Exception received by " << __func__ << "( "
<< "while booting" << ").\n Forwarded...\n\n"; << "while booting" << ").\n Forwarded...\n\n";
return; return;
} }
YAP_Init(engineArgs);
/* Begin preprocessor code */ /* Begin preprocessor code */
/* live */ /* live */
// yerror = YAPError(); // yerror = YAPError();

View File

@ -263,9 +263,9 @@ public:
inline const char *getPrologTopLevelGoal() { return PrologTopLevelGoal; }; inline const char *getPrologTopLevelGoal() { return PrologTopLevelGoal; };
inline void setHaltAfterConsult(bool fl) { HaltAfterConsult = fl; }; inline void setHaltAfterBoot(bool fl) { HaltAfterBoot = fl; };
inline bool getHaltAfterConsult() { return HaltAfterConsult; }; inline bool getHaltAfterBoot() { return HaltAfterBoot; };
inline void setFastBoot(bool fl) { FastBoot = fl; }; inline void setFastBoot(bool fl) { FastBoot = fl; };

View File

@ -78,7 +78,8 @@ static int init_standard_system(int argc, char *argv[], YAP_init_args *iap) {
BootMode = YAP_parse_yap_arguments(argc, argv, iap); BootMode = YAP_parse_yap_arguments(argc, argv, iap);
iap->Embedded = false; iap->Embedded = false;
/* init memory */ /* init memory */
iap->boot_file_type = BootMode = YAP_Init(iap); iap->boot_file_type = BootMode;
YAP_Init(iap);
if (iap->ErrorNo) { if (iap->ErrorNo) {
/* boot failed */ /* boot failed */
YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause); YAP_Error(iap->ErrorNo, 0L, iap->ErrorCause);

View File

@ -234,7 +234,7 @@ typedef struct yap_boot_params {
//> if NON-NULL, a path to extend file-search-path //> if NON-NULL, a path to extend file-search-path
const char *PrologAddPath; const char *PrologAddPath;
//> if previous NON-NULL and TRUE, halt after consulting that file //> if previous NON-NULL and TRUE, halt after consulting that file
bool HaltAfterConsult; bool HaltAfterBoot;
//> ignore .yaprc, .prolog.ini, etc. files. //> ignore .yaprc, .prolog.ini, etc. files.
bool FastBoot; bool FastBoot;
//> the next field only interest YAPTAB //> the next field only interest YAPTAB

View File

@ -378,10 +378,10 @@ extern X_API int YAP_AssertTuples(YAP_PredEntryPtr pred, const YAP_Term *ts,
size_t offset, size_t sz); size_t offset, size_t sz);
/* int YAP_Init(YAP_init_args *) */ /* int YAP_Init(YAP_init_args *) */
extern X_API YAP_file_type_t YAP_Init(YAP_init_args *); extern X_API void YAP_Init(YAP_init_args *);
/* int YAP_FastInit(const char *) */ /* int YAP_FastInit(const char *) */
extern X_API YAP_file_type_t YAP_FastInit(char saved_state[], int argc, extern X_API void YAP_FastInit(char saved_state[], int argc,
char *argv[]); char *argv[]);
#ifndef _PL_STREAM_H #ifndef _PL_STREAM_H

View File

@ -2200,7 +2200,7 @@ X_API int PL_initialise(int myargc, char **myargv) {
#endif #endif
init_args.LIBDIR = NULL; init_args.LIBDIR = NULL;
init_args.BOOTFILE = NULL; init_args.BOOTFILE = NULL;
init_args.HaltAfterConsult = FALSE; init_args.HaltAfterBoot = true;
init_args.FastBoot = FALSE; init_args.FastBoot = FALSE;
init_args.MaxTableSpaceSize = 0; init_args.MaxTableSpaceSize = 0;
init_args.NumberWorkers = 1; init_args.NumberWorkers = 1;
@ -2212,9 +2212,9 @@ X_API int PL_initialise(int myargc, char **myargv) {
GLOBAL_PL_Argc = myargc; GLOBAL_PL_Argc = myargc;
GLOBAL_PL_Argv = myargv; GLOBAL_PL_Argv = myargv;
GLOBAL_InitialisedFromPL = true; GLOBAL_InitialisedFromPL = true;
YAP_file_type_t rc = YAP_Init(&init_args) != YAP_FOUND_BOOT_ERROR;
ATOM_nil = YAP_SWIAtomFromAtom(AtomNil); ATOM_nil = YAP_SWIAtomFromAtom(AtomNil);
return rc; YAP_Init(&init_args);
return true;
} }
X_API int PL_is_initialised(int *argcp, char ***argvp) { X_API int PL_is_initialised(int *argcp, char ***argvp) {

View File

@ -643,16 +643,18 @@ static PyGILState_STATE gstate;
// if (_locked > 0) { _locked++ ; } // if (_locked > 0) { _locked++ ; }
// else // else
gstate = PyGILState_Ensure(); gstate = PyGILState_Ensure();
fprintf(stderr, "+%d\n", (int)gstate);
PL_put_integer(curSlot, gstate); PL_put_integer(curSlot, gstate);
pyErrorAndReturn(curSlot, false); pyErrorAndReturn(curSlot, false);
} }
bool python_release_GIL(term_t curBlock) { bool python_release_GIL(term_t curBlock) {
PyGILState_STATE gstate; PyGILState_STATE gstate;
PyErr_Clear();
if (_threaded) { if (_threaded) {
PL_get_integer(curBlock, &gstate); PL_get_integer(curBlock, &gstate);
PyGILState_Release(gstate); PyGILState_Release(gstate);
fprintf(stderr, "-%d\n", (int)gstate);
} }
PL_reset_term_refs(curBlock); PL_reset_term_refs(curBlock);
pyErrorAndReturn(true, false); pyErrorAndReturn(true, false);

View File

@ -522,8 +522,7 @@ class InteractiveShell(SingletonConfigurable):
# The following was in post_config_initialization # The following was in post_config_initialization
self.init_inspector() self.init_inspector()
self.raw_input_original = input self.raw_input_original = input
self.input_splitter.engine(self.yapeng) #self.input_transformer_manager.engine(self.yapeng)
self.input_transformer_manager.engine(self.yapeng)
self.init_completer() self.init_completer()
# TODO: init_io() needs to happen before init_traceback handlers # TODO: init_io() needs to happen before init_traceback handlers
# because the traceback handlers hardcode the stdout/stderr streams. # because the traceback handlers hardcode the stdout/stderr streams.
@ -2671,7 +2670,6 @@ class InteractiveShell(SingletonConfigurable):
self.events.trigger('post_execute') self.events.trigger('post_execute')
if not silent: if not silent:
self.events.trigger('post_run_cell', result) self.events.trigger('post_run_cell', result)
print("go", result)
return result return result
def _run_cell(self, raw_cell, store_history, silent, shell_futures): def _run_cell(self, raw_cell, store_history, silent, shell_futures):

View File

@ -59,11 +59,12 @@ class YAPInputSplitter(InputSplitter):
# List with lines of raw input accumulated so far. # List with lines of raw input accumulated so far.
_buffer_raw = None _buffer_raw = None
def __init__(self, line_input_checker=True, physical_line_transforms=None, def __init__(self, engine=None, shell=None, line_input_checker=True, physical_line_transforms=None,
logical_line_transforms=None): logical_line_transforms=None):
self._buffer_raw = [] self._buffer_raw = []
self._validate = True self._validate = True
self.yapeng = None self.yapeng = engine
self.shell = shell
if physical_line_transforms is not None: if physical_line_transforms is not None:
self.physical_line_transforms = physical_line_transforms self.physical_line_transforms = physical_line_transforms
@ -102,19 +103,16 @@ class YAPInputSplitter(InputSplitter):
[self.assemble_logical_lines] + self.logical_line_transforms [self.assemble_logical_lines] + self.logical_line_transforms
return t return t
def engine(self, engine): def validQuery(self, text, engine, shell, line=None):
self.yapeng = engine
def validQuery(self, text, line=None):
"""Return whether a legal query """Return whether a legal query
""" """
if text == self.shell.os: if text == shell.os:
return True return True
if not line: if not line:
line = text.rstrip() line = text.rstrip()
(line, _, _, _)=self.shell.clean_end(line) (line, _, _, _)=self.shell.clean_end(line)
self.errors = [] self.errors = []
self.yapeng.mgoal(errors(self, line),"user") engine.mgoal(errors(self, line),"user")
return self.errors != [] return self.errors != []
@ -183,7 +181,7 @@ class YAPInputSplitter(InputSplitter):
if self.transformer_accumulating: if self.transformer_accumulating:
return True return True
else: else:
return self,validQuery(self.source) return self.validQuery(self.source, self.yapeng, self)
def transform_cell(self, cell): def transform_cell(self, cell):
"""Process and translate a cell of input. """Process and translate a cell of input.

View File

@ -472,7 +472,18 @@ class YAPKernelApp(BaseYAPApplication, InteractiveShellApp,
return self.subapp.start() return self.subapp.start()
if self.poller is not None: if self.poller is not None:
self.poller.start() self.poller.start()
self.kernel.start()
import trace
#create a Trace object, telling it what to ignore, and whether to
# do tracing or line-counting or both.
tracer = trace.Trace(
#ignoredirs=[sys.prefix, sys.exec_prefix],
trace=1,
count=0)
tracer.runfunc(self.kernel.start)
#self.kernel.start()
self.io_loop = ioloop.IOLoop.current() self.io_loop = ioloop.IOLoop.current()
try: try:
self.io_loop.start() self.io_loop.start()
@ -485,6 +496,7 @@ def main():
"""Run an IPKernel as an application""" """Run an IPKernel as an application"""
app = YAPKernelApp.instance() app = YAPKernelApp.instance()
app.initialize() app.initialize()
app.start() app.start()

View File

@ -202,6 +202,7 @@ print_message(L,E) :-
:- c_compile('directives.yap'). :- c_compile('directives.yap').
:- c_compile('init.yap').
'$command'(C,VL,Pos,Con) :- '$command'(C,VL,Pos,Con) :-
current_prolog_flag(strict_iso, true), !, /* strict_iso on */ current_prolog_flag(strict_iso, true), !, /* strict_iso on */
@ -223,8 +224,6 @@ print_message(L,E) :-
:- c_compile('arith.yap'). :- c_compile('arith.yap').
%:- stop_low_level_trace. %:- stop_low_level_trace.
:- '$init_prolog'.
:- compile_expressions. :- compile_expressions.

View File

@ -15,3 +15,188 @@
* * * *
*************************************************************************/ *************************************************************************/
'$init_globals' :-
% set_prolog_flag(break_level, 0),
% '$set_read_error_handler'(error), let the user do that
nb_setval('$chr_toplevel_show_store',false).
'$init_consult' :-
set_value('$open_expands_filename',true),
nb_setval('$assert_all',off),
nb_setval('$if_level',0),
nb_setval('$endif',off),
nb_setval('$initialization_goals',off),
nb_setval('$included_file',[]),
nb_setval('$loop_streams',[]),
\+ '$undefined'('$init_preds',prolog),
'$init_preds',
fail.
'$init_consult'.
'$init_win_graphics' :-
'$undefined'(window_title(_,_), system), !.
'$init_win_graphics' :-
load_files([library(win_menu)], [silent(true),if(not_loaded)]),
fail.
'$init_win_graphics'.
'$init_or_threads' :-
'$c_yapor_workers'(W), !,
'$start_orp_threads'(W).
'$init_or_threads'.
'$start_orp_threads'(1) :- !.
'$start_orp_threads'(W) :-
thread_create('$c_worker',_,[detached(true)]),
W1 is W-1,
'$start_orp_threads'(W1).
'$version' :-
current_prolog_flag(verbose, normal), !,
current_prolog_flag(version_git,VersionGit),
current_prolog_flag(compiled_at,AT),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
current_prolog_flag(resource_database, Saved ),
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
format(user_error, '% database loaded from ~a~n', [Saved]).
'$version'.
/**
* Initialise a Prolog engine.
*
* Must be called after restoring.
*/
'$init_prolog' :-
% do catch as early as possible
'$version',
yap_flag(file_name_variables, _OldF, true),
'$init_consult',
%set_prolog_flag(file_name_variables, OldF),
'$init_globals',
set_prolog_flag(fileerrors, true),
set_value('$gc',on),
('$exit_undefp' -> true ; true),
prompt1(' ?- '),
set_prolog_flag(debug, false),
% simple trick to find out if this is we are booting from Prolog.
% boot from a saved state
'$init_from_saved_state_and_args', %start_low_level_trace,
'$db_clean_queues'(0),
% this must be executed from C-code.
% '$startup_saved_state',
set_input(user_input),
set_output(user_output),
'$init_or_threads',
'$run_at_thread_start'.
% then we can execute the programs.
'$startup_goals' :-
module(user),
fail.
'$startup_goals' :-
recorded('$startup_goal',G,_),
catch(once(user:G),Error,user:'$Error'(Error)),
fail.
'$startup_goals' :-
get_value('$init_goal',GA),
GA \= [],
set_value('$init_goal',[]),
'$run_atom_goal'(GA),
fail.
'$startup_goals' :-
recorded('$restore_flag', goal(Module:GA), R),
erase(R),
catch(once(Module:GA),Error,user:'$Error'(Error)),
fail.
'$startup_goals' :-
get_value('$myddas_goal',GA), GA \= [],
set_value('$myddas_goal',[]),
get_value('$myddas_user',User), User \= [],
set_value('$myddas_user',[]),
get_value('$myddas_db',Db), Db \= [],
set_value('$myddas_db',[]),
get_value('$myddas_host',HostT),
( HostT \= [] ->
Host = HostT,
set_value('$myddas_host',[])
;
Host = localhost
),
get_value('$myddas_pass',PassT),
( PassT \= [] ->
Pass = PassT,
set_value('$myddas_pass',[])
;
Pass = ''
),
use_module(library(myddas)),
call(db_open(mysql,myddas,Host/Db,User,Pass)),
'$myddas_import_all',
fail.
'$startup_goals'.
%
% MYDDAS: Import all the tables from one database
%
'$myddas_import_all':-
call(db_my_show_tables(myddas,table(Table))),
call(db_import(myddas,Table,Table)),
fail.
'$myddas_import_all'.
% use if we come from a save_program and we have SWI's shlib
'$init_from_saved_state_and_args' :-
current_prolog_flag(hwnd, _HWND),
load_files(library(win_menu), [silent(true)]),
fail.
'$init_from_saved_state_and_args' :-
recorded('$reload_foreign_libraries',_G,R),
erase(R),
shlib:reload_foreign_libraries,
fail.
% this should be done before -l kicks in.
'$init_from_saved_state_and_args' :-
current_prolog_flag(fast_boot, false),
( exists('~/.yaprc') -> load_files('~/.yaprc', []) ; true ),
( exists('~/.prologrc') -> load_files('~/.prologrc', []) ; true ),
( exists('~/prolog.ini') -> load_files('~/prolog.ini', []) ; true ),
fail.
% use if we come from a save_program and we have a goal to execute
'$init_from_saved_state_and_args' :-
get_value('$consult_on_boot',X), X \= [],
set_value('$consult_on_boot',[]),
'$do_startup_reconsult'(X),
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_flag', init_file(M:B), R),
erase(R),
'$do_startup_reconsult'(M:B),
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_flag', unknown(M:B), R),
erase(R),
yap_flag(M:unknown,B),
fail.
'$init_from_saved_state_and_args' :-
'$startup_goals',
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_goal',G,R),
erase(R),
prompt(_,'| '),
catch(once(user:G),Error,user:'$Error'(Error)),
fail.
'$init_path_extensions' :-
get_value('$extend_file_search_path',P), !,
P \= [],
set_value('$extend_file_search_path',[]),
'$extend_file_search_path'(P).
'$init_path_extensions'.

View File

@ -241,161 +241,7 @@ qend_program :-
X \= os_argv, X \= os_argv,
X \= language, X \= language,
X \= encoding. X \= encoding.
'$init_state' :-
(
recorded('$program_state', _P, R)
->
erase(R),
'$do_init_state'
;
true
).
'$do_init_state' :-
'$undefp_handler'('$undefp'(_,_), prolog),
fail. fail.
'$do_init_state' :-
set_value('$user_module',user),
'$protect',
fail.
'$do_init_state' :-
compile_expressions,
'$init_preds',
fail.
'$do_init_state' :-
recorded('$program_state',L,R),
erase(R),
lists:member(F-V,L),
catch(yap_flag(F,V),Error,user:'$Error'(Error)),
fail.
'$do_init_state' :-
'$reinit_thread0',
fail.
'$do_init_state' :-
'$current_module'(prolog),
module(user),
fail.
'$do_init_state' :-
'$init_from_saved_state_and_args',
fail.
'$do_init_state' :-
stream_property(user_input, tty(true)),
set_prolog_flag(readline, true).
'$do_init_state'.
%
% first, recover what we need from the saved state...
%'
'$init_from_saved_state_and_args' :-
'$init_path_extensions',
fail.
% use if we come from a save_program and we have SWI's shlib
'$init_from_saved_state_and_args' :-
current_prolog_flag(hwnd, _HWND),
load_files(library(win_menu), [silent(true)]),
fail.
'$init_from_saved_state_and_args' :-
recorded('$reload_foreign_libraries',_G,R),
erase(R),
shlib:reload_foreign_libraries,
fail.
% this should be done before -l kicks in.
'$init_from_saved_state_and_args' :-
current_prolog_flag(fast_boot, false),
( exists('~/.yaprc') -> load_files('~/.yaprc', []) ; true ),
( exists('~/.prologrc') -> load_files('~/.prologrc', []) ; true ),
( exists('~/prolog.ini') -> load_files('~/prolog.ini', []) ; true ),
fail.
% use if we come from a save_program and we have a goal to execute
'$init_from_saved_state_and_args' :-
get_value('$consult_on_boot',X), X \= [],
set_value('$consult_on_boot',[]),
'$do_startup_reconsult'(X),
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_flag', init_file(M:B), R),
erase(R),
'$do_startup_reconsult'(M:B),
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_flag', unknown(M:B), R),
erase(R),
yap_flag(M:unknown,B),
fail.
'$init_from_saved_state_and_args' :-
'$startup_goals',
fail.
'$init_from_saved_state_and_args' :-
recorded('$restore_goal',G,R),
erase(R),
prompt(_,'| '),
catch(once(user:G),Error,user:'$Error'(Error)),
fail.
'$init_from_saved_state_and_args'.
'$init_path_extensions' :-
get_value('$extend_file_search_path',P), !,
P \= [],
set_value('$extend_file_search_path',[]),
'$extend_file_search_path'(P).
'$init_path_extensions'.
% then we can execute the programs.
'$startup_goals' :-
module(user),
fail.
'$startup_goals' :-
recorded('$startup_goal',G,_),
catch(once(user:G),Error,user:'$Error'(Error)),
fail.
'$startup_goals' :-
get_value('$init_goal',GA),
GA \= [],
set_value('$init_goal',[]),
'$run_atom_goal'(GA),
fail.
'$startup_goals' :-
recorded('$restore_flag', goal(Module:GA), R),
erase(R),
catch(once(Module:GA),Error,user:'$Error'(Error)),
fail.
'$startup_goals' :-
get_value('$myddas_goal',GA), GA \= [],
set_value('$myddas_goal',[]),
get_value('$myddas_user',User), User \= [],
set_value('$myddas_user',[]),
get_value('$myddas_db',Db), Db \= [],
set_value('$myddas_db',[]),
get_value('$myddas_host',HostT),
( HostT \= [] ->
Host = HostT,
set_value('$myddas_host',[])
;
Host = localhost
),
get_value('$myddas_pass',PassT),
( PassT \= [] ->
Pass = PassT,
set_value('$myddas_pass',[])
;
Pass = ''
),
use_module(library(myddas)),
call(db_open(mysql,myddas,Host/Db,User,Pass)),
'$myddas_import_all',
fail.
'$startup_goals'.
%
% MYDDAS: Import all the tables from one database
%
'$myddas_import_all':-
call(db_my_show_tables(myddas,table(Table))),
call(db_import(myddas,Table,Table)),
fail.
'$myddas_import_all'.
qsave_file(F0) :- qsave_file(F0) :-
ensure_loaded( F0 ), ensure_loaded( F0 ),

View File

@ -11,84 +11,6 @@ live :- '$live'.
), ),
'$system_catch'('$enter_top_level',Module,Error,'$Error'(Error)). '$system_catch'('$enter_top_level',Module,Error,'$Error'(Error)).
'$init_globals' :-
% set_prolog_flag(break_level, 0),
% '$set_read_error_handler'(error), let the user do that
nb_setval('$chr_toplevel_show_store',false).
'$init_consult' :-
set_value('$open_expands_filename',true),
nb_setval('$assert_all',off),
nb_setval('$if_level',0),
nb_setval('$endif',off),
nb_setval('$initialization_goals',off),
nb_setval('$included_file',[]),
nb_setval('$loop_streams',[]),
\+ '$undefined'('$init_preds',prolog),
'$init_preds',
fail.
'$init_consult'.
'$init_win_graphics' :-
'$undefined'(window_title(_,_), system), !.
'$init_win_graphics' :-
load_files([library(win_menu)], [silent(true),if(not_loaded)]),
fail.
'$init_win_graphics'.
'$init_or_threads' :-
'$c_yapor_workers'(W), !,
'$start_orp_threads'(W).
'$init_or_threads'.
'$start_orp_threads'(1) :- !.
'$start_orp_threads'(W) :-
thread_create('$c_worker',_,[detached(true)]),
W1 is W-1,
'$start_orp_threads'(W1).
'$version' :-
current_prolog_flag(halt_after_consult, false),
current_prolog_flag(verbose, normal), !,
current_prolog_flag(version_git,VersionGit),
current_prolog_flag(compiled_at,AT),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
current_prolog_flag(resource_database, Saved ),
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
format(user_error, '% database loaded from ~a~n', [Saved]).
'$init_prolog' :-
% do catch as early as possible
'$version',
yap_flag(file_name_variables, _OldF, true),
'$init_consult',
%set_prolog_flag(file_name_variables, OldF),
'$init_globals',
set_prolog_flag(fileerrors, true),
set_value('$gc',on),
('$exit_undefp' -> true ; true),
prompt1(' ?- '),
set_prolog_flag(debug, false),
% simple trick to find out if this is we are booting from Prolog.
% boot from a saved state
(
current_prolog_flag(saved_program, true)
% use saved state
->
'$init_state'
;
true
),
'$db_clean_queues'(0),
% this must be executed from C-code.
% '$startup_saved_state',
set_input(user_input),
set_output(user_output),
'$init_or_threads',
'$run_at_thread_start'.
% Start file for yap % Start file for yap
/* I/O predicates */ /* I/O predicates */