diff --git a/C/c_interface.c b/C/c_interface.c index dabd21bd8..83ba0829d 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -2852,7 +2852,7 @@ YAP_Read(IOSTREAM *inp) BACKUP_MACHINE_REGS(); - tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, FALSE, &tpos); + tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp, FALSE, &tpos, &rd); if (LOCAL_ErrorMessage) { Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); diff --git a/C/iopreds.c b/C/iopreds.c index a280d4b47..9a3652bf0 100755 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -504,7 +504,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd) old_H = H; LOCAL_Comments = TermNil; LOCAL_CommentsNextChar = LOCAL_CommentsTail = NULL; - tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp_stream, store_comments, &tpos); + tokstart = LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(inp_stream, store_comments, &tpos, rd); if (LOCAL_Error_TYPE != YAP_NO_ERROR && seekable) { H = old_H; Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments); diff --git a/C/scanner.c b/C/scanner.c index 288bc1952..c917ae78d 100644 --- a/C/scanner.c +++ b/C/scanner.c @@ -820,7 +820,7 @@ ch_to_wide(char *base, char *charp) { charp = _PL__utf8_put_char(charp, ch); } } TokEntry * -Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp) +Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp, void *rd0) { GET_LD TokEntry *t, *l, *p; @@ -829,6 +829,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp) int ch; wchar_t *wcharp; struct qq_struct_t *cur_qq = NULL; + struct read_data_t *rd = rd0; LOCAL_ErrorMessage = NULL; LOCAL_Error_Size = 0; @@ -843,7 +844,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp) ch = getchr(inp_stream); } *tposp = Yap_StreamPosition(inp_stream); - Yap_setCurrentSourceLocation(&inp_stream); + Yap_setCurrentSourceLocation( rd ); LOCAL_StartLine = inp_stream->posbuf.lineno; do { wchar_t och; @@ -907,7 +908,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp) } CHECK_SPACE(); *tposp = Yap_StreamPosition(inp_stream); - Yap_setCurrentSourceLocation(&inp_stream); + Yap_setCurrentSourceLocation( rd ); } goto restart; } else { @@ -1230,7 +1231,7 @@ Yap_tokenizer(IOSTREAM *inp_stream, int store_comments, Term *tposp) } CHECK_SPACE(); *tposp = Yap_StreamPosition(inp_stream); - Yap_setCurrentSourceLocation(&inp_stream); + Yap_setCurrentSourceLocation( rd ); } } goto restart; diff --git a/H/pl-shared.h b/H/pl-shared.h index d71b79d91..8f76c6c79 100755 --- a/H/pl-shared.h +++ b/H/pl-shared.h @@ -264,7 +264,7 @@ getUnknownModule(module_t m); COMMON(int) debugmode(debug_type new, debug_type *old); COMMON(int) tracemode(debug_type new, debug_type *old); -COMMON(void) Yap_setCurrentSourceLocation(IOSTREAM **s); +COMMON(void) Yap_setCurrentSourceLocation( void *rd ); extern int raiseSignal(PL_local_data_t *ld, int sig); diff --git a/H/pl-yap.h b/H/pl-yap.h index 6d3cfdeb1..b7fe1aa44 100644 --- a/H/pl-yap.h +++ b/H/pl-yap.h @@ -34,7 +34,7 @@ extern Int Yap_GetCurrentPredArity(void); extern term_t Yap_fetch_module_for_format(term_t args, Term *modp); extern IOENC Yap_DefaultEncoding(void); extern void Yap_SetDefaultEncoding(IOENC); -extern void Yap_setCurrentSourceLocation(IOSTREAM **s); +extern void Yap_setCurrentSourceLocation( void *rd ); extern void *Yap_GetStreamHandle(Atom at); extern atom_t codeToAtom(int chrcode); diff --git a/H/yapio.h b/H/yapio.h index e8090f040..68d3b0560 100644 --- a/H/yapio.h +++ b/H/yapio.h @@ -240,7 +240,7 @@ Term Yap_Variables(VarEntry *,Term); Term Yap_Singletons(VarEntry *,Term); /* routines in scanner.c */ -TokEntry *Yap_tokenizer(struct io_stream *, int, Term *); +TokEntry *Yap_tokenizer(struct io_stream *, int, Term *, void *rd); void Yap_clean_tokenizer(TokEntry *, VarEntry *, VarEntry *,Term); Term Yap_scan_num(struct io_stream *); char *Yap_AllocScannerMemory(unsigned int); diff --git a/os/pl-read.c b/os/pl-read.c index b5249d7ad..ddc7cf691 100644 --- a/os/pl-read.c +++ b/os/pl-read.c @@ -20,7 +20,7 @@ void init_read_data(ReadData _PL_rd, IOSTREAM *in ARG_LD) { CACHE_REGS memset(_PL_rd, 0, sizeof(*_PL_rd)); /* optimise! */ - + _PL_rd->magic = RD_MAGIC; _PL_rd->varnames = 0; _PL_rd->module = Yap_GetModuleEntry(CurrentModule); @@ -356,14 +356,10 @@ addToBuffer(int c, ReadData _PL_rd) #if __YAP_PROLOG__ void -Yap_setCurrentSourceLocation(IOSTREAM ** rd) +Yap_setCurrentSourceLocation( void *rd ) { GET_LD - if (*rd) { - read_data rdt; - rdt._rb.stream = *rd; - setCurrentSourceLocation(&rdt PASS_LD); - } + setCurrentSourceLocation(rd PASS_LD); } #endif diff --git a/pl/checker.yap b/pl/checker.yap index 54a0ea46c..cffe2df15 100644 --- a/pl/checker.yap +++ b/pl/checker.yap @@ -185,7 +185,7 @@ no_style_check([H|T]) :- no_style_check(H), no_style_check(T). '$pred_arity'((H:-_),Name,Arity) :- !, functor(H,Name,Arity). '$pred_arity'((H-->_),Name,Arity) :- !, - functor(HL,Name,1). + functor(HL,Name,1), Arity is A1+2. '$pred_arity'(H,Name,Arity) :- functor(H,Name,Arity). diff --git a/pl/errors.yap b/pl/errors.yap index 89cdd2a44..a9d4d9b0b 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -275,15 +275,16 @@ print_message(_, Term) :- '$print_system_message'(_, banner, _) :- current_prolog_flag(verbose, silent), !. '$print_system_message'(Term, Level, Lines) :- - '$messages':prefix(Level, LinePrefix, Stream, Prefix), - '$messages':file_location(Prefix, LinesF, Lines), !, + ( Level == error -> Term \= error(syntax_error(_), _) ; Level == warning ), + '$messages':prefix(Level, LinePrefix, Stream, LinesF, Lines2), + '$messages':file_location(Lines2, Lines), !, flush_output(user_output), flush_output(user_error), - print_message_lines(Stream, LinePrefix, LinesF). + print_message_lines(Stream, LinePrefix, [nl|LinesF]). '$print_system_message'(Error, Level, Lines) :- flush_output(user_output), flush_output(user_error), '$messages':prefix(Level, LinePrefix, Stream, LinesF, Lines), !, print_message_lines(Stream, LinePrefix, LinesF). - +s diff --git a/pl/init.yap b/pl/init.yap index 3db79966b..1afbc345c 100755 --- a/pl/init.yap +++ b/pl/init.yap @@ -234,10 +234,6 @@ user:prolog_file_type(A, executable) :- :- dynamic file_search_path/2. -:- multifile generate_message_hook/3. - -:- dynamic generate_message_hook/3. - :- multifile swi:swi_predicate_table/4. :- multifile user:message_hook/3. diff --git a/pl/messages.yap b/pl/messages.yap index fe65fc038..9b117c2ff 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -24,18 +24,17 @@ :- multifile prolog:message/3. -file_location(Prefix) --> - { - prolog_load_context(file, FileName) - }, - { '$start_line'(LN) }, - file_position(FileName,LN,Prefix), +:- multifile user:generate_message_hook/3. + +file_location --> + { source_location(FileName, LN) }, + file_position(FileName,LN), [ nl ]. -file_position(user_input,LN,MsgCodes) --> - [ '~a (user_input:~d).' - [MsgCodes,LN] ]. -file_position(FileName,LN,MsgCodes) --> - [ '~a (~a:~d).' - [MsgCodes,FileName,LN] ]. +file_position(user_input,LN) --> + [ 'at line ~d in user_input,' - [LN] ]. +file_position(FileName,LN) --> + [ 'at line ~d in ~a,' - [LN,FileName] ]. translate_message(Term) --> @@ -499,7 +498,7 @@ syntax_error_token(A) --> !, % Quintus/SICStus/SWI compatibility predicate to print message lines % using a prefix. -prolog:print_message_lines(_, _, []) :- !. +prolog:print_message_lines(S, _, []) :- !. prolog:print_message_lines(S, P, [at_same_line|Lines]) :- !, print_message_line(S, Lines, Rest), prolog:print_message_lines(S, P, Rest). @@ -517,7 +516,7 @@ prolog:print_message_lines(S, P-Opts, Lines) :- !, atom_concat('~N', P, Prefix), format(S, Prefix, Opts), print_message_line(S, Lines, Rest), - prolog:print_message_lines(S, P-Opts, Rest). + prolog:print_message_lines(S, P-Opts, Rest)x. prolog:print_message_lines(S, P, Lines) :- atom(P), !, atom_concat('~N', P, Prefix),