From c1dc6b7fb2c140d59010090447593dd7c04d4a18 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 31 Jan 2019 11:52:03 +0000 Subject: [PATCH] boot --- C/c_interface.c | 8 ++++++ C/errors.c | 3 +- C/exec.c | 9 ++++++ C/yap-args.c | 2 ++ H/YapLFlagInfo.h | 6 ++-- pl/absf.yap | 11 ++++---- pl/boot.yap | 72 +++++++++++++++++++++++++++++------------------- pl/top.yap | 11 ++++---- 8 files changed, 78 insertions(+), 44 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index 7cded6b1f..a6e9d223a 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -2202,7 +2202,15 @@ X_API Term YAP_ReadFromStream(int sno) { Term o; BACKUP_MACHINE_REGS(); + + sigjmp_buf signew; + if (sigsetjmp(signew, 0)) { + Yap_syntax_error(LOCAL_toktide, sno, "ReadFromStream"); + RECOVER_MACHINE_REGS(); + return 0; + } else { o = Yap_read_term(sno, TermNil, false); + } RECOVER_MACHINE_REGS(); return o; } diff --git a/C/errors.c b/C/errors.c index dc5dc7c61..4e4648f1e 100755 --- a/C/errors.c +++ b/C/errors.c @@ -363,6 +363,7 @@ bool Yap_PrintWarning(Term twarning) { LOCAL_within_print_message = false; LOCAL_PrologMode &= ~InErrorMode; return rc; + } bool Yap_HandleError__(const char *file, const char *function, int lineno, @@ -415,7 +416,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno, return false; } default: - + if (LOCAL_PrologMode == UserMode) Yap_ThrowError__(file, function, lineno, err, LOCAL_RawTerm, serr); else diff --git a/C/exec.c b/C/exec.c index fa757cc39..951c24d7e 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1712,6 +1712,11 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { // should we catch the exception or pass it through? // We'll pass it through if (pass_ex && Yap_HasException()) { + if ((LOCAL_PrologMode & BootMode) || !CurrentModule ) { + Yap_ResetException(LOCAL_ActiveError); + return false; + } + Yap_RaiseException(); return false; } @@ -1734,6 +1739,10 @@ bool Yap_execute_pred(PredEntry *ppe, CELL *pt, bool pass_ex USES_REGS) { // should we catch the exception or pass it through? // We'll pass it through if (pass_ex) { + if ((LOCAL_PrologMode & BootMode) || !CurrentModule ) { + Yap_ResetException(LOCAL_ActiveError); + return false; + } Yap_RaiseException(); } return false; diff --git a/C/yap-args.c b/C/yap-args.c index ccd7083fe..0d2ff1324 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -166,6 +166,7 @@ static bool load_file(const char *b_file USES_REGS) { /* consult in C */ int lvl = push_text_stack(); + char *full; /* the consult mode does not matter here, really */ if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) { @@ -191,6 +192,7 @@ static bool load_file(const char *b_file USES_REGS) { YAP_Reset(YAP_FULL_RESET, false); Yap_StartSlots(); Term vs = MkVarTerm(), pos = MkVarTerm(); + t = YAP_ReadClauseFromStream(c_stream, vs, pos); // Yap_GetNèwSlot(t); if (t == TermEof || t == TermNil) { diff --git a/H/YapLFlagInfo.h b/H/YapLFlagInfo.h index 643fbba46..5949bc5c9 100644 --- a/H/YapLFlagInfo.h +++ b/H/YapLFlagInfo.h @@ -117,9 +117,9 @@ Just fail /**< If `true` allow printing of informational messages when - searching for file names. If `false` disable printing these messages. It - is `false` by default except if YAP is booted with the `-L` - flag. + searching for file names. If `false` disable printing these + messages. It is `false` by default except if YAP is booted with + the `-L` flag. */ YAP_FLAG(VERBOSE_FILE_SEARCH_FLAG, "verbose_file_search", true, booleanFlag, "false", NULL), diff --git a/pl/absf.yap b/pl/absf.yap index 43bbe3aa9..c65880f87 100755 --- a/pl/absf.yap +++ b/pl/absf.yap @@ -30,14 +30,13 @@ add_to_path/1, add_to_path/2, path/1, - remove_from_path/1]). + remove_from_path/1], []). absolute_file_name__(File,LOpts,TrueFileName) :- % must_be_of_type( atom, File ), % look for solutions gated_call( - '$enter_absf'( File, LOpts, Opts, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ), '$find_in_path'(File, Opts,TrueFileName, HasSol, TakeFirst), Port, @@ -91,12 +90,12 @@ absolute_file_name__(File,LOpts,TrueFileName) :- '$absf_port'(fail, File, TrueFileName, HasSol, OldF, PreviousFileErrors, PreviousVerbose, Expand, Verbose, TakeFirst, FileErrors ). - -core_file_name(Name, Opts) --> +:- start_low_level_trace. +prolog:core_file_name(Name, Opts) --> '$file_name'(Name, Opts, E), '$suffix'(E, Opts), '$glob'(Opts). - +:- stop_low_level_trace. % % handle library(lists) or foreign(jpl) % @@ -416,7 +415,7 @@ remove_from_path(New) :- '$check_path'(New,Path), get_abs_file_parameter( access, Opts, Access ), get_abs_file_parameter( expand, Opts, Expand ), absf_trace('start with ~w', [Name]), - core_file_name(Name, Opts, CorePath, []), + prolog:core_file_name(Name, Opts, CorePath, []), absf_trace(' after name/library unfolding: ~w', [Name]), '$variable_expansion'(CorePath, Opts,ExpandedPath), absf_trace(' after environment variable expansion: ~s', [ExpandedPath]), diff --git a/pl/boot.yap b/pl/boot.yap index 420f0b3a5..b21c06a87 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -37,23 +37,17 @@ */ system_module(Mod, SysExps) :- system_module(Mod, SysExps, []). - - -use_system_module(_Module, _SysExps). system_module(_Mod, SysExps, _Decls) :- - % '$new_system_predicates'(SysExps), + '$new_system_predicates'(SysExps), + !, fail. - system_module(_Mod, _SysExps, _Decls) :- - ( - stream_property(loop_stream,file_name(File)) - -> - recordz(system_file, File, _ ) - ; - recordz(system_file, loop_stream, _ ) - ). - -private(_). +system_module(_Mod, _SysExps, _Decls) :- + stream_property(loop_stream,[file_name(File)]), + !, + recordz(system_file, File, _ ). +system_module(_Mod, _SysExps, _Decls) :- + recordz(system_file, loop_stream, _ ). '$new_system_predicates'([]). '$new_system_predicates'([N/Ar|_Ps]) :- @@ -61,6 +55,10 @@ private(_). '$new_system_predicates'([_P|Ps]) :- '$new_system_predicates'(Ps). +use_system_module(_Module, _SysExps). + +private(_). + % % boootstrap predicates. % @@ -82,22 +80,38 @@ private(_). % be careful here not to generate an undefined exception.. -print_message(L,E) :- - (L = informational - -> - '$query_exception'(prologPredFile, Desc, File), - '$query_exception'(prologPredLine, Desc, FilePos), - format(user_error,'~a:~d: error:', [File,FilePos]) - ; - - %throw(error(error, print_message(['while calling goal = ~w'-E,nl]))). +print_message(informational,_) :- + yap_flag(verbose, silent), + !. +print_message(informational,E) :- + format('informational message ~q.~n',[E]), + !. +%% +% boot:print_message( Type, Error ) +% +print_message(Type,error(_,exception(Desc))) :- '$get_exception'(Desc), + print_boot_message(Type,Error,Desc), + '$print_exception'(Desc), + !. +print_message(Type,Error) :- + format( user_error, '~w while bootstraping: event is ~q~n',[Type,Error]). + + + +print_boot_message(Type,Error,Desc) :- + '$query_exception'(parserFile, Desc, File), + '$query_exception'(parserLine, Desc, FilePos), + !, + format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]). +print_boot_message(Type,Error,Desc) :- '$query_exception'(prologPredFile, Desc, File), '$query_exception'(prologPredLine, Desc, FilePos), - format(user_error,'~a:~d: error:', [File,FilePos]), - '$print_exception'(Desc), - format( user_error, '~w from bootstrap: got ~w~n',[L,E]) - ). + format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]). +print_boot_message(Type,Error,Desc) :- + '$query_exception'(errorFile, Desc, File), + '$query_exception'(errorLine, Desc, FilePos), + format(user_error,'~a:~d: ~a: ~q~n', [File,FilePos,Type,Error]). '$undefp0'([M|G], _Action) :- functor(G,N,A), @@ -141,7 +155,7 @@ print_message(L,E) :- goal_expansion/3, otherwise/0, term_expansion/2, - version/2, + version/2], [ '$do_log_upd_clause'/6, '$do_log_upd_clause0'/6, @@ -249,7 +263,7 @@ initialize_prolog :- :- c_compile( 'preds.yap' ). :- c_compile( 'modules.yap' ). :- c_compile( 'grammar.yap' ). -%:- c_compile( 'protect.yap' ). +:- c_compile( 'protect.yap' ). :- ['absf.yap']. diff --git a/pl/top.yap b/pl/top.yap index bd76975b8..3d0b1772d 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -177,11 +177,11 @@ live :- catch( '$expand_term0'(T,Con,O), _,( '$disable_debugging', fail) ), !. - '$expand_term0'(T,consult,O) :- - expand_term( T, O). - '$expand_term0'(T,reconsult,O) :- - expand_term( T, O). - '$expand_term0'(T,top,O) :- +'$expand_term0'(T,consult,O) :- + expand_term( T, O). +'$expand_term0'(T,reconsult,O) :- + expand_term( T, O). +'$expand_term0'(T,top,O) :- expand_term( T, T1), !, '$expand_term1'(T1,O). @@ -243,6 +243,7 @@ live :- functor(NH,N,Ar), print_message(warning,redefine_imported(Mod,NM,Mod:N/Ar)), erase(RI), + clause(Mod:H,_,R), erase(R), fail. '$init_pred'(H, Mod, Where ) :- '$init_as_dynamic'(Where),