error handling
This commit is contained in:
parent
ec3995dd82
commit
b1067dcc34
@ -160,11 +160,10 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
|
|||||||
{
|
{
|
||||||
Term t, ti;
|
Term t, ti;
|
||||||
int sno;
|
int sno;
|
||||||
char buf0[YAP_FILENAME_MAX + 1];
|
|
||||||
const char *buf;
|
const char *buf;
|
||||||
|
|
||||||
ti = Deref(ARG1);
|
ti = Deref(ARG1);
|
||||||
buf = Yap_TextTermToText(ti, buf0, 0, LOCAL_encoding);
|
buf = Yap_TextTermToText(ti, NULL, 0, LOCAL_encoding);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -292,7 +291,11 @@ void Yap_MemOps(StreamDesc *st) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sssno;
|
||||||
|
|
||||||
bool Yap_CloseMemoryStream(int sno) {
|
bool Yap_CloseMemoryStream(int sno) {
|
||||||
|
sssno++;
|
||||||
|
// if (sssno > 1720) Yap_do_low_level_trace=1;
|
||||||
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
||||||
fflush(GLOBAL_Stream[sno].file);
|
fflush(GLOBAL_Stream[sno].file);
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
read_term
|
|
||||||
* File: iopreds.c *
|
* File: iopreds.c *
|
||||||
* Last rev: 5/2/88 *
|
* Last rev: 5/2/88 *
|
||||||
* mods: *
|
* mods: *
|
||||||
@ -26,11 +25,11 @@ static char SccsId[] = "%W% %G%";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
|
#include "YapEval.h"
|
||||||
#include "YapFlags.h"
|
#include "YapFlags.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "YapText.h"
|
#include "YapText.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "YapEval.h"
|
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#if HAVE_STDARG_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;
|
TokEntry *tok0 = tok;
|
||||||
CELL *Hi = HR;
|
CELL *Hi = HR;
|
||||||
Term tf = TermNil;
|
Term ts[1];
|
||||||
Term *tailp = &tf;
|
ts[0] = TermNil;
|
||||||
|
Term *tailp = ts;
|
||||||
|
|
||||||
while (tok)
|
while (tok) {
|
||||||
{
|
|
||||||
|
|
||||||
if (HR > ASP - 1024)
|
if (HR > ASP - 1024) {
|
||||||
{
|
Int used = HR - Hi;
|
||||||
Int used = HR-Hi;
|
|
||||||
/* for some reason moving this earlier confuses gcc on solaris */
|
/* for some reason moving this earlier confuses gcc on solaris */
|
||||||
HR = Hi;
|
HR = Hi;
|
||||||
tok = tok0;
|
tok = tok0;
|
||||||
if (!Yap_gcl(used, 1, ENV, CP))
|
if (!Yap_gcl(used, 1, ENV, CP)) {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tok == errtok && tok->Tok != Error_tok)
|
if (tok == errtok && tok->Tok != Error_tok) {
|
||||||
{
|
|
||||||
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
|
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
|
||||||
tailp = RepPair(*tailp) + 1;
|
tailp = RepPair(*tailp) + 1;
|
||||||
}
|
}
|
||||||
Term rep = Yap_tokRep(tok);
|
Term rep = Yap_tokRep(tok);
|
||||||
*tailp = MkPairTerm(rep, TermNil);
|
*tailp = MkPairTerm(rep, TermNil);
|
||||||
tailp = RepPair(*tailp) + 1;
|
tailp = RepPair(*tailp) + 1;
|
||||||
if (tok->TokNext)
|
if (tok->TokNext == NULL) {
|
||||||
{
|
break;
|
||||||
|
}
|
||||||
tok = tok->TokNext;
|
tok = tok->TokNext;
|
||||||
}
|
}
|
||||||
|
Yap_DebugPlWriteln(ts[0]);
|
||||||
}
|
return ts[0];
|
||||||
return tf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@pred scan_to_list( +Stream, -Tokens )
|
@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)
|
+ `atom`(Atom)
|
||||||
+ `<QQ>`(Text)
|
+ `<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 `(`, `)`, `,`, `;`
|
+ symbols, including `(`, `)`, `,`, `;`
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static Int scan_to_list(USE_ARGS1)
|
static Int scan_to_list(USE_ARGS1) {
|
||||||
{
|
|
||||||
int inp_stream;
|
int inp_stream;
|
||||||
Term tpos, tout;
|
Term tpos, tout;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1)
|
if (inp_stream == -1) {
|
||||||
{
|
|
||||||
return false;
|
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);
|
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
||||||
tout = scanToList(tok, NULL);
|
tout = scanToList(tok, NULL);
|
||||||
if (tout == 0)
|
if (tout == 0)
|
||||||
return false;
|
return false;
|
||||||
Yap_clean_tokenizer(tok, LOCAL_VarTable, LOCAL_AnonVarTable);
|
Yap_clean_tokenizer(tok, LOCAL_VarTable, LOCAL_AnonVarTable);
|
||||||
|
|
||||||
return Yap_unify(ARG1, tout);
|
return Yap_unify(ARG2, tout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syntax Error Handler
|
* Syntax Error Handler
|
||||||
*
|
*
|
||||||
* @par tokptr: the sequence of tokens
|
* @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:
|
* Implicit arguments:
|
||||||
* +
|
* +
|
||||||
*/
|
*/
|
||||||
static Term syntax_error(TokEntry * errtok, int sno, Term cmod)
|
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term startline, errline, endline;
|
Term startline, errline, endline;
|
||||||
Term tf[3];
|
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);
|
startline = MkIntegerTerm(cline);
|
||||||
endline = MkIntegerTerm(cline);
|
endline = MkIntegerTerm(cline);
|
||||||
if (errtok != LOCAL_toktide)
|
if (errtok != LOCAL_toktide) {
|
||||||
{
|
|
||||||
errtok = LOCAL_toktide;
|
errtok = LOCAL_toktide;
|
||||||
}
|
}
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
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);
|
tm = MkStringTerm(LOCAL_ErrorMessage);
|
||||||
else
|
else
|
||||||
tm = MkStringTerm("syntax error");
|
tm = MkStringTerm("syntax error");
|
||||||
while (tok)
|
while (tok) {
|
||||||
{
|
|
||||||
|
|
||||||
if (HR > ASP - 1024)
|
if (HR > ASP - 1024) {
|
||||||
{
|
|
||||||
errline = MkIntegerTerm(0);
|
errline = MkIntegerTerm(0);
|
||||||
endline = MkIntegerTerm(0);
|
endline = MkIntegerTerm(0);
|
||||||
/* for some reason moving this earlier confuses gcc on solaris */
|
/* for some reason moving this earlier confuses gcc on solaris */
|
||||||
HR = Hi;
|
HR = Hi;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (tok->TokPos != cline)
|
if (tok->TokPos != cline) {
|
||||||
{
|
|
||||||
*tailp = MkPairTerm(TermNewLine, TermNil);
|
*tailp = MkPairTerm(TermNewLine, TermNil);
|
||||||
tailp = RepPair(*tailp) + 1;
|
tailp = RepPair(*tailp) + 1;
|
||||||
cline = tok->TokPos;
|
cline = tok->TokPos;
|
||||||
}
|
}
|
||||||
if (tok == errtok && tok->Tok != Error_tok)
|
if (tok == errtok && tok->Tok != Error_tok) {
|
||||||
{
|
|
||||||
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
|
*tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil);
|
||||||
tailp = RepPair(*tailp) + 1;
|
tailp = RepPair(*tailp) + 1;
|
||||||
}
|
}
|
||||||
Term rep = Yap_tokRep(tok);
|
Term rep = Yap_tokRep(tok);
|
||||||
if (tok->TokNext)
|
if (tok->TokNext) {
|
||||||
{
|
|
||||||
tok = tok->TokNext;
|
tok = tok->TokNext;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
endline = MkIntegerTerm(tok->TokPos);
|
endline = MkIntegerTerm(tok->TokPos);
|
||||||
tok = NULL;
|
tok = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -109,7 +109,7 @@ static Int rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS) {
|
|||||||
max_inp -= (buf_sz - 1);
|
max_inp -= (buf_sz - 1);
|
||||||
if (max_inp <= 0) {
|
if (max_inp <= 0) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user