This commit is contained in:
Vitor Santos Costa 2017-11-29 13:47:57 +00:00
parent 8feca162bf
commit 3688819ea2
31 changed files with 2944 additions and 2897 deletions

View File

@ -209,8 +209,8 @@ bool YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type) {
return TRUE;
}
void *YAP_blob_data(Atom x, size_t *len, blob_type_t **type) {
void *YAP_blob_data(YAP_Atom at, size_t *len, blob_type_t **type) {
Atom x = at;
if (!IsBlob(x)) {
if (len)

File diff suppressed because it is too large Load Diff

View File

@ -4911,17 +4911,17 @@ static Int cont_current_key_integer(USES_REGS1) {
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
}
Term Yap_FetchTermFromDB(DBTerm *ref) {
Term Yap_FetchTermFromDB(void *ref) {
CACHE_REGS
return GetDBTerm(ref, FALSE PASS_REGS);
}
Term Yap_FetchClauseTermFromDB(DBTerm *ref) {
Term Yap_FetchClauseTermFromDB(void *ref) {
CACHE_REGS
return GetDBTerm(ref, TRUE PASS_REGS);
}
Term Yap_PopTermFromDB(DBTerm *ref) {
Term Yap_PopTermFromDB(void *ref) {
CACHE_REGS
Term t = GetDBTerm(ref, FALSE PASS_REGS);
@ -5304,7 +5304,7 @@ static void ReleaseTermFromDB(DBTerm *ref USES_REGS) {
FreeDBSpace((char *)ref);
}
void Yap_ReleaseTermFromDB(DBTerm *ref) {
void Yap_ReleaseTermFromDB(void *ref) {
CACHE_REGS
ReleaseTermFromDB(ref PASS_REGS);
}

View File

@ -386,10 +386,10 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
Yap_RestartYap(1);
}
LOCAL_ActiveError->errorNo = type;
LOCAL_ActiveError->errorAsText = Yap_LookupAtom(Yap_errorName(type));
LOCAL_ActiveError->errorAsText = Yap_errorName(type);
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
LOCAL_ActiveError->classAsText =
Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass));
Yap_errorClassName(LOCAL_ActiveError->errorClass);
LOCAL_ActiveError->errorLine = lineno;
LOCAL_ActiveError->errorFunction = function;
LOCAL_ActiveError->errorFile = file;

View File

@ -2039,10 +2039,10 @@ static Int jump_env(USES_REGS1) {
// LOCAL_Error_TYPE = ERROR_EVENT;
Term t1 = ArgOfTerm(1, t);
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t2))->StrOfAE;
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(FunctorOfTerm(t1)))->StrOfAE;
} else if (IsAtomTerm(t)) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
LOCAL_ActiveError->classAsText = NULL;
}
} else {

View File

@ -689,12 +689,12 @@ static int send_error_message(char s[]) {
}
static wchar_t read_quoted_char(int *scan_nextp,
struct stream_desc *inp_stream) {
struct stream_desc *st) {
int ch;
/* escape sequence */
do_switch:
ch = getchrq(inp_stream);
ch = getchrq(st);
switch (ch) {
case 10:
return 0;
@ -705,7 +705,7 @@ do_switch:
case 'b':
return '\b';
case 'c':
while (chtype((ch = getchrq(inp_stream))) == BS)
while (chtype((ch = getchrq(st))) == BS)
;
{
if (ch == '\\') {
@ -732,7 +732,7 @@ do_switch:
wchar_t wc = '\0';
for (i = 0; i < 4; i++) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch <= '9') {
wc += (ch - '0') << ((3 - i) * 4);
} else if (ch >= 'a' && ch <= 'f') {
@ -750,7 +750,7 @@ do_switch:
wchar_t wc = '\0';
for (i = 0; i < 8; i++) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch <= '9') {
wc += (ch - '0') << ((7 - i) * 4);
} else if (ch >= 'a' && ch <= 'f') {
@ -777,7 +777,7 @@ do_switch:
if (trueGlobalPrologFlag(ISO_FLAG)) {
return send_error_message("invalid escape sequence");
} else {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch == '?') { /* delete character */
return 127;
} else if (ch >= 'a' && ch < 'z') { /* hexa */
@ -800,13 +800,13 @@ do_switch:
/* follow ISO */
{
unsigned char so_far = ch - '0';
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch < '8') { /* octal */
so_far = so_far * 8 + (ch - '0');
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch < '8') { /* octal */
so_far = so_far * 8 + (ch - '0');
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != '\\') {
return send_error_message("invalid octal escape sequence");
}
@ -826,19 +826,19 @@ do_switch:
/* hexadecimal character (YAP allows empty hexadecimal */
{
unsigned char so_far = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
so_far =
so_far * 16 + (chtype(ch) == NU
? ch - '0'
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
ch = getchrq(inp_stream);
ch = getchrq(st);
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
so_far =
so_far * 16 + (chtype(ch) == NU
? ch - '0'
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch == '\\') {
return so_far;
} else {
@ -890,7 +890,7 @@ static int num_send_error_message(char s[]) {
/* reads a number, either integer or float */
static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
int ch = *chp;
Int val = 0L, base = ch - '0';
int might_be_float = TRUE, has_overflow = FALSE;
@ -899,7 +899,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
int max_size = 254, left = 254;
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
/*
* because of things like 00'2, 03'2 and even better 12'2, I need to
* do this (have mercy)
@ -909,7 +909,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
base = 10 * base + ch - '0';
ch = getchr(inp_stream);
ch = getchr(st);
}
if (ch == '\'') {
if (base > 36) {
@ -919,7 +919,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (base == 0) {
CACHE_REGS
wchar_t ascii = ch;
@ -927,11 +927,11 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (ch == '\\' &&
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
ascii = read_quoted_char(&scan_extra, inp_stream);
ascii = read_quoted_char(&scan_extra, st);
}
/* a quick way to represent ASCII */
if (scan_extra)
*chp = getchr(inp_stream);
*chp = getchr(st);
if (sign == -1) {
return MkIntegerTerm(-ascii);
}
@ -951,7 +951,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = oval * base + chval;
if (oval != (val - chval) / base) /* overflow */
has_overflow = (has_overflow || TRUE);
ch = getchr(inp_stream);
ch = getchr(st);
}
}
} else if (ch == 'x' && base == 0) {
@ -959,7 +959,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
while (my_isxdigit(ch, 'F', 'f')) {
Int oval = val;
int chval =
@ -971,17 +971,17 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = val * 16 + chval;
if (oval != (val - chval) / 16) /* overflow */
has_overflow = TRUE;
ch = getchr(inp_stream);
ch = getchr(st);
}
*chp = ch;
} else if (ch == 'o' && base == 0) {
might_be_float = FALSE;
base = 8;
ch = getchr(inp_stream);
ch = getchr(st);
} else if (ch == 'b' && base == 0) {
might_be_float = FALSE;
base = 2;
ch = getchr(inp_stream);
ch = getchr(st);
} else {
val = base;
base = 10;
@ -1002,7 +1002,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = val * base + ch - '0';
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
has_overflow = TRUE;
ch = getchr(inp_stream);
ch = getchr(st);
}
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
int has_dot = (ch == '.');
@ -1010,7 +1010,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
unsigned char *dp;
int dc;
if (chtype(ch = getchr(inp_stream)) != NU) {
if (chtype(ch = getchr(st)) != NU) {
if (ch == 'e' || ch == 'E') {
if (trueGlobalPrologFlag(ISO_FLAG))
return num_send_error_message(
@ -1045,21 +1045,21 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
} while (chtype(ch = getchr(inp_stream)) == NU);
} while (chtype(ch = getchr(st)) == NU);
}
}
if (ch == 'e' || ch == 'E') {
if (--left == 0)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (ch == '-') {
if (--left == 0)
number_overflow();
*sp++ = '-';
ch = getchr(inp_stream);
ch = getchr(st);
} else if (ch == '+') {
ch = getchr(inp_stream);
ch = getchr(st);
}
if (chtype(ch) != NU) {
CACHE_REGS
@ -1071,7 +1071,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
} while (chtype(ch = getchr(inp_stream)) == NU);
} while (chtype(ch = getchr(st)) == NU);
}
*sp = '\0';
*chp = ch;
@ -1257,7 +1257,7 @@ const char *Yap_tokText(void *tokptre) {
return ".";
}
static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
static void open_comment(int ch, StreamDesc *st USES_REGS) {
CELL *h0 = HR;
HR += 5;
h0[0] = AbsAppl(h0 + 2);
@ -1272,7 +1272,7 @@ static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
LOCAL_CommentsTail = h0 + 1;
h0 += 2;
h0[0] = (CELL)FunctorMinus;
h0[1] = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
h0[1] = Yap_StreamPosition(st - GLOBAL_Stream);
h0[2] = TermNil;
LOCAL_CommentsNextChar = h0 + 2;
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
@ -1301,14 +1301,14 @@ static void close_comment(USES_REGS1) {
// mark that we reached EOF,
// next token will be end_of_file)
static void mark_eof(struct stream_desc *inp_stream) {
inp_stream->status |= Push_Eof_Stream_f;
static void mark_eof(struct stream_desc *st) {
st->status |= Push_Eof_Stream_f;
}
#define add_ch_to_buff(ch) \
{ charp += put_utf8(charp, ch); }
TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
Term *tposp) {
CACHE_REGS
@ -1324,14 +1324,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
LOCAL_AnonVarTable = NULL;
l = NULL;
p = NULL; /* Just to make lint happy */
ch = getchr(inp_stream);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "i %d", st-GLOBAL_Stream);
ch = getchr(st);
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
LOCAL_StartLineCount = inp_stream->linecount;
LOCAL_StartLinePos = inp_stream->linepos;
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
LOCAL_StartLineCount = st->linecount;
LOCAL_StartLinePos = st->linepos;
do {
int quote, isvar;
unsigned char *charp, *mp;
@ -1350,22 +1351,22 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
p = t;
restart:
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
switch (chtype(ch)) {
case CC:
if (store_comments) {
open_comment(ch, inp_stream PASS_REGS);
open_comment(ch, st PASS_REGS);
continue_comment:
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
while ((ch = getchr(st)) != 10 && chtype(ch) != EF) {
extend_comment(ch PASS_REGS);
}
extend_comment(ch PASS_REGS);
if (chtype(ch) != EF) {
ch = getchr(inp_stream);
ch = getchr(st);
if (chtype(ch) == CC) {
extend_comment(ch PASS_REGS);
goto continue_comment;
@ -1373,7 +1374,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
close_comment(PASS_REGS1);
} else {
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF)
while ((ch = getchr(st)) != 10 && chtype(ch) != EF)
;
}
if (chtype(ch) != EF) {
@ -1381,15 +1382,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (t == l) {
/* we found a comment before reading characters */
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
}
goto restart;
} else {
t->Tok = Ord(kind = eot_tok);
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
}
break;
@ -1398,14 +1399,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
case UL:
case LC: {
int32_t och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
size_t sz = 512;
TokImage = Malloc(sz PASS_REGS);
scan_name:
charp = (unsigned char *)TokImage;
isvar = (chtype(och) != LC);
add_ch_to_buff(och);
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
for (; chtype(ch) <= NU; ch = getchr(st)) {
if (charp == TokImage + (sz - 1)) {
unsigned char *p0 = TokImage;
sz = Yap_Min(sz * 2, sz + MBYTE);
@ -1423,7 +1424,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return CodeSpaceError(t, p, l);
}
add_ch_to_buff(ch);
ch = getchr(inp_stream);
ch = getchr(st);
}
add_ch_to_buff('\0');
if (!isvar) {
@ -1459,7 +1460,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
cha = ch;
cherr = 0;
CHECK_SPACE();
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
if ((t->TokInfo = get_num(&cha, &cherr, st, sign)) == 0L) {
if (p) {
p->Tok = eot_tok;
t->TokInfo = TermError;
@ -1471,7 +1472,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (cherr) {
TokEntry *e;
t->Tok = Number_tok;
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e == NULL) {
return TrailSpaceError(p, l);
@ -1497,7 +1498,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->Tok = Ord(Var_tok);
t->TokInfo = (Term)Yap_LookupVar("E");
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
return TrailSpaceError(p, l);
@ -1530,7 +1531,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '(')
solo_flag = FALSE;
t->TokInfo = MkAtomTerm(AtomE);
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
return TrailSpaceError(p, l);
@ -1557,7 +1558,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
charp = TokImage;
quote = ch;
len = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
size_t sz = 1024;
while (TRUE) {
@ -1577,23 +1578,23 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
break;
}
if (ch == quote) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != quote)
break;
add_ch_to_buff(ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
} else if (ch == '\\' &&
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
int scan_next = TRUE;
if ((ch = read_quoted_char(&scan_next, inp_stream))) {
if ((ch = read_quoted_char(&scan_next, st))) {
add_ch_to_buff(ch);
}
if (scan_next) {
ch = getchrq(inp_stream);
ch = getchrq(st);
}
} else {
add_ch_to_buff(ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
}
++len;
}
@ -1628,9 +1629,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '\0') {
int pch;
t->Tok = Ord(kind = eot_tok);
pch = Yap_peek(inp_stream - GLOBAL_Stream);
pch = Yap_peek(st - GLOBAL_Stream);
if (chtype(pch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNewLine;
@ -1638,11 +1639,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->TokInfo = TermEof;
return l;
} else
ch = getchr(inp_stream);
ch = getchr(st);
break;
case SY: {
int pch;
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
if (ch == '.' && (pch = Yap_peek(st - GLOBAL_Stream)) &&
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
t->Tok = Ord(kind = eot_tok);
// consume...
@ -1655,7 +1656,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '`')
goto quoted_string;
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (och == '.') {
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
t->Tok = Ord(kind = eot_tok);
@ -1664,7 +1665,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return l;
}
if (chtype(ch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNewLine;
@ -1675,12 +1676,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (och == '/' && ch == '*') {
if (store_comments) {
CHECK_SPACE();
open_comment('/', inp_stream PASS_REGS);
open_comment('/', st PASS_REGS);
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
och = ch;
CHECK_SPACE();
extend_comment(ch PASS_REGS);
ch = getchr(inp_stream);
ch = getchr(st);
}
if (chtype(ch) != EF) {
CHECK_SPACE();
@ -1690,7 +1691,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
} else {
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
}
}
if (chtype(ch) == EF) {
@ -1699,15 +1700,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
break;
} else {
/* leave comments */
ch = getchr(inp_stream);
ch = getchr(st);
if (t == l) {
/* we found a comment before reading characters */
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
CHECK_SPACE();
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
}
}
goto restart;
@ -1721,7 +1722,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return l;
}
if (chtype(ch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNl;
@ -1733,7 +1734,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
TokImage = Malloc(sz);
charp = TokImage;
add_ch_to_buff(och);
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
for (; chtype(ch) == SY; ch = getchr(st)) {
if (charp >= TokImage + (sz - 10)) {
sz = Yap_Min(sz * 2, sz + MBYTE);
TokImage = Realloc(TokImage, sz);
@ -1764,7 +1765,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
unsigned char chs[2];
chs[0] = ch;
chs[1] = '\0';
ch = getchr(inp_stream);
ch = getchr(st);
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
t->Tok = Ord(kind = Name_tok);
if (ch == '(')
@ -1773,7 +1774,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
case BK:
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
{
unsigned char chs[10];
TokImage = charp = chs;
@ -1783,12 +1784,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
if (och == '(') {
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
if (ch == ')') {
t->TokInfo = TermEmptyBrackets;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
} else if (!solo_flag) {
@ -1797,12 +1798,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
} else if (och == '[') {
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
};
if (ch == ']') {
t->TokInfo = TermNil;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
@ -1827,26 +1828,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
cur_qq = qq;
}
t->TokInfo = (CELL)qq;
if (inp_stream->status & Seekable_Stream_f) {
qq->start.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->start.byteno = fseek(st->file, 0, 0);
} else {
qq->start.byteno = inp_stream->charcount - 1;
qq->start.byteno = st->charcount - 1;
}
qq->start.lineno = inp_stream->linecount;
qq->start.linepos = inp_stream->linepos - 1;
qq->start.charno = inp_stream->charcount - 1;
qq->start.lineno = st->linecount;
qq->start.linepos = st->linepos - 1;
qq->start.charno = st->charcount - 1;
t->Tok = Ord(kind = QuasiQuotes_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
};
if (ch == '}') {
t->TokInfo = TermBraces;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
@ -1863,16 +1864,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
cur_qq = NULL;
t->TokInfo = (CELL)qq;
if (inp_stream->status & Seekable_Stream_f) {
qq->mid.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->mid.byteno = fseek(st->file, 0, 0);
} else {
qq->mid.byteno = inp_stream->charcount - 1;
qq->mid.byteno = st->charcount - 1;
}
qq->mid.lineno = inp_stream->linecount;
qq->mid.linepos = inp_stream->linepos - 1;
qq->mid.charno = inp_stream->charcount - 1;
qq->mid.lineno = st->linecount;
qq->mid.linepos = st->linepos - 1;
qq->mid.charno = st->charcount - 1;
t->Tok = Ord(kind = QuasiQuotes_tok);
ch = getchr(inp_stream);
ch = getchr(st);
sz = 1024;
TokImage = Malloc(sz);
if (!TokImage) {
@ -1885,11 +1886,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
charp = TokImage;
quote = ch;
len = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
while (TRUE) {
if (ch == '|') {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != '}') {
} else {
charp += put_utf8((unsigned char *)charp, och);
@ -1899,13 +1900,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
} else if (chtype(ch) == EF) {
Free(TokImage);
mark_eof(inp_stream);
mark_eof(st);
t->Tok = Ord(kind = eot_tok);
t->TokInfo = TermOutOfHeapError;
break;
} else {
charp += put_utf8(charp, ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
}
if (charp > (unsigned char *)AuxSp - 1024) {
/* Not enough space to read in the string. */
@ -1925,26 +1926,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
strncpy((char *)mp, (const char *)TokImage, len + 1);
qq->text = (unsigned char *)mp;
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
if (inp_stream->status & Seekable_Stream_f) {
qq->end.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->end.byteno = fseek(st->file, 0, 0);
} else {
qq->end.byteno = inp_stream->charcount - 1;
qq->end.byteno = st->charcount - 1;
}
qq->end.lineno = inp_stream->linecount;
qq->end.linepos = inp_stream->linepos - 1;
qq->end.charno = inp_stream->charcount - 1;
qq->end.lineno = st->linecount;
qq->end.linepos = st->linepos - 1;
qq->end.charno = st->charcount - 1;
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
solo_flag = FALSE;
ch = getchr(inp_stream);
ch = getchr(st);
break;
}
t->Tok = Ord(kind = Ponctuation_tok);
break;
case EF:
mark_eof(inp_stream);
mark_eof(st);
t->Tok = Ord(kind = eot_tok);
t->TokInfo = TermEof;
return l;
@ -1966,7 +1967,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
p->TokNext = e;
e->Tok = Error_tok;
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
e->TokPos = GetCurInpPos(inp_stream);
e->TokPos = GetCurInpPos(st);
e->TokNext = NULL;
LOCAL_ErrorMessage = NULL;
p = e;

View File

@ -1098,7 +1098,7 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
}
LOCAL_ActiveError->prologPredModule =
(pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog);
(pp->ModuleOfPred ? pp->ModuleOfPred : "prolog");
LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
if (codeptr->opc == UNDEF_OPCODE) {
LOCAL_ActiveError->prologPredFirstLine = 0;

View File

@ -147,14 +147,14 @@ static int dump_runtime_variables(void) {
return 1;
}
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char *saved_state,
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state,
int argc, char *argv[]) {
memset(iap, 0, sizeof(YAP_init_args));
YAP_init_args *iap = x;
memset(iap, 0, sizeof(YAP_init_args));
#if __ANDROID__
iap->boot_file_type = YAP_BOOT_PL;
iap->SavedState = malloc(strlen(saved_state)+1);
strcpy(iap->SavedState, saved_state);
iap->assetManager = true;
iap->SavedState = NULL;
iap->assetManager = NULL;
#else
iap->boot_file_type = YAP_QLY;
iap->SavedState = saved_state;
@ -498,7 +498,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
} else if (!strncmp("-home=", p, strlen("-home="))) {
GLOBAL_Home = p + strlen("-home=");
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
if (!ChDir(p + strlen("-cwd=")) ) {
if (!Yap_ChDir(p + strlen("-cwd=")) ) {
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno));
}

View File

@ -88,7 +88,9 @@ protected:
PredEntry *ap;
/// auxiliary routine to find a predicate in the current module.
PredEntry *getPred(YAPTerm &t, Term *&outp);
/// auxiliary routine to find a predicate in the current module.
PredEntry *getPred(YAPTerm &t, CELL *& outp);
PredEntry *asPred() { return ap; };
@ -122,7 +124,7 @@ protected:
///
/// It is just a call to getPred
inline YAPPredicate(Term t) {
CELL *v = NULL;
CELL *v = nullptr;
YAPTerm tt = YAPTerm(t);
ap = getPred(tt, v);
}
@ -131,7 +133,7 @@ protected:
///
/// It is just a call to getPred
inline YAPPredicate(YAPTerm t) {
Term *v = nullptr;
CELL *v = nullptr;
ap = getPred(t, v);
}
@ -275,13 +277,13 @@ public:
*/
class X_API YAPFLIP : public YAPPredicate {
public:
YAPFLIP(CPredicate call, YAPAtom name, uintptr_t arity,
YAPModule module = YAPModule(), CPredicate retry = 0,
CPredicate cut = 0, size_t extra = 0, bool test = false)
YAPFLIP(YAP_UserCPred call, YAPAtom name, YAP_Arity arity,
YAPModule module = YAPModule(), YAP_UserCPred retry = 0,
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
: YAPPredicate(name, arity, module) {
if (retry) {
Yap_InitCPredBackCut(name.getName(), arity, extra, call, retry, cut,
UserCPredFlag);
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra
);
} else {
if (test) {
YAP_UserCPredicate(name.getName(), call, arity);

View File

@ -19,7 +19,7 @@ X_API char *Yap_TermToString(Term t, encoding_t encodingp,
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
YAP_Term);
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
arity_t, arity_t);
YAP_Arity, YAP_Arity);
#if YAP_PYTHON
X_API bool do_init_python(void);
@ -944,7 +944,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
#if YAP_PYTHON
do_init_python();
#endif
YAP_PredEntryPtr p = YAP_AtomToPred( YAP_LookupAtom("initialize_prolog") );
YAPPredicate p = YAPPredicate( YAPAtomTerm("initialize_prolog") );
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
if (initq.next())
{
@ -992,7 +992,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
}
/// auxiliary routine to find a predicate in the current module.
PredEntry *YAPPredicate::getPred(YAPTerm &tt, Term *&outp)
PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL * &outp)
{
CACHE_REGS
Term m = Yap_CurrentModule(), t = tt.term();
@ -1110,7 +1110,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
if (LOCAL_ActiveError->prologPredLine)
{
s += "\n";
s += LOCAL_ActiveError->prologPredFile->StrOfAE;
s += LOCAL_ActiveError->prologPredFile;
s += ":";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
@ -1118,7 +1118,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
s += ":0 ";
s += LOCAL_ActiveError->prologPredModule;
s += ":";
s += (LOCAL_ActiveError->prologPredName)->StrOfAE;
s += (LOCAL_ActiveError->prologPredName);
s += "/";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
@ -1126,13 +1126,13 @@ YAPEngine::YAPEngine(int argc, char *argv[],
}
s += " error ";
if (LOCAL_ActiveError->classAsText != nullptr)
s += LOCAL_ActiveError->classAsText->StrOfAE;
s += LOCAL_ActiveError->classAsText;
s += ".";
s += LOCAL_ActiveError->errorAsText->StrOfAE;
s += LOCAL_ActiveError->errorAsText;
s += ".\n";
if (LOCAL_ActiveError->errorTerm)
{
Term t = LOCAL_ActiveError->errorTerm->Entry;
Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
if (t)
{
s += "error term is: ";

View File

@ -85,8 +85,16 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
YAP_Arity, YAP_Term);
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(),
int arity, int extra);
X_API extern void YAP_UserBackCPredicate(const char *name,
YAP_UserCPred init,
YAP_UserCPred cont,
YAP_Arity arity, YAP_Arity extra);
X_API extern void YAP_UserBackCutCPredicate(const char *name,
YAP_UserCPred init,
YAP_UserCPred cont,
YAP_UserCPred cut,
YAP_Arity arity, YAP_Arity extra);
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);

View File

@ -185,17 +185,15 @@ public:
virtual void run(char *s) {}
};
void YAP_init_args::YAP_init_args()
{
Yap_InitDefaults(this, NULL, 0, NULL);
} ;
/// @brief Setup all arguments to a new engine
struct X_API YAPEngineArgs: YAP_init_args {
public:
YAPEngineArgs(): yap_boot_params() {
#if YAP_PYTHON
YAPEngineArgs():yap_boot_params() {
char s[32];
strcpy(s, "startup.yss" );
Yap_InitDefaults(this,s,0,nullptr);
#if YAP_PYTHON
Embedded = true;
python_in_python = Py_IsInitialized();
#endif

View File

@ -96,7 +96,7 @@ typedef struct ExtraAtomEntryStruct {
#define USE_OFFSETS_IN_PROPS 0
#endif
typedef SFLAGS PropFlags;
typedef u_short PropFlags;
/* basic property entry structure */
typedef struct PropEntryStruct {

View File

@ -17,9 +17,6 @@
#include "YapTermConfig.h"
#include "config.h"
typedef void *Functor;
typedef void *Atom;
#endif
#if HAVE_STDINT_H
@ -29,6 +26,22 @@ typedef void *Atom;
#include <inttypes.h>
#endif
/* truth-values */
/* stdbool defines the booleam type, bool,
and the constants false and true */
#if HAVE_STDBOOL_H
#include <stdbool.h>
#else
#ifndef true
typedef int _Bool;
#define bool _Bool;
#define false 0
#define true 1
#endif
#endif /* HAVE_STDBOOL_H */
#define ALIGN_BY_TYPE(X, TYPE) \
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
@ -45,59 +58,98 @@ typedef void *Atom;
#if defined(PRIdPTR)
typedef intptr_t Int;
typedef uintptr_t UInt;
typedef intptr_t YAP_Int;
typedef uintptr_t YAP_UInt;
#elif defined(_WIN64)
typedef int64_t Int;
typedef uint64_t UInt;
typedef int64_t YAP_Int;
typedef uint64_t YAP_UInt;
#elif defined(_WIN32)
typedef int32_t Int;
typedef uint32_t UInt;
typedef int32_t YAP_Int;
typedef uint32_t YAP_UInt;
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
typedef long int Int;
typedef unsigned long int UInt;
typedef long int YAP_Int;
typedef unsigned long int YAP_UInt;
#elif SIZEOF_INT == SIZEOF_INT_P
typedef int Int;
typedef unsigned int UInt;
typedef int YAP_Int;
typedef unsigned int YAP_UInt;
#else
#error Yap require integer types of the same size as a pointer
#endif
/* */ typedef short int Short;
/* */ typedef unsigned short int UShort;
/* */ typedef short int YAP_Short;
/* */ typedef unsigned short int YAP_UShort;
typedef UInt CELL;
typedef YAP_UInt YAP_CELL;
typedef YAP_UInt YAP_Term;
/* Type definitions */
#ifndef TRUE
#define TRUE true
#endif
#ifndef FALSE
#endif
typedef bool YAP_Bool;
#define FALSE false
typedef YAP_Int YAP_handle_t;
typedef double YAP_Float;
typedef void *YAP_Atom;
typedef void *YAP_Functor;
#ifdef YAP_H
typedef YAP_Int Int;
typedef YAP_UInt UInt;
typedef YAP_Short Short;
typedef YAP_UShort UShort;
typedef uint16_t BITS16;
typedef int16_t SBITS16;
typedef uint32_t BITS32;
typedef YAP_CELL CELL;
typedef YAP_Term Term;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#define SmallSize sizeof(SMALLUNSGN)
typedef YAP_Int Int;
typedef YAP_Float Float;
typedef YAP_handle_t yhandle_t;
#endif
#include "YapError.h"
#include "../os/encoding.h"
typedef encoding_t YAP_encoding_t;
#include "YapFormat.h"
/*************************************************************************************************
type casting macros
*************************************************************************************************/
typedef UInt Term;
typedef Int yhandle_t;
typedef double Float;
#if SIZEOF_INT < SIZEOF_INT_P
#define SHORT_INTS 1
#else

View File

@ -1306,10 +1306,10 @@ void Yap_UpdateTimestamps(PredEntry *);
void Yap_ErDBE(DBRef);
DBTerm *Yap_StoreTermInDB(Term, int);
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
Term Yap_FetchTermFromDB(DBTerm *);
Term Yap_FetchClauseTermFromDB(DBTerm *);
Term Yap_PopTermFromDB(DBTerm *);
void Yap_ReleaseTermFromDB(DBTerm *);
Term Yap_FetchTermFromDB(void *);
Term Yap_FetchClauseTermFromDB(void *);
Term Yap_PopTermFromDB(void *);
void Yap_ReleaseTermFromDB(void *);
/* init.c */
Atom Yap_GetOp(OpEntry *, int *, int);
@ -1598,8 +1598,8 @@ bool Yap_PutException(Term t);
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
return LOCAL_BallTerm != NULL;
}
INLINE_ONLY inline EXTERN DBTerm *Yap_RefToException(void) {
DBTerm *dbt = LOCAL_BallTerm;
INLINE_ONLY inline EXTERN void *Yap_RefToException(void) {
void *dbt = LOCAL_BallTerm;
LOCAL_BallTerm = NULL;
return dbt;
}

View File

@ -80,7 +80,7 @@ typedef struct vfs {
const char *suffix;
bool (*chDir)(struct vfs *me, const char *s);
/** operations */
void *(*open)(int sno, const char *fname, const char *io_mode); /// open an object
void *(*open)(struct vfs *,int sno, const char *fname, const char *io_mode); /// open an object
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
bool (*close)(int sno); /// close the object
int (*get_char)(int sno); /// get an octet to the stream
@ -92,7 +92,7 @@ typedef struct vfs {
const char *(*nextdir)(void *d); /// walk to the next entry in a directory object
bool (*closedir)(void *d);
; /// close access a directory object
bool (*stat)(const char *s,
bool (*stat)(struct vfs *,const char *s,
vfs_stat *); /// obtain size, age, permissions of a file.
bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory.
bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.

View File

@ -50,23 +50,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef YAP_H
/* The YAP main types */
#include "YapTerm.h"
/**
This term can never be constructed as a valid term, so it is
used as a "BAD" term
*/
#define TermZERO ((Term)0)
#else
#include "YapConfig.h"
#endif /* YAP_H */
#if HAVE_STDINT_H
#include <stdint.h>
#endif
@ -74,21 +61,6 @@
#include <inttypes.h>
#endif
/* truth-values */
/* stdbool defines the booleam type, bool,
and the constants false and true */
#if HAVE_STDBOOL_H
#include <stdbool.h>
#else
#ifndef true
typedef int _Bool;
#define bool _Bool;
#define false 0
#define true 1
#endif
#endif /* HAVE_STDBOOL_H */
/**
FALSE and TRUE are the pre-standard versions,
still widely used.
@ -103,79 +75,26 @@ typedef int _Bool;
typedef bool YAP_Bool;
#endif
#ifdef YAP_H
/* if Yap.h is available, just reexport */
/**
This term can never be constructed as a valid term, so it is
used as a "BAD" term
*/
#define TermZERO ((Term)0)
#define YAP_CELL CELL
#define YAP_Term Term
#include "YapConfig.h"
#define YAP_Arity arity_t
#define YAP_Module Term
#define YAP_Functor Functor
#define YAP_Atom Atom
#define YAP_Int Int
#define YAP_UInt UInt
#define YAP_Float Float
#define YAP_handle_t yhandle_t
#define YAP_PredEntryPtr struct pred_entry *
#define YAP_UserCPred CPredicate
#define YAP_agc_hook Agc_hook
#define YAP_encoding_t encoding_t
#else
/* Type definitions */
#if defined(PRIdPTR)
typedef uintptr_t YAP_UInt;
typedef intptr_t YAP_Int;
#elif _WIN64
typedef int64_t YAP_Int;
typedef uint64_t YAP_UInt;
#elif _WIN32
typedef int32_t YAP_Int;
typedef uint32_t YAP_UInt;
#else
typedef long int YAP_Int;
typedef unsigned long int YAP_UInt;
#endif
typedef YAP_UInt YAP_CELL;
typedef YAP_CELL YAP_Term;
typedef void *YAP_PredEntryPtr;
typedef size_t YAP_Arity;
typedef YAP_Term YAP_Module;
typedef struct FunctorEntry *YAP_Functor;
typedef struct AtomEntry *YAP_Atom;
typedef double YAP_Float;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef YAP_Int YAP_handle_t;
typedef struct YAP_pred_entry *YAP_PredEntryPtr;
typedef void *YAP_PredEntryPtr;
typedef YAP_Bool (*YAP_UserCPred)(void);
@ -187,8 +106,6 @@ typedef int (*YAP_agc_hook)(void *_Atom);
typedef encoding_t YAP_encoding_t;
#endif
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
@ -257,6 +174,10 @@ typedef enum {
#define YAP_RECONSULT_MODE 1
#define YAP_BOOT_MODE 2
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
int Argc, char *Argv[]);
typedef struct yap_boot_params {
//> boot type as suggested by the user
YAP_file_type_t boot_file_type;
@ -351,16 +272,8 @@ typedef struct yap_boot_params {
int ErrorNo;
//> errorstring
char *ErrorCause;
#ifdef __cplusplus
void YAP_init_args();
#endif
} YAP_init_args;
#ifdef YAP_H
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
int Argc, char **Argv);
#endif
/* this should be opaque to the user */
typedef struct {
unsigned long b; //> choice-point at entry

View File

@ -176,48 +176,48 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
/// go back t
} yap_error_stage_t;
/// a Prolo goal that caused a bug
/// a Prolog goal that caused a bug
typedef struct error_prolog_source {
YAP_Int prologPredCl;
YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine;
YAP_UInt prologPredLastLine;
YAP_Atom prologPredName;
YAP_UInt prologPredArity;
YAP_Term prologPredModule;
YAP_Atom prologPredFile;
struct DB_TERM *errorGoal;
intptr_t prologPredCl;
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
const char * prologPredName;
uintptr_t prologPredArity;
const char * prologPredModule;
const char * prologPredFile;
void *errorGoal;
struct error_prolog_source *errorParent;
} error_prolog_source_t;
/// all we need to know about an error/throw
typedef struct yap_error_descriptor {
typedef struct error_descriptor {
enum yap_error_status status;
yap_error_class_number errorClass;
YAP_Atom errorAsText;
YAP_Atom classAsText;
const char * errorAsText;
const char * classAsText;
yap_error_number errorNo;
YAP_Int errorLine;
intptr_t errorLine;
const char *errorFunction;
const char *errorFile;
// struct error_prolog_source *errorSource;
YAP_Int prologPredCl;
YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine;
YAP_UInt prologPredLastLine;
YAP_Atom prologPredName;
YAP_UInt prologPredArity;
YAP_Term prologPredModule;
YAP_Atom prologPredFile;
YAP_UInt prologParserLine;
YAP_UInt prologParserFirstLine;
YAP_UInt prologParserLastLine;
YAP_Atom prologParserName;
YAP_Atom prologParserFile;
YAP_Bool prologConsulting;
struct DB_TERM *errorTerm;
YAP_Term rawErrorTerm, rawExtraErrorTerm;
intptr_t prologPredCl;
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
const char * prologPredName;
uintptr_t prologPredArity;
const char * prologPredModule;
const char * prologPredFile;
uintptr_t prologParserLine;
uintptr_t prologParserFirstLine;
uintptr_t prologParserLastLine;
const char * prologParserName;
const char * prologParserFile;
bool prologConsulting;
void *errorTerm;
uintptr_t rawErrorTerm, rawExtraErrorTerm;
char *errorMsg;
size_t errorMsgLen;
struct yap_error_descriptor *top_error;

View File

@ -268,18 +268,19 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
YAP_UserCPred, YAP_Arity, YAP_Arity);
/* YAP_Int YAP_ListLength(YAP_Term t) */
extern X_API YAP_Int YAP_ListLength(YAP_Term);
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
int
arity, int extra) */
extern X_API void YAP_UserBackCutCPredicate(const char *, YAP_UserCPred,
extern X_API void YAP_UserBackCutCPredicate(const char *name, YAP_UserCPred,
YAP_UserCPred, YAP_UserCPred,
YAP_Arity, YAP_Arity);
/* YAP_Int YAP_ListLength(YAP_Term t) */
extern X_API YAP_Int YAP_ListLength(YAP_Term);
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
/* void CallProlog(YAP_Term t) */
extern X_API YAP_Int YAP_CallProlog(YAP_Term t);
@ -399,7 +400,7 @@ extern X_API YAP_Term YAP_ReadFromStream(int s);
/// read a Prolog clause from a Prolog opened stream $s$. Similar to
/// YAP_ReadFromStream() but takes /// default options from read_clause/3.
extern X_API YAP_Term YAP_ReadFromStream(int s);
extern X_API YAP_Term YAP_ReadClauseFromStream(int s);
extern X_API void YAP_Write(YAP_Term t, FILE *s, int);

View File

@ -136,9 +136,9 @@ FILE *open_memstream(char **buf, size_t *len);
#endif
#if __ANDROID__
#undef HAVE_FMEMOPEN
#undef HAVE_OPEN_MEMSTREAM
//extern FILE * fmemopen(void *buf, size_t size, const char *mode);
#define HAVE_FMEMOPEN 1
#define HAVE_OPEN_MEMSTREAM 1
#endif
#if HAVE_FMEMOPEN

View File

@ -7,7 +7,10 @@ set (YAPOS_SOURCES
console.c
files.c
fmem.c
fmemopen.c
# fmemopen.c
#android/fmemopen.c
# android/fopencookie.c
# android/open_memstream.c
format.c
iopreds.c
mem.c

View File

@ -35,197 +35,188 @@ static char SccsId[] = "%W% %G%";
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
AAssetManager * Yap_assetManager;
AAssetManager *Yap_assetManager;
jboolean Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
{
jboolean
Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv *env, jclass clazz, jobject assetManager) {
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
return true;
return true;
}
static void *
open_asset__( int sno, const char *fname, const char *io_mode)
{
int mode;
const void *buf;
VFS_t *me = GLOBAL_Stream[sno].vfs;
if (strstr(fname,"/assets") == fname) {
// we're in
if ( Yap_assetManager == NULL) {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"asset manager",
fname);
return NULL;
}
if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"%s: no writing but flags are %s",
fname, io_mode);
return NULL;
}
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
else {
mode = AASSET_MODE_UNKNOWN;
}
AAsset *a = AAssetManager_open( Yap_assetManager, fname, mode);
// try not to use it as an asset
off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd;
StreamDesc *st = GLOBAL_Stream+sno;
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as red-only file
st->file = fdopen(fd, "r");
st->vfs = me;
st->vfs_handle = a;
return a;
} else if ((buf = AAsset_getBuffer(a))) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
if (rc) AAsset_close(a);
return st;
}
// should be done, but if not
GLOBAL_Stream[sno].vfs_handle= a;
st->vfs = me;
return a;
}
return NULL;
open_asset__(VFS_t *me, int sno, const char *fname, const char *io_mode) {
int mode;
const void *buf;
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
else {
mode = AASSET_MODE_UNKNOWN;
}
fname += strlen(me->prefix) + 1;
AAsset *a = AAssetManager_open(Yap_assetManager, fname, mode);
if (!a)
return NULL;
// try not to use it as an asset
off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd;
StreamDesc *st = GLOBAL_Stream + sno;
if ((buf = AAsset_getBuffer(a))) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
if (rc) AAsset_close(a);
st->vfs = NULL;
st->vfs_handle = NULL;
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
return st;
} else if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as read-only file
st->file = fdopen(fd, "r");
st->vfs = NULL;
st->vfs_handle = NULL;
st->status = Seekable_Stream_f|Input_Stream_f;
return st;
} else {
// should be done, but if not
GLOBAL_Stream[sno].vfs_handle = a;
st->vfs = me;
st->status = Input_Stream_f;
return a;
}
}
static bool
close_asset(int sno)
{
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
return true;
close_asset(int sno) {
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
return true;
}
static int64_t seek64(int sno, int64_t offset, int whence)
{
return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
static int64_t seek64(int sno, int64_t offset, int whence) {
return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
}
static int getc_asset(int sno)
{
int ch;
if ( AAsset_read (GLOBAL_Stream[sno].vfs_handle, &ch, 1) )
return ch;
return -1;
static int getc_asset(int sno) {
int ch;
if (AAsset_read(GLOBAL_Stream[sno].vfs_handle, &ch, 1))
return ch;
return -1;
}
static void *opendir_a( VFS_t *me, const char *dirName)
{
return (void *)AAssetManager_openDir (Yap_assetManager, dirName);
static void *opendir_a(VFS_t *me, const char *dirName) {
dirName += strlen(me->prefix) + 1;
return (void *) AAssetManager_openDir(Yap_assetManager, dirName);
}
static const char *readdir_a(void *dirHandle)
{
return AAssetDir_getNextFileName ((AAssetDir *)dirHandle);
static const char *readdir_a(void *dirHandle) {
return AAssetDir_getNextFileName((AAssetDir *) dirHandle);
}
static bool closedir_a(void *dirHandle)
{
AAssetDir_close ((AAssetDir *)dirHandle);
return true;
static bool closedir_a(void *dirHandle) {
AAssetDir_close((AAssetDir *) dirHandle);
return true;
}
static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out)
{
struct stat bf;
if (stat( "/assets", &bf)) {
out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid;
memcpy(&out->st_atimespec, (const void *)&out->st_atimespec, sizeof(struct timespec));
memcpy(&out->st_mtimespec,(const void *) &out->st_mtimespec, sizeof(struct timespec));
memcpy(&out->st_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec));
}
AAsset *a = AAssetManager_open( Yap_assetManager , fname, AASSET_MODE_UNKNOWN);
static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
struct stat bf;
fname += strlen(me->prefix) + 1;
if (stat("/assets", &bf)) {
out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid;
memcpy(&out->st_atimespec, (const void *) &out->st_atimespec, sizeof(struct timespec));
memcpy(&out->st_mtimespec, (const void *) &out->st_mtimespec, sizeof(struct timespec));
memcpy(&out->st_ctimespec, (const void *) &out->st_ctimespec, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *) &out->st_birthtimespec,
sizeof(struct timespec));
}
AAsset *a = AAssetManager_open(Yap_assetManager, fname, AASSET_MODE_UNKNOWN);
// try not to use it as an asset
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
return true;
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
return true;
}
static
bool is_dir_a( VFS_t *me,const char *dirName)
{
bool rc;
bool is_dir_a(VFS_t *me, const char *dirName) {
bool rc;
dirName += strlen(me->prefix) + 1;
// try not to use it as an asset
AAssetDir *d = AAssetManager_openDir ( Yap_assetManager, dirName);
AAssetDir *d = AAssetManager_openDir(Yap_assetManager, dirName);
if (d == NULL)
return false;
return false;
rc = (AAssetDir_getNextFileName(d) != NULL);
AAssetDir_close(d);
return rc;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "isdir %s <%p>", dirName, d);
AAssetDir_close(d);
return rc;
}
static
VFS_t *exists_a(VFS_t *me, const char *dirName)
{
bool exists_a(VFS_t *me, const char *dirName) {
dirName += strlen(me->prefix) + 1;
// try not to use it as an asset
AAsset *d = AAssetManager_open ( Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
AAsset *d = AAssetManager_open(Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exists %s <%p>", dirName, d);
if (d == NULL)
return NULL;
AAsset_close(d);
return me;
return false;
AAsset_close(d);
return true;
}
static bool set_cwd (VFS_t *me, const char *dirName) {
static bool set_cwd(VFS_t *me, const char *dirName) {
chdir("/assets");
if (me->virtual_cwd)
free((void*)(me->virtual_cwd));
me->virtual_cwd = malloc( sizeof(dirName) + 1 );
return me!= NULL;
if (!me->virtual_cwd)
me->virtual_cwd = malloc(YAP_FILENAME_MAX + 1);
strcpy(me->virtual_cwd, dirName);
return true;
}
#endif
VFS_t *
Yap_InitAssetManager( void )
{
Yap_InitAssetManager(void) {
#if __ANDROID__
VFS_t *me;
/* init standard VFS */
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** operations */
me->open = open_asset__; /// open an object in this space
me->close= close_asset; /// close the object
me->get_char = getc_asset; /// get an octet to the stream
me->put_char = NULL; /// output an octet to the stream
me->seek = seek64; /// jump around the stream
me->opendir = opendir_a; /// open a directory object, if one exists
me->nextdir = readdir_a; /// open a directory object, if one exists
me->closedir = closedir_a; /// close access a directory object
me->stat = stat_a; /// obtain size, age, permissions of a file.
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
me->exists = exists_a; /// obtain size, age, permissions of a file.
me->chdir = set_cwd; /// chnage working directory.
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
me->writers = NULL;
LOCK(BGL);
me-> next = GLOBAL_VFS;
GLOBAL_VFS = me;
return me;
UNLOCK(BGL);
return me;
/* init standard VFS */
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC | VFS_CAN_SEEK |
VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** operations */
me->open = open_asset__; /// open an object in this space
me->close = close_asset; /// close the object
me->get_char = getc_asset; /// get an octet to the stream
me->put_char = NULL; /// output an octet to the stream
me->seek = seek64; /// jump around the stream
me->opendir = opendir_a; /// open a directory object, if one exists
me->nextdir = readdir_a; /// open a directory object, if one exists
me->closedir = closedir_a; /// close access a directory object
me->stat = stat_a; /// obtain size, age, permissions of a file.
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
me->exists = exists_a; /// obtain size, age, permissions of a file.
me->chdir = set_cwd; /// chnage working directory.
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
me->writers = NULL;
me->virtual_cwd = NULL;
LOCK(BGL);
me->next = GLOBAL_VFS;
GLOBAL_VFS = me;
return me;
UNLOCK(BGL);
return me;
#else
return NULL;
#endif

View File

@ -20,6 +20,11 @@
#define ENCODING_H 1
#include "YapError.h"
#if HAVE_STRING_H
#include <string.h>
#endif
typedef enum {
ENC_OCTET = 0, /// binary files

View File

@ -114,16 +114,18 @@ bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS)
return true;
}
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
size_t nchars) {
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
size_t nchars USES_REGS) {
FILE *f;
// like any file stream.
st->file = f = fmemopen((void *)buf, nchars, "r");
st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
st->file = f = fmemopen(buf, nchars, "r");
st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f;
st->vfs = NULL;
st->encoding = enc;
st->encoding = LOCAL_encoding;
Yap_DefaultStreamOps(st);
st->linecount = 0;
st->linepos = st->charcount = 0;
return true;
}
@ -198,9 +200,7 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
// setbuf(st->file, NULL);
st->status |= Seekable_Stream_f;
#else
st->file = fmemopen((void *)buf, nchars, "w");
st->nsize = nchars;
st->nbuf = buf;
st->file = fmemopen((void *)st->nbuf, st->nsize, "w");
if (!st->nbuf) {
return -1;
}

View File

@ -1,10 +1,12 @@
* Copyright (C) 2007 Eric Blake
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*
* Modifications for Android written Jul 2009 by Alan Viverette
*/
#if __ANDROID__
/*
FUNCTION
<fmemopen>>---open a stream around a fixed-length string
@ -69,7 +71,7 @@ Supporting OS subroutines required: <<sbrk>>.
#include <errno.h>
#include <string.h>
#include <malloc.h>
#include "stdioext.h"
//#include "stdioext.h"
/* Describe details of an open memstream. */
typedef struct fmemcookie {
@ -172,13 +174,13 @@ fmemseek(void *cookie, fpos_t pos, int whence)
}
else
{
if (c->writeonly &amp;&amp; c->pos < c->eof)
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly &amp;&amp; c->pos < c->eof)
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
@ -206,9 +208,9 @@ fmemopen(void *buf, size_t size, const char *mode)
int flags;
int dummy;
if ((flags = __sflags (mode, &amp;dummy)) == 0)
if ((flags = __sflags (mode, &dummy)) == 0)
return NULL;
if (!size || !(buf || flags &amp; __SAPP))
if (!size || !(buf || flags & __SAPP))
{
return NULL;
}
@ -225,7 +227,7 @@ fmemopen(void *buf, size_t size, const char *mode)
c->max = size;
/* 9 modes to worry about. */
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
c->writeonly = (flags &amp; __SWR) != 0;
c->writeonly = (flags & __SWR) != 0;
c->saved = '\0';
if (!buf)
{
@ -233,7 +235,7 @@ fmemopen(void *buf, size_t size, const char *mode)
c->buf = (char *) (c + 1);
*(char *) buf = '\0';
c->pos = c->eof = 0;
c->append = (flags &amp; __SAPP) != 0;
c->append = (flags & __SAPP) != 0;
}
else
{
@ -244,7 +246,7 @@ fmemopen(void *buf, size_t size, const char *mode)
/* a/a+ and buf: position and size at first NUL. */
buf = memchr (c->buf, '\0', size);
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
if (!buf &amp;&amp; c->writeonly)
if (!buf && c->writeonly)
/* a: guarantee a NUL within size even if no writes. */
c->buf[size - 1] = '\0';
c->append = 1;
@ -267,10 +269,12 @@ fmemopen(void *buf, size_t size, const char *mode)
fp->_file = -1;
fp->_flags = flags;
fp->_cookie = c;
fp->_read = flags &amp; (__SRD | __SRW) ? fmemread : NULL;
fp->_write = flags &amp; (__SWR | __SRW) ? fmemwrite : NULL;
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
fp->_seek = fmemseek;
fp->_close = fmemclose;
return fp;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ Int Yap_CloseSocket(int, socket_info, socket_domain);
#endif /* USE_SOCKET */
extern bool Yap_clearInput(int sno);
extern Term Yap_read_term(int inp_stream, Term opts, bool clauatse);
extern Term Yap_read_term(int inp_stream, Term opts, bool clause);
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
extern void init_read_data(ReadData _PL_rd, struct stream_desc *s);
@ -216,7 +216,7 @@ INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s) {
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
inline static Atom StreamFullName(int i) { return (GLOBAL_Stream[i].name); }
inline static Atom StreamFullName(int i) { return (Atom)(GLOBAL_Stream[i].name); }
inline static void console_count_output_char(int ch, StreamDesc *s) {
CACHE_REGS

View File

@ -829,13 +829,13 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
return YAP_SCANNING;
}
static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
static parser_state_t scan(REnv *re, FEnv *fe, int sno) {
CACHE_REGS
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
LOCAL_tokptr = LOCAL_toktide =
Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos);
Yap_tokenizer(GLOBAL_Stream + sno, false, &fe->tpos);
#if DEBUG
if (GLOBAL_Option[2]) {
TokEntry *t = LOCAL_tokptr;
@ -857,7 +857,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
LOCAL_Error_TYPE = SYNTAX_ERROR;
return YAP_PARSING_ERROR;
}
return scanEOF(fe, inp_stream);
return scanEOF(fe, sno);
}
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
@ -956,7 +956,7 @@ static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) {
*
*
*/
Term Yap_read_term(int inp_stream, Term opts, bool clause) {
Term Yap_read_term(int sno, Term opts, bool clause) {
FEnv fe;
REnv re;
#if EMACS
@ -968,23 +968,23 @@ Term Yap_read_term(int inp_stream, Term opts, bool clause) {
while (true) {
switch (state) {
case YAP_START_PARSING:
state = initParser(opts, &fe, &re, inp_stream, clause);
state = initParser(opts, &fe, &re, sno, clause);
if (state == YAP_PARSING_FINISHED) {
pop_text_stack(lvl);
return 0;
}
break;
case YAP_SCANNING:
state = scan(&re, &fe, inp_stream);
state = scan(&re, &fe, sno);
break;
case YAP_SCANNING_ERROR:
state = scanError(&re, &fe, inp_stream);
state = scanError(&re, &fe, sno);
break;
case YAP_PARSING:
state = parse(&re, &fe, inp_stream);
state = parse(&re, &fe, sno);
break;
case YAP_PARSING_ERROR:
state = parseError(&re, &fe, inp_stream);
state = parseError(&re, &fe, sno);
break;
case YAP_PARSING_FINISHED: {
CACHE_REGS
@ -1021,17 +1021,17 @@ static Int
static Int read_term(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Term out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream == -1) {
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno == -1) {
return (FALSE);
}
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), false);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, ARG3), false);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out != 0L;
}
@ -1060,7 +1060,7 @@ static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()};
#undef PAR
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
int inp_stream) {
int sno) {
CACHE_REGS
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
@ -1082,7 +1082,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
fe->cmod = PROLOG_MODULE;
}
re->bq = getBackQuotesFlag();
fe->enc = GLOBAL_Stream[inp_stream].encoding;
fe->enc = GLOBAL_Stream[sno].encoding;
fe->sp = 0;
fe->qq = 0;
if (args[READ_CLAUSE_OUTPUT].used) {
@ -1118,12 +1118,12 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
fe->vp = 0;
}
fe->ce = Yap_CharacterEscapes(fe->cmod);
re->seekable = (GLOBAL_Stream[inp_stream].status & Seekable_Stream_f) != 0;
re->seekable = (GLOBAL_Stream[sno].status & Seekable_Stream_f) != 0;
if (re->seekable) {
#if HAVE_FGETPOS
fgetpos(GLOBAL_Stream[inp_stream].file, &re->rpos);
fgetpos(GLOBAL_Stream[sno].file, &re->rpos);
#else
re->cpos = GLOBAL_Stream[inp_stream].charcount;
re->cpos = GLOBAL_Stream[sno].charcount;
#endif
}
re->prio = LOCAL_default_priority;
@ -1166,15 +1166,15 @@ static Int read_clause2(USES_REGS1) {
*/
static Int read_clause(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Term out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream < 0)
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno < 0)
return false;
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), true);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, ARG3), true);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out != 0;
}
@ -1191,20 +1191,20 @@ static Int read_clause(
*/
#if 0
static Int start_mega(USES_REGS1) {
int inp_stream;
int sno;
Term out;
Term t3 = Deref(ARG3);
yhandle_t h = Yap_InitSlot(ARG2);
TokENtry *tok;
arity_t srity = 0;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
if (inp_stream < 0)
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
if (sno < 0)
return false;
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
LOCAL_tokptr = LOCAL_toktide =
x Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos);
x Yap_tokenizer(GLOBAL_Stream + sno, false, &tpos);
if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL &&
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
bool start = true;
@ -1253,16 +1253,16 @@ static Int source_location(USES_REGS1) {
*/
static Int read2(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Int out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream == -1) {
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno == -1) {
return (FALSE);
}
out = Yap_read_term(inp_stream, add_output(ARG2, TermNil), false);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, TermNil), false);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out;
}

View File

@ -52,7 +52,6 @@ static Int p_putenv(USES_REGS1);
static Term do_glob(const char *spec, bool ok_to);
#ifdef MACYAP
static int chdir(char *);
/* #define signal skel_signal */
#endif /* MACYAP */
static const char *expandVars(const char *spec, char *u);
@ -104,7 +103,7 @@ static bool is_directory(const char *FileName) {
bool Yap_Exists(const char *f) {
VFS_t *vfs;
if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs,f) != NULL;
return vfs->exists(vfs,f);
}
#if _WIN32
if (_access(f, 0) == 0)
@ -346,7 +345,7 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
#define HAVE_REALPATH 1
#endif
bool ChDir(const char *path) {
bool Yap_ChDir(const char *path) {
bool rc = false;
char qp[FILENAME_MAX + 1];
const char *qpath = Yap_AbsoluteFile(path, qp, true);
@ -1137,6 +1136,14 @@ static int volume_header(char *file) {
int Yap_volume_header(char *file) { return volume_header(file); }
const char *Yap_getcwd(const char *cwd, size_t cwdlen) {
VFS_t *me = GLOBAL_VFS;
while(me) {
if (me->virtual_cwd) {
strcpy(cwd, me->virtual_cwd);
return cwd;
}
me = me->next;
}
#if _WIN32 || defined(__MINGW32__)
if (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
Yap_WinError("GetCurrentDirectory failed");
@ -1166,7 +1173,7 @@ static Int working_directory(USES_REGS1) {
}
if (t2 == TermEmptyAtom || t2 == TermDot)
return true;
return ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
}
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
@ -1188,11 +1195,21 @@ const char *Yap_findFile(const char *isource, const char *idef,
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
char *save_buffer = NULL;
const char *root = iroot, *source = isource;
char *root = iroot, *source = isource;
int rc = FAIL_RESTORE;
int try
= 0;
int try = 0;
bool abspath = false;
int lvl = push_text_stack();
root = Malloc(YAP_FILENAME_MAX+1);
source= Malloc(YAP_FILENAME_MAX+1);
if (iroot && iroot[0])
strcpy(root, iroot);
else
root[0] = 0;
if (isource && isource[0])
strcpy(source, isource);
else
source[0] = 0;
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
// "try=%d %s %s", try, isource, iroot) ; }
while (rc == FAIL_RESTORE) {
@ -1201,21 +1218,28 @@ const char *Yap_findFile(const char *isource, const char *idef,
// { CACHE_REGS
switch (try ++) {
case 0: // path or file name is given;
root = iroot;
if (idef || isource) {
source = (isource ? isource : idef);
if (!source[0] && idef && idef[0]) {
strcpy(source, idef);
}
if (source) {
if (source[0]) {
abspath = Yap_IsAbsolutePath(source);
}
if (!abspath && !root && ftype == YAP_BOOT_PL) {
if (!abspath && !root[0] && ftype == YAP_BOOT_PL) {
root = YAP_PL_SRCDIR;
}
break;
case 1: // library directory is given in command line
if (in_lib && ftype == YAP_SAVED_STATE) {
root = iroot;
source = (isource ? isource : idef);
if (iroot && iroot[0])
strcpy(root, iroot);
else
root[0] = 0;
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
} else {
done = true;
}
@ -1223,35 +1247,45 @@ const char *Yap_findFile(const char *isource, const char *idef,
case 2: // use environment variable YAPLIBDIR
#if HAVE_GETENV
if (in_lib) {
const char *eroot;
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
root = getenv("YAPLIBDIR");
eroot = getenv("YAPLIBDIR");
} else if (ftype == YAP_BOOT_PL) {
root = getenv("YAPSHAREDIR"
eroot = getenv("YAPSHAREDIR"
"/pl");
if (root == NULL) {
if (eroot == NULL) {
continue;
} else {
save_buffer = getFileNameBuffer();
strncpy(save_buffer, root, YAP_FILENAME_MAX);
strncat(save_buffer, "/pl", YAP_FILENAME_MAX);
strncpy(root, eroot, YAP_FILENAME_MAX);
strncat(root, "/pl", YAP_FILENAME_MAX);
}
}
source = (isource ? isource : idef);
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
} else
#endif
done = true;
break;
case 3: // use compilation variable YAPLIBDIR
if (in_lib) {
source = (isource ? isource : idef);
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
if (ftype == YAP_PL) {
root = YAP_SHAREDIR;
strcpy(root,YAP_SHAREDIR);
} else if (ftype == YAP_BOOT_PL) {
root = malloc(YAP_FILENAME_MAX+1);
strcpy(root, YAP_SHAREDIR);
strcat(root,"/pl");
} else {
root = YAP_LIBDIR;
strcpy(root,YAP_LIBDIR);
}
} else
done = true;
@ -1260,9 +1294,9 @@ const char *Yap_findFile(const char *isource, const char *idef,
case 4: // WIN stuff: registry
#if __WINDOWS
if (in_lib) {
source = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
source = Yap_RegistryGetString(source);
root = NULL;
const char *key = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
strcpy( source, Yap_RegistryGetString(source) );
root[0] = 0;
} else
#endif
done = true;
@ -1280,42 +1314,45 @@ const char *Yap_findFile(const char *isource, const char *idef,
if (pt) {
if (ftype == YAP_BOOT_PL) {
#if __ANDROID__
root = "../../../files/Yap/pl";
strcpy(root, "../../../files/Yap/pl");
#else
root = "../../share/Yap/pl";
#endif
} else {
root = (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
? "../../lib/Yap"
: "../../share/Yap");
: "../../share/Yap"));
}
if (root == iroot) {
if (strcmp(root, iroot)==0) {
done = true;
continue;
}
if (!save_buffer)
save_buffer = getFileNameBuffer();
save_buffer = Malloc(YAP_FILENAME_MAX+1);
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
expand_root, in_lib))
root = save_buffer;
strcpy(root, save_buffer);
else
done = true;
} else {
done = true;
}
source = (isource ? isource : idef);
if (isource && isource[0])
strcpy(source, isource);
else if (idef && idef[0])
strcpy(source, idef);
else
source[0] = 0;
}
break;
case 6: // default, try current directory
if (!isource && ftype == YAP_SAVED_STATE)
source = idef;
root = NULL;
strcpy(source, idef);
root[0] = 0;
break;
default:
if (save_buffer)
freeFileNameBuffer(save_buffer);
return false;
pop_text_stack(lvl);
return NULL;
}
if (done)
@ -1324,12 +1361,11 @@ const char *Yap_findFile(const char *isource, const char *idef,
// "root= %s %s ", root, source) ; }
const char *work = PlExpandVars(source, root, result);
if (save_buffer)
freeFileNameBuffer(save_buffer);
// expand names in case you have
// to add a prefix
if (!access || Yap_Exists(work)) {
work = pop_output_text_stack(lvl,work);
return work; // done
} else if (abspath)
return NULL;

View File

@ -86,7 +86,7 @@ extern int Yap_PlGetWchar(void);
extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(const char*, const char *);
extern int Yap_OpenStream(const char*, const char*);
extern int Yap_FileStream(FILE*, char *, Term, int);
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
@ -162,6 +162,7 @@ extern uint64_t Yap_StartOfWTimes;
extern bool Yap_HandleSIGINT(void);
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS);
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *bufi,
size_t nchars USES_REGS);
#endif

View File

@ -294,8 +294,8 @@ const char* jniStrError(int errnum, char* buf, size_t buflen) {
// char *strerror_r(int errnum, char *buf, size_t n);
return strerror_r(errnum, buf, buflen);
#else
int rc = strerror_r(errnum, buf, buflen);
if (rc != 0) {
char *rc = strerror_r(errnum, buf, buflen);
if (rc != NULL) {
// (POSIX only guarantees a value other than 0. The safest
// way to implement this function is to use C++ and overload on the
// type of strerror_r to accurately distinguish GNU from POSIX.)