make full init even before entering Prolog top-level

This commit is contained in:
Vítor Santos Costa 2012-09-21 11:49:59 +01:00
parent ceb5785120
commit d5bf100b71
7 changed files with 68 additions and 48 deletions

View File

@ -3186,7 +3186,7 @@ YAP_Init(YAP_init_args *yap_init)
Yap_AttsSize = 2048*sizeof(CELL); Yap_AttsSize = 2048*sizeof(CELL);
if (restore_result == DO_ONLY_CODE) { if (restore_result == DO_ONLY_CODE) {
/* first, initialise the saved state */ /* first, initialise the saved state */
Term t_goal = MkAtomTerm(AtomStartupSavedState); Term t_goal = MkAtomTerm(AtomInitProlog);
YAP_RunGoalOnce(t_goal); YAP_RunGoalOnce(t_goal);
Yap_InitYaamRegs(); Yap_InitYaamRegs();
/* reset stacks */ /* reset stacks */

View File

@ -999,9 +999,13 @@ p_read_module_preds( USES_REGS1 )
} }
static void 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); YAP_RunGoalOnce(t);
} }
@ -1030,7 +1034,7 @@ p_read_program( USES_REGS1 )
Sclose( stream ); Sclose( stream );
/* back to the top level we go */ /* back to the top level we go */
Yap_CloseSlots(PASS_REGS1); Yap_CloseSlots(PASS_REGS1);
ReInitCatch(); ReInitProlog();
Yap_RestartYap( 3 ); Yap_RestartYap( 3 );
return TRUE; return TRUE;
} }
@ -1044,7 +1048,6 @@ Yap_Restore(char *s, char *lib_dir)
return -1; return -1;
read_module(stream); read_module(stream);
Sclose( stream ); Sclose( stream );
ReInitCatch();
return DO_ONLY_CODE; return DO_ONLY_CODE;
} }

View File

@ -135,6 +135,7 @@
AtomId = Yap_LookupAtom("id"); AtomId = Yap_LookupAtom("id");
AtomInf = Yap_LookupAtom("inf"); AtomInf = Yap_LookupAtom("inf");
AtomInitGoal = Yap_FullLookupAtom("$init_goal"); AtomInitGoal = Yap_FullLookupAtom("$init_goal");
AtomInitProlog = Yap_FullLookupAtom("$init_prolog");
AtomInStackExpansion = Yap_LookupAtom("in stack expansion"); AtomInStackExpansion = Yap_LookupAtom("in stack expansion");
AtomInput = Yap_LookupAtom("input"); AtomInput = Yap_LookupAtom("input");
AtomInstantiationError = Yap_LookupAtom("instantiation_error"); AtomInstantiationError = Yap_LookupAtom("instantiation_error");

View File

@ -135,6 +135,7 @@
AtomId = AtomAdjust(AtomId); AtomId = AtomAdjust(AtomId);
AtomInf = AtomAdjust(AtomInf); AtomInf = AtomAdjust(AtomInf);
AtomInitGoal = AtomAdjust(AtomInitGoal); AtomInitGoal = AtomAdjust(AtomInitGoal);
AtomInitProlog = AtomAdjust(AtomInitProlog);
AtomInStackExpansion = AtomAdjust(AtomInStackExpansion); AtomInStackExpansion = AtomAdjust(AtomInStackExpansion);
AtomInput = AtomAdjust(AtomInput); AtomInput = AtomAdjust(AtomInput);
AtomInstantiationError = AtomAdjust(AtomInstantiationError); AtomInstantiationError = AtomAdjust(AtomInstantiationError);

View File

@ -268,6 +268,8 @@
#define AtomInf Yap_heap_regs->AtomInf_ #define AtomInf Yap_heap_regs->AtomInf_
Atom AtomInitGoal_; Atom AtomInitGoal_;
#define AtomInitGoal Yap_heap_regs->AtomInitGoal_ #define AtomInitGoal Yap_heap_regs->AtomInitGoal_
Atom AtomInitProlog_;
#define AtomInitProlog Yap_heap_regs->AtomInitProlog_
Atom AtomInStackExpansion_; Atom AtomInStackExpansion_;
#define AtomInStackExpansion Yap_heap_regs->AtomInStackExpansion_ #define AtomInStackExpansion Yap_heap_regs->AtomInStackExpansion_
Atom AtomInput_; Atom AtomInput_;

View File

@ -140,6 +140,7 @@ A IOMode N "io_mode"
A Id N "id" A Id N "id"
A Inf N "inf" A Inf N "inf"
A InitGoal F "$init_goal" A InitGoal F "$init_goal"
A InitProlog F "$init_prolog"
A InStackExpansion N "in stack expansion" A InStackExpansion N "in stack expansion"
A Input N "input" A Input N "input"
A InstantiationError N "instantiation_error" A InstantiationError N "instantiation_error"

View File

@ -25,33 +25,40 @@ true :- true.
'$init_system', '$init_system',
'$do_live'. '$do_live'.
'$init_prolog' :-
'$init_system'.
'$do_live' :- '$do_live' :-
repeat, repeat,
'$current_module'(Module), '$current_module'(Module),
( Module==user -> ( Module==user ->
'$compile_mode'(_,0) '$compile_mode'(_,0)
; ;
format(user_error,'[~w]~n', [Module]) format(user_error,'[~w]~n', [Module])
), ),
'$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)). '$system_catch'('$enter_top_level',Module,Error,user:'$Error'(Error)).
'$init_system' :- '$init_system' :-
% do catch as early as possible '$nb_getval'('$yap_inited', on, fail), !.
( '$init_system' :-
'$access_yap_flags'(15, 0), nb_setval('$yap_inited', on),
'$access_yap_flags'(22, 0), % do catch as early as possible
\+ '$uncaught_throw' (
-> '$access_yap_flags'(15, 0),
'$version' '$access_yap_flags'(22, 0),
; \+ '$uncaught_throw'
true ->
), '$version'
( ;
'$access_yap_flags'(22, 0) -> true
set_value('$verbose',on) ),
; (
set_value('$verbose',off) '$access_yap_flags'(22, 0) ->
), set_value('$verbose',on)
;
set_value('$verbose',off)
),
% '$init_preds', % needs to be done before library_directory % '$init_preds', % needs to be done before library_directory
% ( % (
% retractall(user:library_directory(_)), % retractall(user:library_directory(_)),
@ -61,13 +68,13 @@ true :- true.
% ; % ;
% true % true
% ), % ),
'$enter_system_mode', '$enter_system_mode',
'$init_globals', '$init_globals',
'$swi_set_prolog_flag'(fileerrors, true), '$swi_set_prolog_flag'(fileerrors, true),
set_value('$gc',on), set_value('$gc',on),
('$exit_undefp' -> true ; true), ('$exit_undefp' -> true ; true),
prompt1(' ?- '), prompt1(' ?- '),
'$debug_on'(false), '$debug_on'(false),
% simple trick to find out if this is we are booting from Prolog. % simple trick to find out if this is we are booting from Prolog.
% boot from a saved state % boot from a saved state
( (
@ -160,23 +167,28 @@ true :- true.
prompt1('?- '), prompt1('?- '),
prompt(_,'|: '), prompt(_,'|: '),
'$system_catch'('$raw_read'(user_input, Line), prolog, E, '$system_catch'('$raw_read'(user_input, Line), prolog, E,
(print_message(error, E), (print_message(error, E),
( E = error(syntax_error(_), _) ( E = error(syntax_error(_), _)
-> fail -> fail
; throw(E) ; throw(E)
))), ))),
( current_predicate(_, user:rl_add_history(_)) (
-> format(atom(CompleteLine), '~W~W', current_predicate(_, user:rl_add_history(_))
->
format(atom(CompleteLine), '~W~W',
[ Line, [partial(true)], [ Line, [partial(true)],
'.', [partial(true)] '.', [partial(true)]
]), ]),
call(user:rl_add_history(CompleteLine)) call(user:rl_add_history(CompleteLine))
; true ;
true
), ),
'$system_catch'(atom_to_term(Line, Goal, Bindings), prolog, E, '$system_catch'(
( print_message(error, E), atom_to_term(Line, Goal, Bindings), prolog, E,
fail ( print_message(error, E),
)), !. fail
)
), !.
% reset alarms when entering top-level. % reset alarms when entering top-level.