changes to support eclipse compat
support of Android assets as /assets files.
This commit is contained in:
@@ -2288,12 +2288,14 @@ YAP_EnterGoal(PredEntry *pe, Term *ptr, YAP_dogoalinfo *dgi)
|
||||
CACHE_REGS
|
||||
int out;
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "yapi.cpp", "got %p pred %p slot %d", LOCAL, pe, dgi->CurSlot);
|
||||
BACKUP_MACHINE_REGS();
|
||||
LOCAL_PrologMode = UserMode;
|
||||
dgi->p = P;
|
||||
dgi->cp = CP;
|
||||
dgi->CurSlot = LOCAL_CurSlot;
|
||||
// ensure our current ENV receives current P.
|
||||
|
||||
Yap_PrepGoal(pe->ArityOfPE, ptr, B PASS_REGS);
|
||||
P = pe->CodeOfPred;
|
||||
dgi->b = LCL0-(CELL*)B;
|
||||
@@ -2986,6 +2988,7 @@ YAP_Init(YAP_init_args *yap_init)
|
||||
if (initialised)
|
||||
return YAP_BOOT_DONE_BEFOREHAND;
|
||||
initialised = TRUE;
|
||||
__android_log_print(ANDROID_LOG_INFO, "c_interface.c", "entered init %p", yap_init);
|
||||
|
||||
Yap_InitPageSize(); /* init memory page size, required by later functions */
|
||||
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
|
||||
|
24
C/grow.c
24
C/grow.c
@@ -1419,13 +1419,18 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
|
||||
int res;
|
||||
int blob_overflow = (NOfBlobs > NOfBlobsMax);
|
||||
|
||||
#if (THREADS) || YAPOR
|
||||
res = FALSE;
|
||||
if (NOfAtoms > 2*AtomHashTableSize || blob_overflow) {
|
||||
Yap_undo_signal( YAP_CDOVF_SIGNAL );
|
||||
return TRUE;
|
||||
LOCK(GLOBAL_ThreadHandlesLock);
|
||||
// make sure that we cannot have more than a thread life
|
||||
if (Yap_NOfThreads() > 1) {
|
||||
UNLOCK(GLOBAL_ThreadHandlesLock);
|
||||
res = FALSE;
|
||||
if (NOfAtoms > 2*AtomHashTableSize || blob_overflow) {
|
||||
Yap_undo_signal( YAP_CDOVF_SIGNAL );
|
||||
UNLOCK(LOCAL_SignalLock);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// don't release the MTHREAD lock in case we're running from the C-interface.
|
||||
if (NOfAtoms > 2*AtomHashTableSize || blob_overflow) {
|
||||
UInt n = NOfAtoms;
|
||||
if (GLOBAL_AGcThreshold)
|
||||
@@ -1438,11 +1443,14 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
|
||||
res = growatomtable( PASS_REGS1 );
|
||||
} else {
|
||||
Yap_undo_signal( YAP_CDOVF_SIGNAL );
|
||||
UNLOCK(GLOBAL_ThreadHandlesLock);
|
||||
return TRUE;
|
||||
}
|
||||
LeaveGrowMode(GrowHeapMode);
|
||||
if (res)
|
||||
if (res) {
|
||||
UNLOCK(GLOBAL_ThreadHandlesLock);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
#if USE_SYSTEM_MALLOC
|
||||
P = Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"malloc failed");
|
||||
@@ -1451,7 +1459,7 @@ Yap_locked_growheap(int fix_code, size_t in_size, void *cip)
|
||||
res=do_growheap(fix_code, in_size, (struct intermediates *)cip, NULL, NULL, NULL PASS_REGS);
|
||||
#endif
|
||||
LeaveGrowMode(GrowHeapMode);
|
||||
#endif
|
||||
UNLOCK(GLOBAL_ThreadHandlesLock);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
17
C/heapgc.c
17
C/heapgc.c
@@ -169,11 +169,13 @@ PUSH_POINTER(CELL *v USES_REGS) {
|
||||
*LOCAL_iptop++ = v;
|
||||
}
|
||||
|
||||
#ifdef EASY_SHUNTING
|
||||
inline static void
|
||||
POP_POINTER( USES_REGS1 ) {
|
||||
if (LOCAL_iptop >= (CELL_PTR *)ASP) return;
|
||||
--LOCAL_iptop;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline static void
|
||||
POPSWAP_POINTER(CELL_PTR *vp, CELL_PTR v USES_REGS) {
|
||||
@@ -1524,21 +1526,6 @@ mark_external_reference(CELL *ptr USES_REGS) {
|
||||
}
|
||||
}
|
||||
|
||||
static void inline
|
||||
mark_external_reference2(CELL *ptr USES_REGS) {
|
||||
CELL *next = GET_NEXT(*ptr);
|
||||
|
||||
if (ONHEAP(next)) {
|
||||
#ifdef HYBRID_SCHEME
|
||||
CELL_PTR *old = LOCAL_iptop;
|
||||
#endif
|
||||
mark_variable(ptr PASS_REGS);
|
||||
POPSWAP_POINTER(old, ptr PASS_REGS);
|
||||
} else {
|
||||
mark_code(ptr,next PASS_REGS);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* mark all heap objects accessible from the trail (which includes the active
|
||||
* general purpose registers)
|
||||
|
@@ -484,7 +484,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
||||
{
|
||||
CACHE_REGS
|
||||
TokEntry *tokstart;
|
||||
Term t, v;
|
||||
Term t;
|
||||
Term OCurrentModule = CurrentModule, tmod, tpos;
|
||||
int store_comments = rd->comments;
|
||||
|
||||
@@ -614,6 +614,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
||||
if (store_comments && !Yap_unify(LOCAL_Comments, Yap_GetFromSlot( rd->comments PASS_REGS)))
|
||||
return FALSE;
|
||||
if (rd->varnames) {
|
||||
Term v;
|
||||
while (TRUE) {
|
||||
CELL *old_H = HR;
|
||||
|
||||
@@ -638,6 +639,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
||||
}
|
||||
|
||||
if (rd->variables) {
|
||||
Term v;
|
||||
while (TRUE) {
|
||||
CELL *old_H = HR;
|
||||
|
||||
@@ -661,6 +663,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
||||
return FALSE;
|
||||
}
|
||||
if (rd->singles) {
|
||||
Term v;
|
||||
while (TRUE) {
|
||||
CELL *old_H = HR;
|
||||
|
||||
|
1
C/qlyr.c
1
C/qlyr.c
@@ -1082,6 +1082,7 @@ Yap_Restore(char *s, char *lib_dir)
|
||||
IOSTREAM *stream = Yap_OpenRestore(s, lib_dir);
|
||||
if (!stream)
|
||||
return -1;
|
||||
__android_log_print(ANDROID_LOG_INFO, "qlyr.c", "loading startup %p", stream);
|
||||
GLOBAL_RestoreFile = s;
|
||||
read_module(stream);
|
||||
Sclose( stream );
|
||||
|
31
C/save.c
31
C/save.c
@@ -247,6 +247,22 @@ open_file(char *my_file, int flag)
|
||||
{
|
||||
int splfild;
|
||||
|
||||
#if __ANDROID__
|
||||
if (strstr(my_file, "/assets/") == my_file) {
|
||||
if (flag == O_RDONLY) {
|
||||
extern AAssetManager *assetManager;
|
||||
my_file += strlen("/assets/");
|
||||
__android_log_print(ANDROID_LOG_ERROR, "save.c", "open_file %p %s", assetManager, my_file);
|
||||
AAsset* asset = AAssetManager_open(assetManager, my_file, AASSET_MODE_UNKNOWN);
|
||||
if (!asset)
|
||||
return -1;
|
||||
__android_log_print(ANDROID_LOG_ERROR, "save.c", "open_file %p", asset);
|
||||
AAsset_close( asset );
|
||||
return 0; // usually the file will be compressed, so there is no point in actually trying to open it.
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#ifdef M_WILLIAMS
|
||||
if (flag & O_CREAT)
|
||||
splfild = creat(my_file, flag);
|
||||
@@ -1453,6 +1469,11 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
int mode = FAIL_RESTORE;
|
||||
char save_buffer[YAP_FILENAME_MAX+1];
|
||||
|
||||
#if __ANDROID__
|
||||
if (!inpf)
|
||||
inpf = YAPSTARTUP;
|
||||
#endif
|
||||
__android_log_print(ANDROID_LOG_ERROR, "save.c", "saved state %s", inpf);
|
||||
save_buffer[0] = '\0';
|
||||
// LOCAL_ErrorMessage = NULL;
|
||||
if (inpf == NULL) {
|
||||
@@ -1473,10 +1494,13 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
strncat(LOCAL_FileNameBuf, "/", YAP_FILENAME_MAX-1);
|
||||
strncat(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||
} else {
|
||||
strncat(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX-1);
|
||||
}
|
||||
if (inpf != NULL && !((splfild = open_file(inpf, O_RDONLY)) < 0)) {
|
||||
if (inpf != NULL &&
|
||||
!((splfild = open_file(inpf, O_RDONLY)) < 0))
|
||||
{
|
||||
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "save.c", "saved state %p", *streamp);
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
@@ -1517,7 +1541,7 @@ OpenRestore(char *inpf, char *YapLibDir, CELL *Astate, CELL *ATrail, CELL *AStac
|
||||
}
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
if ((inpf = Yap_RegistryGetString("startup"))) {
|
||||
if (!((splfild = open_file(inpf, O_RDONLY)) < 0)) {
|
||||
if (!((splfild = Sopen_file(inpf, "r")) < 0)) {
|
||||
if ((mode = try_open(inpf,Astate,ATrail,AStack,AHeap,save_buffer,streamp)) != FAIL_RESTORE) {
|
||||
return mode;
|
||||
}
|
||||
@@ -1582,6 +1606,7 @@ Yap_OpenRestore(char *inpf, char *YapLibDir)
|
||||
IOSTREAM *stream = NULL;
|
||||
|
||||
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
||||
__android_log_print(ANDROID_LOG_ERROR, "save.c", "saved state %p", stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
17
C/threads.c
17
C/threads.c
@@ -90,6 +90,12 @@ Yap_ThreadID( void )
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Yap_NOfThreads(void) {
|
||||
// GLOBAL_ThreadHandlesLock is held
|
||||
return GLOBAL_NOfThreads;
|
||||
}
|
||||
|
||||
static int
|
||||
allocate_new_tid(void)
|
||||
{
|
||||
@@ -1090,6 +1096,17 @@ void Yap_InitThreadPreds(void)
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
Yap_NOfThreads(void) {
|
||||
// GLOBAL_ThreadHandlesLock is held
|
||||
#ifdef YAPOR
|
||||
return 2;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static Int
|
||||
p_no_threads(void)
|
||||
{ /* '$thread_signal'(+P) */
|
||||
|
@@ -1618,6 +1618,40 @@ p_term_variables( USES_REGS1 ) /* variables in term t */
|
||||
return Yap_unify(ARG2,out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports a nil-terminated list with all the variables in a term.
|
||||
* @param[in] the term
|
||||
* @param[in] the arity of the calling predicate (required for exact garbage collection).
|
||||
*/
|
||||
Term
|
||||
Yap_TermVariables( Term t, UInt arity USES_REGS ) /* variables in term t */
|
||||
{
|
||||
Term out;
|
||||
|
||||
do {
|
||||
t = Deref(t);
|
||||
if (IsVarTerm(t)) {
|
||||
return MkPairTerm(t, TermNil);
|
||||
} else if (IsPrimitiveTerm(t)) {
|
||||
return TermNil;
|
||||
} else if (IsPairTerm(t)) {
|
||||
out = vars_in_complex_term(RepPair(t)-1,
|
||||
RepPair(t)+1, TermNil PASS_REGS);
|
||||
}
|
||||
else {
|
||||
Functor f = FunctorOfTerm(t);
|
||||
out = vars_in_complex_term(RepAppl(t),
|
||||
RepAppl(t)+
|
||||
ArityOfFunctor(f), TermNil PASS_REGS);
|
||||
}
|
||||
if (out == 0L) {
|
||||
if (!expand_vts( arity PASS_REGS ))
|
||||
return FALSE;
|
||||
}
|
||||
} while (out == 0L);
|
||||
return out;
|
||||
}
|
||||
|
||||
static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end, Term inp USES_REGS)
|
||||
{
|
||||
|
||||
|
Reference in New Issue
Block a user