android debugging plus clean-ups

This commit is contained in:
Vítor Santos Costa
2015-04-13 13:28:17 +01:00
parent d1a230eb56
commit ef586e264e
77 changed files with 2346 additions and 4054 deletions

View File

@@ -126,7 +126,7 @@ typedef struct PropEntryStruct
typedef CELL arity_t;
#define FunctorProperty ((PropFlags)(0xbb00))
#define FunctorProperty ((PropFlags)(0xbb00))
/* functor property */
typedef struct FunctorEntryStruct

View File

@@ -81,7 +81,7 @@ INLINE_ONLY inline EXTERN void save_B(void);
#define CACHE_REGS
#define REFRESH_CACHE_REGS
#define INIT_REGS
#define PASS_REGS1
#define PASS_REGS1
#define PASS_REGS
#define USES_REGS1 void
#define USES_REGS
@@ -223,7 +223,7 @@ extern REGSTORE Yap_REGS;
#define YENV2MEM
#define YENV_ADDRESS (&(YENV))
#define MEM2YENV
#define MEM2YENV
#if defined(__GNUC__) && defined(__alpha)
@@ -391,7 +391,7 @@ INLINE_ONLY EXTERN inline void restore_B(void) {
#define RECOVER_B() save_B(); B = BK_B
#define restore_TR()
#define restore_TR()
#elif defined(__GNUC__) && defined(hppa)
@@ -478,7 +478,7 @@ INLINE_ONLY EXTERN inline void restore_TR(void) {
#elif defined(__GNUC__) && (defined(_POWER) || defined(__POWERPC__))
/*
/*
Because of a bug in GCC, we should always start from the first available
general register. According to rs6000.h, this is r13 everywhere
@@ -490,7 +490,7 @@ INLINE_ONLY EXTERN inline void restore_TR(void) {
*/
#define CreepFlag Yap_REGS.CreepFlag_
/*
/*
vsc: this MUST start from register 13, otherwise GCC will break down in flames and
use the registers for evil purposes. :-(
*/
@@ -509,7 +509,7 @@ register CELL *YENV asm ("r19");
#undef YENV2MEM
#undef YENV_ADDRESS (&(YENV))
#undef MEM2YENV
#undef MEM2YENV
#define YENV2MEM { CELL *YENV_MEM = YENV
#define YENV_ADDRESS (&YENV_MEM)
@@ -628,7 +628,7 @@ INLINE_ONLY EXTERN inline void restore_B(void) {
#define RECOVER_B()
#define restore_TR()
#define restore_TR()
#endif
@@ -745,8 +745,8 @@ StackGap( USES_REGS1 )
{
UInt gmin = (LCL0-H0)>>2;
if (gmin < MinStackGap) gmin = MinStackGap;
// if (gmin > 1024*1024) return 1024*1024;
if (gmin < MinStackGap) gmin = MinStackGap;
// if (gmin > 1024*1024) return 1024*1024;
return gmin;
}

49
H/Yap.h
View File

@@ -1,4 +1,4 @@
/*************************************************************************
/*************************************************************************
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
@@ -505,16 +505,19 @@ extern int Yap_output_msg;
#if __ANDROID__
#include <jni.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <android/log.h>
#else
static inline char * __android_log_print(int i,const char *loc,const char *msg,...) {
return NULL;
}
#define ANDROID_LOG_INFO 0
#define ANDROID_LOG_ERROR 0
#define ANDROID_LOG_DEBUG 0
extern AAssetManager * Yap_assetManager;
extern void *Yap_openAssetFile( const char *path ) ;
extern bool Yap_isAsset( const char *path );
extern bool Yap_AccessAsset( const char *name , int mode);
extern bool Yap_AssetIsFile( const char *name );
extern bool Yap_AssetIsDir( const char *name );
extern int64_t Yap_AssetSize( const char *name );
#endif
@@ -858,4 +861,34 @@ Global variables for JIT
#endif
#endif
#if DEBUGX
inline static void
LOG0(const char *f, int l, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
#if __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "YAP ", fmt, ap);
#else __WINDOWS__
FILE * fd;
fd = fopen("c:\\cygwin\\Log.txt", "a");
vfprintf(fd, fmt, ap);
fclose(fd);
#endif
vfprintf(stderr, fmt, ap);
va_end(ap);
}
#else
#define LOG0( ... )
#endif
#ifndef __ANDROID__
#define __android_log_print( ... )
#endif
#define LOG( ... ) LOG0( __FILE__, __LINE__, __VA_ARGS__ )
#define REGS_LOG( ... ) CACHE_REGS LOG0( __FILE__, __LINE__, __VA_ARGS__ )
#endif /* YAP_H */

View File

@@ -30,10 +30,10 @@ of a function. Hence, slots should always be used as local variables.
Slots are organized as follows:
---- Offset of next pointer in chain (tagged as an handle_t)
---- Number of entries (tagged as handle_t), in the example TAG(INT,4)
Entry
Entry
Entry
Entry
Entry
Entry
Entry
Entry
---- Number of entries (tagged as handle_t), in the example TAG(INT,4)
Slots are not known to the yaam. Instead, A new set of slots is created when the emulator calls user C-code.
@@ -54,8 +54,8 @@ Slots are not known to the yaam. Instead, A new set of slots is created when the
static inline void
Yap_RebootSlots__( int wid USES_REGS ) {
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
REMOTE_CurSlot(wid) = 1;
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
REMOTE_CurSlot(wid) = 1;
}
@@ -65,7 +65,7 @@ Yap_RebootSlots__( int wid USES_REGS ) {
static inline yhandle_t
Yap_StartSlots__( USES_REGS1 ) {
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
// fprintf( stderr, " StartSlots = %ld", LOCAL_CurSlot);
if (LOCAL_CurSlot < 0) {
Yap_Error( SYSTEM_ERROR, 0L, " StartSlots = %ld", LOCAL_CurSlot);
}
@@ -87,9 +87,10 @@ Yap_CurrentSlot( USES_REGS1 ) {
return LOCAL_CurSlot;
}
#define Yap_GetFromSlot(slot) Yap_GetFromSlot__(slot PASS_REGS)
/// @brief read from a slot.
static inline Term
Yap_GetFromSlot(yhandle_t slot USES_REGS)
Yap_GetFromSlot__(yhandle_t slot USES_REGS)
{
return(Deref(LOCAL_SlotBase[slot]));
}
@@ -142,21 +143,25 @@ ensure_slots(int N USES_REGS)
}
}
#define Yap_InitSlot( t ) Yap_InitSlot__( t PASS_REGS )
/// @brief create a new slot with term t
static inline Int
Yap_InitSlot(Term t USES_REGS)
static inline yhandle_t
Yap_InitSlot__(Term t USES_REGS)
{
yhandle_t old_slots = LOCAL_CurSlot;
ensure_slots( 1 PASS_REGS);
LOCAL_SlotBase[old_slots] = t;
LOCAL_CurSlot++;
return old_slots;
}
#define Yap_NewSlots( n ) Yap_NewSlots__( n PASS_REGS )
/// @brief allocate n empty new slots
static inline yhandle_t
Yap_NewSlots(int n USES_REGS)
Yap_NewSlots__(int n USES_REGS)
{
yhandle_t old_slots = LOCAL_CurSlot;
int i;
@@ -169,7 +174,7 @@ Yap_NewSlots(int n USES_REGS)
return old_slots;
}
#define Yap_InitSlots(n, ts) Yap_InitSlots__(n, ts PASS_REGS)
#define Yap_InitSlots(n, ts) Yap_InitSlots__(n, ts PASS_REGS)
/// @brief create n new slots with terms ts[]
static inline yhandle_t
@@ -177,7 +182,7 @@ Yap_InitSlots__(int n, Term *ts USES_REGS)
{
yhandle_t old_slots = LOCAL_CurSlot;
int i;
ensure_slots( n PASS_REGS);
for (i=0; i< n; i++)
LOCAL_SlotBase[old_slots+i] = ts[i];
@@ -193,7 +198,7 @@ Yap_RecoverSlots(int n, yhandle_t topSlot USES_REGS)
return false;
#ifdef DEBUG
if (topSlot + n > LOCAL_CurSlot) {
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "Inconsistent slot state in Yap_RecoverSlots.");
Yap_Error(SYSTEM_ERROR, 0 /* TermNil */, "Inconsistent slot state in Yap_RecoverSlots.");
return false;
}
#endif

View File

@@ -371,7 +371,13 @@ int Yap_signal_index(const char *);
#ifdef MAC
void Yap_SetTextFile(char *);
#endif
char *Yap_getcwd(const char *, size_t);
#if __ANDROIDD__
extern AAssetManager * Yap_assetManager;
extern void *Yap_openAssetFile( const char *path ) ;
extern bool Yap_isAsset( const char *path );
#endif
const char *Yap_getcwd(const char *, size_t);
void Yap_cputime_interval(Int *,Int *);
void Yap_systime_interval(Int *,Int *);
void Yap_walltime_interval(Int *,Int *);
@@ -452,7 +458,7 @@ struct AtomEntryStruct *Yap_lookupBlob(void *blob, size_t len, void *type, int *
void Yap_init_optyap_preds(void);
/* pl-file.c */
struct PL_local_data *Yap_InitThreadIO(int wid);
struct PL_local_data *Yap_InitThreadIO(int wid);
void Yap_flush(void);
/* pl-yap.c */
@@ -465,5 +471,3 @@ gc_P(yamop *p, yamop *cp)
{
return (p->opc == Yap_opcode(_execute_cpred) ? cp : p);
}

View File

@@ -188,7 +188,7 @@ IsFunctorProperty (int flags)
00 00 predicate entry
80 00 db property
bb 00 functor entry
bb 00 functor entry
ff df sparse functor
ff ex arithmetic property
ff f4 translation
@@ -404,7 +404,7 @@ AbsModProp (ModEntry * p)
}
#define ModToTerm(m) (m == PROLOG_MODULE ? TermProlog : m )
#endif
#define ModProperty ((PropFlags)0xfffa)
@@ -638,8 +638,8 @@ IsValProperty (int flags)
return (PropFlags) ((flags == ValProperty));
}
typedef uint64_t pred_flags_t;
typedef uint64_t pred_flags_t;
/* predicate property entry structure */
/* AsmPreds are things like var, nonvar, atom ...which are implemented
@@ -749,12 +749,12 @@ typedef enum {
#endif
Term ModuleOfPred; /* module for this definition */
UInt TimeStampOfPred;
timestamp_type LastCallOfPred;
timestamp_type LastCallOfPred;
/* This must be at an odd number of cells, otherwise it
will not be aligned on RISC machines */
profile_data StatisticsForPred; /* enable profiling for predicate */
struct pred_entry *NextPredOfModule; /* next pred for same module */
} PredEntry;
} PredEntry;
#define PEProp ((PropFlags)(0x0000))
#if USE_OFFSETS_IN_PROPS
@@ -1269,7 +1269,7 @@ Yap_GetTranslationProp(Atom at)
if (p0 == NIL) return (TranslationEntry *)NULL;
return p;
}
INLINE_ONLY inline EXTERN PropFlags IsTranslationProperty (int);
INLINE_ONLY inline EXTERN PropFlags
@@ -1361,7 +1361,7 @@ IsTranslationProperty (int flags)
}
/* end of code for named mutexes */
typedef enum {
STATIC_ARRAY = 1,
DYNAMIC_ARRAY = 2,
@@ -1708,7 +1708,7 @@ GetPredPropByFuncHavingLock (FunctorEntry *fe, Term cur_mod)
UInt hash = PRED_HASH(fe,cur_mod,PredHashTableSize);
READ_LOCK(PredHashRWLock);
p = PredHash[hash];
while (p) {
if (p->FunctorOfPred == fe &&
p->ModuleOfPred == cur_mod)
@@ -1766,7 +1766,7 @@ GetPredPropByFuncAndModHavingLock (FunctorEntry *fe, Term cur_mod)
UInt hash = PRED_HASH(fe,cur_mod,PredHashTableSize);
READ_LOCK(PredHashRWLock);
p = PredHash[hash];
while (p) {
if (p->FunctorOfPred == fe &&
p->ModuleOfPred == cur_mod)
@@ -1883,11 +1883,11 @@ INLINE_ONLY EXTERN inline void AddPropToAtom(AtomEntry *, PropEntry *p);
INLINE_ONLY EXTERN inline void
AddPropToAtom(AtomEntry *ae, PropEntry *p)
{
/* old properties should be always last, and wide atom properties
/* old properties should be always last, and wide atom properties
should always be first */
if (ae->PropsOfAE != NIL &&
RepProp(ae->PropsOfAE)->KindOfPE == WideAtomProperty) {
PropEntry *pp = RepProp(ae->PropsOfAE);
PropEntry *pp = RepProp(ae->PropsOfAE);
p->NextOfPE = pp->NextOfPE;
pp->NextOfPE = AbsProp(p);
} else {
@@ -1898,4 +1898,3 @@ AddPropToAtom(AtomEntry *ae, PropEntry *p)
#endif

View File

@@ -1089,8 +1089,6 @@ extern void **Yap_ABSMI_OPCODES;
#endif
#if DEPTH_LIMIT
/*
Make this into an even number so that the system will know

View File

@@ -1,4 +1,4 @@
/*************************************************************************
/*************************************************************************
* *
* YAP Prolog *
* *
@@ -25,4 +25,3 @@ typedef struct array_access_struct {
Term indx; /* index in array, for now
keep it as an integer! */
} array_access;

View File

@@ -201,7 +201,7 @@ INLINE_ONLY EXTERN inline CELL *EXO_OFFSET_TO_ADDRESS(struct index_t *it, BITS3
INLINE_ONLY EXTERN inline CELL *
EXO_OFFSET_TO_ADDRESS(struct index_t *it, BITS32 off)
{
if (off == 0L)
if (off == 0L)
return (CELL *)NULL;
return (it->cls)+(off-1)*it->arity;
}
@@ -258,8 +258,8 @@ typedef struct dbterm_list {
#define CL_IN_USE(X) ((X)->ClRefCount)
#else
#define INIT_CLREF_COUNT(X)
#define INC_CLREF_COUNT(X)
#define DEC_CLREF_COUNT(X)
#define INC_CLREF_COUNT(X)
#define DEC_CLREF_COUNT(X)
#define CL_IN_USE(X) ((X)->ClFlags & InUseMask || (X)->ClRefCount)
#endif
@@ -301,6 +301,7 @@ LogUpdClause *Yap_FollowIndexingCode(PredEntry *,yamop *, Term *, yamop *,yamop
yamop *Yap_ExoLookup(PredEntry *ap USES_REGS);
CELL Yap_NextExo(choiceptr cpt, struct index_t *it);
#
#if USE_THREADED_CODE
#define OP_HASH_SIZE 2048
@@ -359,7 +360,7 @@ same_lu_block(yamop **paddr, yamop *p)
#define Yap_MkStaticRefTerm(cp, ap) __Yap_MkStaticRefTerm((cp), (ap) PASS_REGS)
static inline Term
static inline Term
__Yap_MkStaticRefTerm(StaticClause *cp, PredEntry *ap USES_REGS)
{
Term t[2];
@@ -376,7 +377,7 @@ Yap_ClauseFromTerm(Term t)
#define Yap_MkMegaRefTerm(ap, ipc) __Yap_MkMegaRefTerm((ap), (ipc) PASS_REGS)
static inline Term
static inline Term
__Yap_MkMegaRefTerm(PredEntry *ap,yamop *ipc USES_REGS)
{
Term t[2];
@@ -385,13 +386,13 @@ __Yap_MkMegaRefTerm(PredEntry *ap,yamop *ipc USES_REGS)
return Yap_MkApplTerm(FunctorMegaClause,2,t);
}
static inline yamop *
static inline yamop *
Yap_MegaClauseFromTerm(Term t)
{
return (yamop *)IntegerOfTerm(ArgOfTerm(2,t));
}
static inline PredEntry *
static inline PredEntry *
Yap_MegaClausePredicateFromTerm(Term t)
{
return (PredEntry *)IntegerOfTerm(ArgOfTerm(1,t));
@@ -399,7 +400,7 @@ Yap_MegaClausePredicateFromTerm(Term t)
#define Yap_MkExoRefTerm(ap, i) __Yap_MkExoRefTerm((ap), (i) PASS_REGS)
static inline Term
static inline Term
__Yap_MkExoRefTerm(PredEntry *ap,Int i USES_REGS)
{
Term t[2];
@@ -408,13 +409,13 @@ __Yap_MkExoRefTerm(PredEntry *ap,Int i USES_REGS)
return Yap_MkApplTerm(FunctorExoClause,2,t);
}
static inline Int
static inline Int
Yap_ExoClauseFromTerm(Term t)
{
return IntegerOfTerm(ArgOfTerm(2,t));
}
static inline PredEntry *
static inline PredEntry *
Yap_ExoClausePredicateFromTerm(Term t)
{
return (PredEntry *)IntegerOfTerm(ArgOfTerm(1,t));

View File

@@ -38,6 +38,7 @@
#if __ANDROID__
#define GLOBAL_assetManager Yap_global->assetManager_
#define GLOBAL_AssetsWD Yap_global->AssetsWD_
#endif
#if THREADS

View File

@@ -38,6 +38,7 @@ typedef struct global_data {
#if __ANDROID__
struct AAssetManager* assetManager_;
char* AssetsWD_;
#endif
#if THREADS

View File

@@ -37,7 +37,8 @@ static void InitGlobal(void) {
GLOBAL_AGCHook = NULL;
#if __ANDROID__
GLOBAL_assetManager = GLOBAL_assetManager;
GLOBAL_assetManager = NULL;
GLOBAL_AssetsWD = NULL;
#endif
#if THREADS

View File

@@ -26,21 +26,21 @@ EXTEND_SEQ_CHARS(Word ptr, int c) {
return ptr+2;
}
static inline int
static inline int
CLOSE_SEQ_STRING(Word p, Word p0, term_t tail, term_t term, term_t l) {
CACHE_REGS
Yap_PutInSlot(l, AbsPair(p0) PASS_REGS);
p--;
if (tail) {
RESET_VARIABLE(p);
if (Yap_unify(Yap_GetFromSlot(l PASS_REGS), Yap_GetFromSlot(term PASS_REGS))) {
if (Yap_unify(Yap_GetFromSlot(l), Yap_GetFromSlot(term))) {
Yap_PutInSlot(tail, (CELL)(p) PASS_REGS);
return TRUE;
}
return FALSE;
} else {
p[0] = TermNil;
return Yap_unify(Yap_GetFromSlot(l PASS_REGS), Yap_GetFromSlot(term PASS_REGS));
return Yap_unify(Yap_GetFromSlot(l), Yap_GetFromSlot(term ));
}
}

View File

@@ -188,6 +188,7 @@ typedef struct {
int optimise; /* -O: optimised compilation */
} cmdline;
#if 0
struct
{ //char * CWDdir;
//size_t CWDlen;
@@ -196,6 +197,7 @@ typedef struct {
char * module; /* argv[0] module passed */
#endif
} paths;
#endif
struct
{ ExtensionCell _ext_head; /* head of registered extensions */
@@ -251,7 +253,7 @@ typedef struct {
/* Procedure dc_call_prolog0; /\* $c_call_prolog/0 *\/ */
/* #ifdef O_ATTVAR */
/* Procedure dwakeup1; /\* system:$wakeup/1 *\/ */
predicate_t portray_attvar1; /* $attvar:portray_attvar/1 */
predicate_t portray_attvar1; /* $attvar:portray_attvar/1 */
/* #endif */
/* #ifdef O_CALL_RESIDUE */
/* Procedure call_residue_vars2; /\* $attvar:call_residue_vars/2 *\/ */
@@ -390,7 +392,7 @@ typedef struct PL_local_data {
#ifdef O_GMP
struct
{
{
int persistent; /* do persistent operations */
} gmp;
#endif
@@ -411,4 +413,3 @@ typedef struct PL_local_data {
extern PL_local_data_t lds;
#endif

View File

@@ -141,7 +141,7 @@ typedef int Char; /* char that can pass EOF */
typedef enum
{ V_INTEGER, /* integer (64-bit) value */
#ifdef O_GMP
#ifdef O_GMP
V_MPZ, /* mpz_t */
V_MPQ, /* mpq_t */
#endif
@@ -226,7 +226,7 @@ typedef enum
#endif
typedef Term PL_atomic_t; /* same size as a word */
typedef struct record * Record;
typedef struct record * Record;
#define MAXSIGNAL 64
@@ -242,7 +242,7 @@ users foreign language code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define NOTRACE PL_FA_NOTRACE
#define META PL_FA_TRANSPARENT
#define METAP PL_FA_TRANSPARENT
#define NDET PL_FA_NONDETERMINISTIC
#define VA PL_FA_VARARGS
#define CREF PL_FA_CREF
@@ -491,7 +491,7 @@ typedef struct wakeup_state
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Defining built-in predicates using the new interface
Defining built-in predicates using the new interface
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#define ESC ((char) 27)
@@ -698,19 +698,19 @@ extern int System(char *cmd);
extern char *expandVars(const char *pattern, char *expanded, int maxlen);
PL_EXPORT(bool) ChDir(const char *X);
#if _WIN32 || defined(__MINGW32__)
PL_EXPORT(char *) BaseName(const char *X);
PL_EXPORT(char *) DirName(const char *f);
PL_EXPORT(char *) DirName(const char *f);
#else
#define BaseName basename
#define BaseName basename
#define DirName dirname
#endif
PL_EXPORT(char *) OsPath(const char *X, char *Y);
#define DeleteTemporaryFile(F) RemoveFile(stringAtom(F))
PL_EXPORT(intptr_t) lengthList(term_t list, int errors);

View File

@@ -75,16 +75,16 @@ COMMON(word) pl_writeq(term_t term);
static inline int
get_procedure(term_t descr, predicate_t *proc, term_t he, int f) {
CACHE_REGS
Term t = Yap_GetFromSlot(descr PASS_REGS);
Term t = Yap_GetFromSlot(descr );
if (IsVarTerm(t)) return FALSE;
if (IsAtomTerm(t))
if (IsAtomTerm(t))
*proc = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t),CurrentModule));
else if (IsApplTerm(t)) {
Functor f = FunctorOfTerm(t);
if (IsExtensionFunctor(f)) {
return FALSE;
}
}
*proc = RepPredProp(Yap_GetPredPropByFunc(f, CurrentModule));
}
return TRUE;
@@ -125,7 +125,7 @@ void PL_license(const char *license, const char *module);
inline static char *
atomName(Atom atom)
{
if (IsWideAtom(atom))
if (IsWideAtom(atom))
return (char *)(atom->WStrOfAE);
return atom->StrOfAE;
}
@@ -143,7 +143,7 @@ atomName(Atom atom)
Procedure resolveProcedure(functor_t f, Module module);
#define charEscapeWriteOption(A) FALSE // VSC: to implement
#define wordToTermRef(A) Yap_InitSlot(*(A) PASS_REGS)
#define wordToTermRef(A) Yap_InitSlot(*(A))
#define isTaggedInt(A) IsIntegerTerm(A)
#define valInt(A) IntegerOfTerm(A)
@@ -161,7 +161,7 @@ int isWideAtom(atom_t atom);
inline static int
charCode(Term w)
{ if ( IsAtomTerm(w) )
{
{
Atom a = atomValue(w);
if (IsWideAtom(a)) {
@@ -203,7 +203,7 @@ stripostfix(const char *s, const char *e)
return strcasecmp(&s[ls-le], e) == 0;
return FALSE;
}
}
#endif
#if HAVE_SIGPROCMASK

View File

@@ -38,6 +38,7 @@ static void RestoreGlobal(void) {
#if __ANDROID__
#endif
#if THREADS