diff --git a/C/c_interface.c b/C/c_interface.c index 92627bda2..5fefae752 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -3186,7 +3186,7 @@ YAP_Init(YAP_init_args *yap_init) Yap_AttsSize = 2048*sizeof(CELL); if (restore_result == DO_ONLY_CODE) { /* first, initialise the saved state */ - Term t_goal = MkAtomTerm(AtomStartupSavedState); + Term t_goal = MkAtomTerm(AtomInitProlog); YAP_RunGoalOnce(t_goal); Yap_InitYaamRegs(); /* reset stacks */ diff --git a/C/qlyr.c b/C/qlyr.c index 5ce26501a..6e12eeb2b 100644 --- a/C/qlyr.c +++ b/C/qlyr.c @@ -999,9 +999,13 @@ p_read_module_preds( USES_REGS1 ) } static void -ReInitCatch(void) +ReInitProlog(void) { - Term t = Yap_MkNewApplTerm(PredHandleThrow->FunctorOfPred, PredHandleThrow->ArityOfPE); + Term t = MkAtomTerm(AtomInitProlog); +#if defined(YAPOR) || defined(TABLING) + Yap_init_root_frames(); +#endif /* YAPOR || TABLING */ + Yap_InitYaamRegs(); YAP_RunGoalOnce(t); } @@ -1030,7 +1034,7 @@ p_read_program( USES_REGS1 ) Sclose( stream ); /* back to the top level we go */ Yap_CloseSlots(PASS_REGS1); - ReInitCatch(); + ReInitProlog(); Yap_RestartYap( 3 ); return TRUE; } @@ -1044,7 +1048,6 @@ Yap_Restore(char *s, char *lib_dir) return -1; read_module(stream); Sclose( stream ); - ReInitCatch(); return DO_ONLY_CODE; } diff --git a/H/iatoms.h b/H/iatoms.h index de3159edd..2b3f20eb1 100644 --- a/H/iatoms.h +++ b/H/iatoms.h @@ -135,6 +135,7 @@ AtomId = Yap_LookupAtom("id"); AtomInf = Yap_LookupAtom("inf"); AtomInitGoal = Yap_FullLookupAtom("$init_goal"); + AtomInitProlog = Yap_FullLookupAtom("$init_prolog"); AtomInStackExpansion = Yap_LookupAtom("in stack expansion"); AtomInput = Yap_LookupAtom("input"); AtomInstantiationError = Yap_LookupAtom("instantiation_error"); diff --git a/H/ratoms.h b/H/ratoms.h index 913ef73a3..c4bf08b26 100644 --- a/H/ratoms.h +++ b/H/ratoms.h @@ -135,6 +135,7 @@ AtomId = AtomAdjust(AtomId); AtomInf = AtomAdjust(AtomInf); AtomInitGoal = AtomAdjust(AtomInitGoal); + AtomInitProlog = AtomAdjust(AtomInitProlog); AtomInStackExpansion = AtomAdjust(AtomInStackExpansion); AtomInput = AtomAdjust(AtomInput); AtomInstantiationError = AtomAdjust(AtomInstantiationError); diff --git a/H/tatoms.h b/H/tatoms.h index 16318620e..224c73231 100644 --- a/H/tatoms.h +++ b/H/tatoms.h @@ -268,6 +268,8 @@ #define AtomInf Yap_heap_regs->AtomInf_ Atom AtomInitGoal_; #define AtomInitGoal Yap_heap_regs->AtomInitGoal_ + Atom AtomInitProlog_; +#define AtomInitProlog Yap_heap_regs->AtomInitProlog_ Atom AtomInStackExpansion_; #define AtomInStackExpansion Yap_heap_regs->AtomInStackExpansion_ Atom AtomInput_; diff --git a/misc/ATOMS b/misc/ATOMS index 339022b8a..9fefab1a1 100644 --- a/misc/ATOMS +++ b/misc/ATOMS @@ -140,6 +140,7 @@ A IOMode N "io_mode" A Id N "id" A Inf N "inf" A InitGoal F "$init_goal" +A InitProlog F "$init_prolog" A InStackExpansion N "in stack expansion" A Input N "input" A InstantiationError N "instantiation_error" diff --git a/pl/boot.yap b/pl/boot.yap index 6cab9a0c5..3f4a3e002 100755 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -25,33 +25,40 @@ true :- true. '$init_system', '$do_live'. +'$init_prolog' :- + '$init_system'. + '$do_live' :- - repeat, - '$current_module'(Module), - ( Module==user -> - '$compile_mode'(_,0) - ; - format(user_error,'[~w]~n', [Module]) - ), - '$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)). + repeat, + '$current_module'(Module), + ( Module==user -> + '$compile_mode'(_,0) + ; + format(user_error,'[~w]~n', [Module]) + ), + '$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)). + '$init_system' :- - % do catch as early as possible - ( - '$access_yap_flags'(15, 0), - '$access_yap_flags'(22, 0), - \+ '$uncaught_throw' - -> - '$version' - ; - true - ), - ( - '$access_yap_flags'(22, 0) -> - set_value('$verbose',on) - ; - set_value('$verbose',off) - ), + '$nb_getval'('$yap_inited', on, fail), !. +'$init_system' :- + nb_setval('$yap_inited', on), + % do catch as early as possible + ( + '$access_yap_flags'(15, 0), + '$access_yap_flags'(22, 0), + \+ '$uncaught_throw' + -> + '$version' + ; + true + ), + ( + '$access_yap_flags'(22, 0) -> + set_value('$verbose',on) + ; + set_value('$verbose',off) + ), % '$init_preds', % needs to be done before library_directory % ( % retractall(user:library_directory(_)), @@ -61,13 +68,13 @@ true :- true. % ; % true % ), - '$enter_system_mode', - '$init_globals', - '$swi_set_prolog_flag'(fileerrors, true), - set_value('$gc',on), - ('$exit_undefp' -> true ; true), - prompt1(' ?- '), - '$debug_on'(false), + '$enter_system_mode', + '$init_globals', + '$swi_set_prolog_flag'(fileerrors, true), + set_value('$gc',on), + ('$exit_undefp' -> true ; true), + prompt1(' ?- '), + '$debug_on'(false), % simple trick to find out if this is we are booting from Prolog. % boot from a saved state ( @@ -160,23 +167,28 @@ true :- true. prompt1('?- '), prompt(_,'|: '), '$system_catch'('$raw_read'(user_input, Line), prolog, E, - (print_message(error, E), - ( E = error(syntax_error(_), _) - -> fail - ; throw(E) - ))), - ( current_predicate(_, user:rl_add_history(_)) - -> format(atom(CompleteLine), '~W~W', + (print_message(error, E), + ( E = error(syntax_error(_), _) + -> fail + ; throw(E) + ))), + ( + current_predicate(_, user:rl_add_history(_)) + -> + format(atom(CompleteLine), '~W~W', [ Line, [partial(true)], '.', [partial(true)] ]), call(user:rl_add_history(CompleteLine)) - ; true + ; + true ), - '$system_catch'(atom_to_term(Line, Goal, Bindings), prolog, E, - ( print_message(error, E), - fail - )), !. + '$system_catch'( + atom_to_term(Line, Goal, Bindings), prolog, E, + ( print_message(error, E), + fail + ) + ), !. % reset alarms when entering top-level.