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);
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 */

View File

@ -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;
}

View File

@ -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");

View File

@ -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);

View File

@ -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_;

View File

@ -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"

View File

@ -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.