This commit is contained in:
Vitor Santos Costa 2018-07-03 00:08:19 +01:00
parent fd492b5b16
commit e2a46cf423
12 changed files with 58 additions and 41 deletions

View File

@ -2138,8 +2138,7 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
return -1;
} LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, fl);
pop_text_stack(lvl);
Yap_init_consult(consulted, pop_output_text_stack__(lvl,fl));
RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno;

View File

@ -1768,6 +1768,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
disc[2] = Yap_Module_Name(p);
sc[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomDiscontiguous, 3), 3, disc);
sc[1] = MkIntegerTerm(Yap_source_line_no());
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "source %s ", RepAtom(LOCAL_SourceFileName)->StrOfAE);
sc[2] = MkAtomTerm(LOCAL_SourceFileName);
sc[3] = t;
t = Yap_MkApplTerm(Yap_MkFunctor(AtomStyleCheck, 4), 4, sc);
@ -2078,7 +2079,7 @@ void Yap_init_consult(int mode, const char *filenam) {
expand_consult();
}
LOCAL_ConsultSp--;
LOCAL_ConsultSp->f_name = (const unsigned char *)filenam;
LOCAL_ConsultSp->f_name = Yap_LookupAtom(filenam);
LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--;

View File

@ -447,7 +447,7 @@ static void Yap_setCurrentSourceLocation(struct stream_desc *s) {
if (s->status & Pipe_Stream_f)
LOCAL_SourceFileName = AtomPipe;
else if (s->status & InMemory_Stream_f)
LOCAL_SourceFileName = AtomCharsio;
LOCAL_SourceFileName = s->name;
else
LOCAL_SourceFileName = s->name;
LOCAL_SourceFileLineno = s->linecount;

View File

@ -1808,7 +1808,7 @@ void Yap_dump_stack(void) {
yap_error_class_number classno = Yap_errorClass(errnbr);
fprintf(stderr, "%% Error STATUS: %s/%s\n\n", Yap_errorName(errnbr),
Yap_errorName(classno));
Yap_errorClassName(classno));
fprintf(stderr, "%% Execution mode\n");
if (LOCAL_PrologMode & BootMode)

View File

@ -103,7 +103,7 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
if (rc) AAsset_close(am);
st->vfs = NULL;
st->vfs_handle = NULL;
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
return st;
} else if ((fd = AAsset_openFileDescriptor64(am, &sz0, &sz)) >= 0) {
// can use it as read-only file

View File

@ -82,8 +82,9 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
CACHE_REGS
int sno;
int i = push_text_stack();
sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER);
char buf [16];
Atom nat = Yap_LookupAtom(Yap_StrPrefix(s, 16));
sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER, nat, MkAtomTerm(Yap_LookupAtom("eval")));
if (sno < 0)
return FALSE;
if (encp)

View File

@ -131,8 +131,18 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
return true;
}
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
memBufSource src) {
char *Yap_StrPrefix( const char *buf, size_t n) {
char *b = (char*)malloc(n);
strncpy(b, buf, n - 1);
if (strlen(buf) > n - 1)
b[15] = '\0';
return b;
}
int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src, Atom fname,
Term uname) {
CACHE_REGS
int sno;
StreamDesc *st;
@ -153,7 +163,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
f = st->file = fmemopen((void *)buf, nchars, "r");
st->vfs = NULL;
flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
Yap_initStream(sno, f, "memStream", "r", TermNone, encoding, flags, NULL);
Yap_initStream(sno, f, fname, "r", uname, encoding, flags, NULL);
// like any file stream.
Yap_DefaultStreamOps(st);
UNLOCK(st->streamlock);
@ -176,7 +186,7 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
}
buf = pop_output_text_stack(l, buf);
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC);
MEM_BUF_MALLOC, Yap_LookupAtom(Yap_StrPrefix((char *)buf,16)), TermNone);
t = Yap_MkStream(sno);
return Yap_unify(ARG2, t);
}

View File

@ -1289,8 +1289,9 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
return false;
}
buf = pop_output_text_stack(i, buf);
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf,32));
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC);
MEM_BUF_MALLOC, nat, MkAtomTerm(NameOfFunctor(f)));
return Yap_OpenBufWriteStream(PASS_REGS1);
}
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {

View File

@ -837,6 +837,8 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
LOCAL_ErrorMessage = NULL;
fe->old_TR = TR;
LOCAL_Error_TYPE = YAP_NO_ERROR;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " open %s, %d",
CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, inp_stream);
LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name;
LOCAL_eot_before_eof = false;
fe->tpos = StreamPosition(inp_stream);
@ -1394,8 +1396,8 @@ static Int start_mega(USES_REGS1) {
Term rval;
int sno;
encoding_t l = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s)+1, &l,
MEM_BUF_USER);
sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s+1), &l,
MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix(s,16)), TermNone );
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
rval = Yap_read_term(sno, opts, false);
@ -1408,7 +1410,7 @@ static Int start_mega(USES_REGS1) {
int sno;
encoding_t l = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s), &l,
MEM_BUF_USER);
MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
rval = Yap_read_term(sno, opts, false);
Yap_CloseStream(sno);
@ -1530,7 +1532,7 @@ static Int start_mega(USES_REGS1) {
}
char *ss = (char *)s;
encoding_t enc = ENC_ISO_UTF8;
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER);
int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix(ss,16)), TermString);
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
rc = Yap_read_term(sno, Deref(ARG3), 3);
Yap_CloseStream(sno);

View File

@ -93,7 +93,7 @@ static Term readFromBuffer(const char *s, Term opts) {
int sno;
encoding_t enc = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, strlen_utf8((unsigned char *)s),
&enc, MEM_BUF_USER);
&enc, MEM_BUF_USER, Yap_LookupAtom(Yap_StrPrefix((char *)s,16)), TermNone);
rval = Yap_read_term(sno, opts, 3);
Yap_CloseStream(sno);

View File

@ -114,11 +114,14 @@ typedef enum mem_buf_source {
extern char *Yap_MemStreamBuf(int sno);
extern char *Yap_StrPrefix( const char *buf, size_t n) ;
extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp,
bool error_on);
extern int Yap_FormatFloat(Float f, char **s, size_t sz);
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src);
encoding_t *encp, memBufSource src, Atom name,
Term uname);
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_BufferToTerm(const char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Term bindings, size_t sz,

View File

@ -291,45 +291,45 @@ table_attributes( sqlite3, Con, RelationName, TypesList ) :-
table_access_predicate( mysql, Con, Arity, P, LA, M,
( P :- user:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code),
( P :- user:(myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
queries_atom(Code,FinalSQL),
db_my_result_set(Mode),
'$write_or_not'(FinalSQL),
myddas_util_predicates:'$write_or_not'(FinalSQL),
c_db_my_query(FinalSQL,ResultSet,Con,Mode,_),
!,
c_db_my_row(ResultSet,Arity,LA) ))).
table_access_predicate( postgres, Con, Arity, P, LA, _M,
( P :- '$copy_term_nv'(P,[],G,_),
translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL),
db_my_result_set(Mode),
'$write_or_not'(FinalSQL),
( P :- myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(M:G,M:G,Code),
myddas_prolog2sql:queries_atom(Code,FinalSQL),
myddas_postgres:postgres_result_set(Mode),
myddas_util_predicates:'$write_or_not'(FinalSQL),
c_postgres_query(FinalSQL,ResultSet,Con,Mode,_),
!,
c_postgsres_row(ResultSet,Arity,LA) ))).
table_access_predicate( sqlite3, Con, Arity, P, LA, M,
( P :- ('$copy_term_nv'(P,[],G,_),
translate(M:G,M:G,Code),
queries_atom(Code,FinalSQL),
sqlite3_result_set(Mode),
'$write_or_not'(FinalSQL),
c_sqlite3_query(FinalSQL,ResultSet,Con,Mode,_),
( P :- (myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
myddas_prolog2sql:queries_atom(Code,FinalSQL),
myddas_sqlite3:sqlite3_result_set(Mode),
myddas_util_predicates:'$write_or_not'(FinalSQL),
user:c_sqlite3_query(FinalSQL,ResultSet,Con,Mode,_),
!,
sqlite3_row(ResultSet,Arity,LA)
myddas_aqlite3:sqlite3_row(ResultSet,Arity,LA)
) )).
table_access_predicate( odbc, Con, Arity, P, LA, M,
( P :- M:('$copy_term_nv'(P,[],G,_),
translate(G,G,Code),
queries_atom(Code,FinalSQL),
c_odbc_result_set(Mode),
'$write_or_not'(FinalSQL),
c_odbc_query(FinalSQL,ResultSet,Con,Mode,_),
( P :- M:(myddas_util_predicates:'$copy_term_nv'(P,[],G,_),
myddas_prolog2sql:translate(G,G,Code),
myddas_prolog2sql:queries_atom(Code,FinalSQL),
myddas_odbc:odbc_result_set(Mode),
'myddas_util_predicates:$write_or_not'(FinalSQL),
myddas_odbc:c_odbc_query(FinalSQL,ResultSet,Con,Mode,_),
!,
c_odbc_row(ResultSet,Arity,LA)
myddas_odbc:c_odbc_row(ResultSet,Arity,LA)
) )).
table_insert( mysql, Con, RelationName, TypesList, Predicate, LA,