error handling

This commit is contained in:
Vitor Santos Costa 2017-08-27 22:22:34 +01:00
parent ec3995dd82
commit b1067dcc34
3 changed files with 112 additions and 123 deletions

View File

@ -160,11 +160,10 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
{
Term t, ti;
int sno;
char buf0[YAP_FILENAME_MAX + 1];
const char *buf;
ti = Deref(ARG1);
buf = Yap_TextTermToText(ti, buf0, 0, LOCAL_encoding);
buf = Yap_TextTermToText(ti, NULL, 0, LOCAL_encoding);
if (!buf) {
return false;
}
@ -292,7 +291,11 @@ void Yap_MemOps(StreamDesc *st) {
}
static int sssno;
bool Yap_CloseMemoryStream(int sno) {
sssno++;
// if (sssno > 1720) Yap_do_low_level_trace=1;
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
fflush(GLOBAL_Stream[sno].file);
fclose(GLOBAL_Stream[sno].file);

View File

@ -8,7 +8,6 @@
* *
**************************************************************************
* *
read_term
* File: iopreds.c *
* Last rev: 5/2/88 *
* mods: *
@ -26,11 +25,11 @@ static char SccsId[] = "%W% %G%";
*/
#include "Yap.h"
#include "YapEval.h"
#include "YapFlags.h"
#include "YapHeap.h"
#include "YapText.h"
#include "Yatom.h"
#include "YapEval.h"
#include "yapio.h"
#include <stdlib.h>
#if HAVE_STDARG_H
@ -238,48 +237,45 @@ static Term add_priority(Term t, Term tail) {
}
}
static Term scanToList(TokEntry *tok, TokEntry *errtok)
{
static Term scanToList(TokEntry *tok, TokEntry *errtok) {
TokEntry *tok0 = tok;
CELL *Hi = HR;
Term tf = TermNil;
Term *tailp = &tf;
Term ts[1];
ts[0] = TermNil;
Term *tailp = ts;
while (tok)
{
while (tok) {
if (HR > ASP - 1024)
{
Int used = HR-Hi;
if (HR > ASP - 1024) {
Int used = HR - Hi;
/* for some reason moving this earlier confuses gcc on solaris */
HR = Hi;
tok = tok0;
if (!Yap_gcl(used, 1, ENV, CP))
{
if (!Yap_gcl(used, 1, ENV, CP)) {
return 0;
}
continue;
}
if (tok == errtok && tok->Tok != Error_tok)
{
if (tok == errtok && tok->Tok != Error_tok) {
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
tailp = RepPair(*tailp) + 1;
}
Term rep = Yap_tokRep(tok);
*tailp = MkPairTerm(rep, TermNil);
tailp = RepPair(*tailp) + 1;
if (tok->TokNext)
{
if (tok->TokNext == NULL) {
break;
}
tok = tok->TokNext;
}
}
return tf;
Yap_DebugPlWriteln(ts[0]);
return ts[0];
}
/**
/**
@pred scan_to_list( +Stream, -Tokens )
Generate a list of tokens from a scan of the (input) stream, Tokens are of the form:
Generate a list of tokens from a scan of the (input) stream, Tokens are of the
form:
+ `atom`(Atom)
+ `<QQ>`(Text)
@ -290,28 +286,27 @@ Generate a list of tokens from a scan of the (input) stream, Tokens are of the f
+ symbols, including `(`, `)`, `,`, `;`
*/
static Int scan_to_list(USE_ARGS1)
{
static Int scan_to_list(USE_ARGS1) {
int inp_stream;
Term tpos, tout;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream == -1)
{
if (inp_stream == -1) {
return false;
}
TokEntry *tok = Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos);
TokEntry *tok = LOCAL_tokptr = LOCAL_toktide =
Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
tout = scanToList(tok, NULL);
if (tout == 0)
return false;
Yap_clean_tokenizer(tok, LOCAL_VarTable, LOCAL_AnonVarTable);
return Yap_unify(ARG1, tout);
}
return Yap_unify(ARG2, tout);
}
/**
/**
* Syntax Error Handler
*
* @par tokptr: the sequence of tokens
@ -320,8 +315,7 @@ Generate a list of tokens from a scan of the (input) stream, Tokens are of the f
* Implicit arguments:
* +
*/
static Term syntax_error(TokEntry * errtok, int sno, Term cmod)
{
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
CACHE_REGS
Term startline, errline, endline;
Term tf[3];
@ -333,8 +327,7 @@ Generate a list of tokens from a scan of the (input) stream, Tokens are of the f
startline = MkIntegerTerm(cline);
endline = MkIntegerTerm(cline);
if (errtok != LOCAL_toktide)
{
if (errtok != LOCAL_toktide) {
errtok = LOCAL_toktide;
}
LOCAL_Error_TYPE = YAP_NO_ERROR;
@ -343,35 +336,28 @@ Generate a list of tokens from a scan of the (input) stream, Tokens are of the f
tm = MkStringTerm(LOCAL_ErrorMessage);
else
tm = MkStringTerm("syntax error");
while (tok)
{
while (tok) {
if (HR > ASP - 1024)
{
if (HR > ASP - 1024) {
errline = MkIntegerTerm(0);
endline = MkIntegerTerm(0);
/* for some reason moving this earlier confuses gcc on solaris */
HR = Hi;
break;
}
if (tok->TokPos != cline)
{
if (tok->TokPos != cline) {
*tailp = MkPairTerm(TermNewLine, TermNil);
tailp = RepPair(*tailp) + 1;
cline = tok->TokPos;
}
if (tok == errtok && tok->Tok != Error_tok)
{
if (tok == errtok && tok->Tok != Error_tok) {
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
tailp = RepPair(*tailp) + 1;
}
Term rep = Yap_tokRep(tok);
if (tok->TokNext)
{
if (tok->TokNext) {
tok = tok->TokNext;
}
else
{
} else {
endline = MkIntegerTerm(tok->TokPos);
tok = NULL;
break;

View File

@ -109,7 +109,7 @@ static Int rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS) {
max_inp -= (buf_sz - 1);
if (max_inp <= 0) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
Yap_Error(RESOURCE_ERROR_STACK, ARG1, "read_line_to_codes/%d", arity);
PlIOError(RESOURCE_ERROR_STACK, ARG1, "read_line_to_codes/%d", arity);
return FALSE;
}
}