indenting

This commit is contained in:
Vitor Santos Costa 2016-05-14 11:34:27 +01:00
parent 7b977c2538
commit d375d0ffbb
2 changed files with 113 additions and 108 deletions

View File

@ -2503,7 +2503,8 @@ static Term GetDBTerm(DBTerm *DBSP, int src USES_REGS) {
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
if (HR + NOf > ASP - EventFlag / sizeof(CELL)) { if (HR + NOf > ASP - EventFlag / sizeof(CELL)) {
if (LOCAL_PrologMode & InErrorMode) { if (LOCAL_PrologMode & InErrorMode) {
if (HR + NOf > ASP) LOCAL_PrologMode &= ~InErrorMode;
if (HR + NOf > ASP)
fprintf(stderr, fprintf(stderr,
"\n\n [ FATAL ERROR: No Stack for Error Handling ]\n"); "\n\n [ FATAL ERROR: No Stack for Error Handling ]\n");
Yap_exit(1); Yap_exit(1);
@ -2713,6 +2714,9 @@ static PredEntry *new_lu_entry(Term t) {
pe->PredFlags |= LogUpdatePredFlag; pe->PredFlags |= LogUpdatePredFlag;
if (IsAtomTerm(t)) { if (IsAtomTerm(t)) {
pe->PredFlags |= AtomDBPredFlag; pe->PredFlags |= AtomDBPredFlag;
pe->FunctorOfPred = (Functor)AtomOfTerm(t);
} else {
pe->FunctorOfPred = FunctorOfTerm(t);
} }
pe->ArityOfPE = 3; pe->ArityOfPE = 3;
pe->OpcodeOfPred = Yap_opcode(_op_fail); pe->OpcodeOfPred = Yap_opcode(_op_fail);

View File

@ -35,7 +35,7 @@
#if DEBUG #if DEBUG
void Yap_PrintPredName(PredEntry *ap) { void Yap_PrintPredName(PredEntry *ap) {
CACHE_REGS CACHE_REGS
Term tmod = ap->ModuleOfPred; Term tmod = ap->ModuleOfPred;
if (!tmod) if (!tmod)
tmod = TermProlog; tmod = TermProlog;
#if THREADS #if THREADS
@ -91,7 +91,7 @@ void Yap_PrintPredName(PredEntry *ap) {
bool Yap_Warning(const char *s, ...) { bool Yap_Warning(const char *s, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
PredEntry *pred; PredEntry *pred;
bool rc; bool rc;
Term ts[2]; Term ts[2];
@ -134,8 +134,8 @@ bool Yap_Warning(const char *s, ...) {
bool Yap_PrintWarning(Term twarning) { bool Yap_PrintWarning(Term twarning) {
CACHE_REGS CACHE_REGS
PredEntry *pred = RepPredProp(PredPropByFunc( PredEntry *pred = RepPredProp(PredPropByFunc(
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2; FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
Term cmod = ( CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule ); Term cmod = ( CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule );
bool rc; bool rc;
Term ts[2]; Term ts[2];
@ -149,10 +149,10 @@ bool Yap_PrintWarning(Term twarning) {
LOCAL_within_print_message = true; LOCAL_within_print_message = true;
if (pred->OpcodeOfPred == UNDEF_OPCODE || if (pred->OpcodeOfPred == UNDEF_OPCODE ||
pred->OpcodeOfPred == FAIL_OPCODE pred->OpcodeOfPred == FAIL_OPCODE
) { ) {
fprintf(stderr, "warning message:\n"); fprintf(stderr, "warning message:\n");
Yap_DebugPlWrite(twarning); Yap_DebugPlWrite(twarning);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
LOCAL_within_print_message = false; LOCAL_within_print_message = false;
CurrentModule = cmod; CurrentModule = cmod;
@ -170,7 +170,7 @@ bool Yap_PrintWarning(Term twarning) {
bool Yap_HandleError__(const char *file, const char *function, int lineno, const char *s, ...) { bool Yap_HandleError__(const char *file, const char *function, int lineno, const char *s, ...) {
CACHE_REGS CACHE_REGS
yap_error_number err = LOCAL_Error_TYPE; yap_error_number err = LOCAL_Error_TYPE;
const char *serr; const char *serr;
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
@ -209,7 +209,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno, const
int Yap_SWIHandleError(const char *s, ...) { int Yap_SWIHandleError(const char *s, ...) {
CACHE_REGS CACHE_REGS
yap_error_number err = LOCAL_Error_TYPE; yap_error_number err = LOCAL_Error_TYPE;
char *serr; char *serr;
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
@ -249,36 +249,36 @@ int Yap_SWIHandleError(const char *s, ...) {
void Yap_RestartYap(int flag) { void Yap_RestartYap(int flag) {
CACHE_REGS CACHE_REGS
#if PUSH_REGS #if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs); restore_absmi_regs(&Yap_standard_regs);
#endif #endif
siglongjmp(LOCAL_RestartEnv, 1); siglongjmp(LOCAL_RestartEnv, 1);
} }
static void error_exit_yap(int value) { static void error_exit_yap(int value) {
CACHE_REGS CACHE_REGS
if (!(LOCAL_PrologMode & BootMode)) { if (!(LOCAL_PrologMode & BootMode)) {
#if DEBUG #if DEBUG
#endif #endif
} }
fprintf(stderr, "\n Exiting ....\n"); fprintf(stderr, "\n Exiting ....\n");
#if HAVE_BACKTRACE #if HAVE_BACKTRACE
void *callstack[256]; void *callstack[256];
int i; int i;
int frames = backtrace(callstack, 256); int frames = backtrace(callstack, 256);
char** strs = backtrace_symbols(callstack, frames); char** strs = backtrace_symbols(callstack, frames);
fprintf(stderr, "Execution stack:\n"); fprintf(stderr, "Execution stack:\n");
for (i = 0; i < frames; ++i) { for (i = 0; i < frames; ++i) {
fprintf(stderr, " %s\n", strs[i]); fprintf(stderr, " %s\n", strs[i]);
} }
free(strs); free(strs);
#endif #endif
Yap_exit(value); Yap_exit(value);
} }
/* This needs to be a static because I can't trust the stack (WIN32), and /* This needs to be a static because I can't trust the stack (WIN32), and
I can't trust the Yap stacks (error) */ I can't trust the Yap stacks (error) */
#define YAP_BUF_SIZE 512 #define YAP_BUF_SIZE 512
static char tmpbuf[YAP_BUF_SIZE]; static char tmpbuf[YAP_BUF_SIZE];
@ -299,51 +299,51 @@ static char tmpbuf[YAP_BUF_SIZE];
#undef E2 #undef E2
#undef END_ERRORS #undef END_ERRORS
#define BEGIN_ERROR_CLASSES() \ #define BEGIN_ERROR_CLASSES() \
static Term mkerrorct(yap_error_class_number c, Term *ts) { \ static Term mkerrorct(yap_error_class_number c, Term *ts) { \
switch (c) { switch (c) {
#define ECLASS(CL, A, B) \ #define ECLASS(CL, A, B) \
case CL: \ case CL: \
if (A == 0) \ if (A == 0) \
return MkAtomTerm(Yap_LookupAtom(A)); \ return MkAtomTerm(Yap_LookupAtom(A)); \
else { \ else { \
return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \ return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \
} }
#define END_ERROR_CLASSES() \ #define END_ERROR_CLASSES() \
} \ } \
} }
#define BEGIN_ERRORS() \ #define BEGIN_ERRORS() \
static Term mkerrort(yap_error_number e, Term *ts) { \ static Term mkerrort(yap_error_number e, Term *ts) { \
switch (e) { switch (e) {
#define E0(A, B) \ #define E0(A, B) \
case A: \ case A: \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E(A, B, C) \ #define E(A, B, C) \
case A: \ case A: \
ts -= 1; \ ts -= 1; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E2(A, B, C, D) \ #define E2(A, B, C, D) \
case A: \ case A: \
ts -= 2; \ ts -= 2; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \ ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define END_ERRORS() \ #define END_ERRORS() \
} \ } \
} }
#include "YapErrors.h" #include "YapErrors.h"
/** /**
* @brief Yap_Error * @brief Yap_Error
* This function handles errors in the C code. Check errors.yap for the * This function handles errors in the C code. Check errors.yap for the
*corresponding Prolog code. *corresponding Prolog code.
* *
@ -378,7 +378,7 @@ case A: \
yamop *Yap_Error__(const char *file, const char *function, int lineno, yamop *Yap_Error__(const char *file, const char *function, int lineno,
yap_error_number type, Term where, ...) { yap_error_number type, Term where, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
CELL nt[3]; CELL nt[3];
Functor fun; Functor fun;
bool serious; bool serious;
@ -488,16 +488,16 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
return P; return P;
} }
switch (type) { switch (type) {
case SYSTEM_ERROR_INTERNAL: { case SYSTEM_ERROR_INTERNAL: {
fprintf(stderr, "%% Internal YAP Error: %s exiting....\n", tmpbuf); fprintf(stderr, "%% Internal YAP Error: %s exiting....\n", tmpbuf);
serious = TRUE; serious = TRUE;
if (LOCAL_PrologMode & BootMode) { if (LOCAL_PrologMode & BootMode) {
fprintf(stderr, "%% YAP crashed while booting %s\n", tmpbuf); fprintf(stderr, "%% YAP crashed while booting %s\n", tmpbuf);
} else { } else {
Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE); Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE);
if (tmpbuf[0]) { if (tmpbuf[0]) {
fprintf(stderr, "%% Bug found while executing %s\n", tmpbuf); fprintf(stderr, "%% Bug found while executing %s\n", tmpbuf);
} }
#if HAVE_BACKTRACE #if HAVE_BACKTRACE
void *callstack[256]; void *callstack[256];
int i; int i;
@ -505,7 +505,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
char** strs = backtrace_symbols(callstack, frames); char** strs = backtrace_symbols(callstack, frames);
fprintf(stderr, "Execution stack:\n"); fprintf(stderr, "Execution stack:\n");
for (i = 0; i < frames; ++i) { for (i = 0; i < frames; ++i) {
fprintf(stderr, " %s\n", strs[i]); fprintf(stderr, " %s\n", strs[i]);
} }
free(strs); free(strs);
@ -553,6 +553,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
return (P); return (P);
default: { default: {
LOCAL_PrologMode &= ~InErrorMode;
Term ts[3]; Term ts[3];
ts[2] = where; ts[2] = where;
nt[0] = mkerrort(type, ts + 2); nt[0] = mkerrort(type, ts + 2);
@ -560,7 +561,8 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} }
LOCAL_PrologMode &= ~InErrorMode;
if (type != ABORT_EVENT) { if (type != ABORT_EVENT) {
Term location; Term location;
@ -577,57 +579,56 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} }
nt[1] = TermNil; nt[1] = TermNil;
switch (type) { switch (type) {
case RESOURCE_ERROR_HEAP: case RESOURCE_ERROR_HEAP:
case RESOURCE_ERROR_STACK: case RESOURCE_ERROR_STACK:
case RESOURCE_ERROR_TRAIL: case RESOURCE_ERROR_TRAIL:
comment = MkAtomTerm(Yap_LookupAtom(tmpbuf)); comment = MkAtomTerm(Yap_LookupAtom(tmpbuf));
default: default:
if (comment != TermNil) if (comment != TermNil)
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("i")), comment), nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("i")), comment),
nt[1]); nt[1]);
if (file && function) { if (file && function) {
Term ts[3], t3; Term ts[3], t3;
ts[0] = MkAtomTerm(Yap_LookupAtom(file)); ts[0] = MkAtomTerm(Yap_LookupAtom(file));
ts[1] = MkIntegerTerm(lineno); ts[1] = MkIntegerTerm(lineno);
ts[2] = MkAtomTerm(Yap_LookupAtom(function)); ts[2] = MkAtomTerm(Yap_LookupAtom(function));
t3 = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("c"), 3), 3, ts); t3 = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("c"), 3), 3, ts);
nt[1] = nt[1] =
MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("c")), t3), nt[1]); MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("c")), t3), nt[1]);
} }
if ((location = Yap_pc_location(P, B, ENV)) != TermNil) { if ((location = Yap_pc_location(P, B, ENV)) != TermNil) {
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("p")), location), nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("p")), location),
nt[1]); nt[1]);
} }
if ((location = Yap_env_location(CP, B, ENV, 0)) != TermNil) { if ((location = Yap_env_location(CP, B, ENV, 0)) != TermNil) {
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")), location), nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")), location),
nt[1]); nt[1]);
} }
} }
} }
/* disable active signals at this point */ /* disable active signals at this point */
LOCAL_Signals = 0; LOCAL_Signals = 0;
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
LOCAL_PrologMode &= ~InErrorMode;
#if DEBUG #if DEBUG
// DumpActiveGoals( PASS_REGS1 ); // DumpActiveGoals( PASS_REGS1 );
#endif #endif
/* wait if we we are in user code, /* wait if we we are in user code,
it's up to her to decide */ it's up to her to decide */
fun = FunctorError; fun = FunctorError;
error_t = Yap_MkApplTerm(fun, 2, nt); error_t = Yap_MkApplTerm(fun, 2, nt);
if (type == ABORT_EVENT) { if (type == ABORT_EVENT) {
error_t = MkAtomTerm(AtomDAbort); error_t = MkAtomTerm(AtomDAbort);
} else { } else {
error_t = Yap_MkApplTerm(fun, 2, nt); error_t = Yap_MkApplTerm(fun, 2, nt);
} }
Yap_JumpToEnv(error_t); Yap_JumpToEnv(error_t);
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
return P; return P;
} }
static Int static Int
is_boolean( USES_REGS1 ) is_boolean( USES_REGS1 )
@ -728,7 +729,7 @@ void
Yap_InitErrorPreds( void ) Yap_InitErrorPreds( void )
{ {
CACHE_REGS CACHE_REGS
Yap_InitCPred("is_boolean", 2, is_boolean, TestPredFlag); Yap_InitCPred("is_boolean", 2, is_boolean, TestPredFlag);
Yap_InitCPred("is_callable", 2, is_callable, TestPredFlag); Yap_InitCPred("is_callable", 2, is_callable, TestPredFlag);
Yap_InitCPred("is_atom", 2, is_atom, TestPredFlag); Yap_InitCPred("is_atom", 2, is_atom, TestPredFlag);
Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator, TestPredFlag); Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator, TestPredFlag);