From e2a46cf423e88b345af98d999e1800fc9f91d8ec Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 3 Jul 2018 00:08:19 +0100 Subject: [PATCH] droid --- C/c_interface.c | 3 +- C/cdmgr.c | 3 +- C/scanner.c | 2 +- C/stack.c | 2 +- os/assets.c | 2 +- os/chartypes.c | 5 ++- os/fmem.c | 18 ++++++-- os/iopreds.c | 3 +- os/readterm.c | 10 +++-- os/writeterm.c | 2 +- os/yapio.h | 5 ++- .../myddas/pl/myddas_assert_predicates.ypp | 44 +++++++++---------- 12 files changed, 58 insertions(+), 41 deletions(-) diff --git a/C/c_interface.c b/C/c_interface.c index a701e838c..0acfbbeb1 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -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; diff --git a/C/cdmgr.c b/C/cdmgr.c index 79fbeca10..34de06463 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -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--; diff --git a/C/scanner.c b/C/scanner.c index 9555bd7d1..f401e94f5 100755 --- a/C/scanner.c +++ b/C/scanner.c @@ -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; diff --git a/C/stack.c b/C/stack.c index 8269b9beb..b719eaf95 100644 --- a/C/stack.c +++ b/C/stack.c @@ -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) diff --git a/os/assets.c b/os/assets.c index 26a5c6f04..ed1dac028 100644 --- a/os/assets.c +++ b/os/assets.c @@ -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 diff --git a/os/chartypes.c b/os/chartypes.c index a8371c7fc..cab263e7f 100644 --- a/os/chartypes.c +++ b/os/chartypes.c @@ -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) diff --git a/os/fmem.c b/os/fmem.c index 7d99fabe1..b5bed15d1 100644 --- a/os/fmem.c +++ b/os/fmem.c @@ -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); } diff --git a/os/iopreds.c b/os/iopreds.c index 0a860672a..0918e2db0 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -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")) { diff --git a/os/readterm.c b/os/readterm.c index e7e1c67ca..8c199748f 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -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); diff --git a/os/writeterm.c b/os/writeterm.c index 24e92bd67..fe2b279f3 100644 --- a/os/writeterm.c +++ b/os/writeterm.c @@ -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); diff --git a/os/yapio.h b/os/yapio.h index 7fb6d4fbf..2fd961bcc 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -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, diff --git a/packages/myddas/pl/myddas_assert_predicates.ypp b/packages/myddas/pl/myddas_assert_predicates.ypp index c6bbcd625..ac34345f7 100644 --- a/packages/myddas/pl/myddas_assert_predicates.ypp +++ b/packages/myddas/pl/myddas_assert_predicates.ypp @@ -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,