fix swi call leak

improve yapi
reformat
This commit is contained in:
Vitor Santos Costa 2017-06-19 19:02:36 +01:00
parent 6b545c8f71
commit d7e21c80df
35 changed files with 2412 additions and 2334 deletions

View File

@ -28,11 +28,14 @@
#define _EXPORT_KERNEL 1 #define _EXPORT_KERNEL 1
#include <stdlib.h> #include <stdlib.h>
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if HAVE_STDARG_H #if HAVE_STDARG_H
#include <stdarg.h> #include <stdarg.h>
#endif #endif
@ -48,17 +51,25 @@
#include "attvar.h" #include "attvar.h"
#include "clause.h" #include "clause.h"
#include "yapio.h" #include "yapio.h"
#ifdef TABLING #ifdef TABLING
#include "tab.macros.h" #include "tab.macros.h"
#endif /* TABLING */ #endif /* TABLING */
#ifdef YAPOR #ifdef YAPOR
#include "or.macros.h" #include "or.macros.h"
#endif /* YAPOR */ #endif /* YAPOR */
#include "cut_c.h" #include "cut_c.h"
#include "threads.h" #include "threads.h"
#if HAVE_MALLOC_H #if HAVE_MALLOC_H
#include <malloc.h> #include <malloc.h>
#endif #endif
#include "iopreds.h" #include "iopreds.h"
#include <libgen.h> #include <libgen.h>
@ -316,7 +327,7 @@ X_API Term YAP_MkBigNumTerm(void *big) {
#if USE_GMP #if USE_GMP
Term I; Term I;
BACKUP_H(); BACKUP_H();
I = Yap_MkBigIntTerm((MP_INT *)big); I = Yap_MkBigIntTerm((MP_INT *) big);
RECOVER_H(); RECOVER_H();
return I; return I;
#else #else
@ -326,7 +337,7 @@ X_API Term YAP_MkBigNumTerm(void *big) {
X_API YAP_Bool YAP_BigNumOfTerm(Term t, void *b) { X_API YAP_Bool YAP_BigNumOfTerm(Term t, void *b) {
#if USE_GMP #if USE_GMP
MP_INT *bz = (MP_INT *)b; MP_INT *bz = (MP_INT *) b;
if (IsVarTerm(t)) if (IsVarTerm(t))
return FALSE; return FALSE;
if (!IsBigIntTerm(t)) if (!IsBigIntTerm(t))
@ -342,7 +353,7 @@ X_API Term YAP_MkRationalTerm(void *big) {
#if USE_GMP #if USE_GMP
Term I; Term I;
BACKUP_H(); BACKUP_H();
I = Yap_MkBigRatTerm((MP_RAT *)big); I = Yap_MkBigRatTerm((MP_RAT *) big);
RECOVER_H(); RECOVER_H();
return I; return I;
#else #else
@ -352,7 +363,7 @@ X_API Term YAP_MkRationalTerm(void *big) {
X_API YAP_Bool YAP_RationalOfTerm(Term t, void *b) { X_API YAP_Bool YAP_RationalOfTerm(Term t, void *b) {
#if USE_GMP #if USE_GMP
MP_RAT *br = (MP_RAT *)b; MP_RAT *br = (MP_RAT *) b;
if (IsVarTerm(t)) if (IsVarTerm(t))
return FALSE; return FALSE;
if (!IsBigIntTerm(t)) if (!IsBigIntTerm(t))
@ -379,9 +390,9 @@ X_API Term YAP_MkBlobTerm(unsigned int sz) {
} }
} }
I = AbsAppl(HR); I = AbsAppl(HR);
HR[0] = (CELL)FunctorBigInt; HR[0] = (CELL) FunctorBigInt;
HR[1] = ARRAY_INT; HR[1] = ARRAY_INT;
dst = (MP_INT *)(HR + 2); dst = (MP_INT *) (HR + 2);
dst->_mp_size = 0L; dst->_mp_size = 0L;
dst->_mp_alloc = sz; dst->_mp_alloc = sz;
HR += (2 + sizeof(MP_INT) / sizeof(CELL)); HR += (2 + sizeof(MP_INT) / sizeof(CELL));
@ -399,8 +410,8 @@ X_API void *YAP_BlobOfTerm(Term t) {
return NULL; return NULL;
if (!IsBigIntTerm(t)) if (!IsBigIntTerm(t))
return NULL; return NULL;
src = (MP_INT *)(RepAppl(t) + 2); src = (MP_INT *) (RepAppl(t) + 2);
return (void *)(src + 1); return (void *) (src + 1);
} }
X_API Term YAP_MkFloatTerm(double n) { X_API Term YAP_MkFloatTerm(double n) {
@ -562,13 +573,13 @@ X_API Term YAP_MkListFromTerms(Term *ta, Int sz) {
return TermNil; return TermNil;
BACKUP_H(); BACKUP_H();
while (HR + sz * 2 > ASP - 1024) { while (HR + sz * 2 > ASP - 1024) {
Int sl1 = Yap_InitSlot((CELL)ta); Int sl1 = Yap_InitSlot((CELL) ta);
RECOVER_H(); RECOVER_H();
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
return TermNil; return TermNil;
} }
BACKUP_H(); BACKUP_H();
ta = (CELL *)Yap_GetFromSlot(sl1); ta = (CELL *) Yap_GetFromSlot(sl1);
Yap_RecoverSlots(1, sl1); Yap_RecoverSlots(1, sl1);
} }
h = HR; h = HR;
@ -687,8 +698,8 @@ X_API void *YAP_ExtraSpaceCut(void) {
void *ptr; void *ptr;
BACKUP_B(); BACKUP_B();
ptr = (void *)(((CELL *)(Yap_REGS.CUT_C_TOP)) - ptr = (void *) (((CELL *) (Yap_REGS.CUT_C_TOP)) -
(((yamop *)Yap_REGS.CUT_C_TOP->try_userc_cut_yamop) (((yamop *) Yap_REGS.CUT_C_TOP->try_userc_cut_yamop)
->y_u.OtapFs.extra)); ->y_u.OtapFs.extra));
RECOVER_B(); RECOVER_B();
@ -702,7 +713,7 @@ X_API void *YAP_ExtraSpace(void) {
BACKUP_H(); BACKUP_H();
/* find a pointer to extra space allocable */ /* find a pointer to extra space allocable */
ptr = (void *)((CELL *)(B + 1) + P->y_u.OtapFs.s); ptr = (void *) ((CELL *) (B + 1) + P->y_u.OtapFs.s);
B->cp_h = HR; B->cp_h = HR;
RECOVER_H(); RECOVER_H();
@ -836,13 +847,13 @@ X_API Term *YAP_AddressOfTermInSlot(Int slot) {
CACHE_REGS CACHE_REGS
Term *b = Yap_AddressFromSlot(slot); Term *b = Yap_AddressFromSlot(slot);
Term a = *b; Term a = *b;
restart: restart:
if (!IsVarTerm(a)) { if (!IsVarTerm(a)) {
return (b); return (b);
} else if (a == (CELL)b) { } else if (a == (CELL) b) {
return (b); return (b);
} else { } else {
b = (CELL *)a; b = (CELL *) a;
a = *b; a = *b;
goto restart; goto restart;
} }
@ -854,113 +865,149 @@ X_API void YAP_PutInSlot(Int slot, Term t) {
} }
typedef Int (*CPredicate0)(void); typedef Int (*CPredicate0)(void);
typedef Int (*CPredicate1)(yhandle_t); typedef Int (*CPredicate1)(yhandle_t);
typedef Int (*CPredicate2)(yhandle_t, yhandle_t); typedef Int (*CPredicate2)(yhandle_t, yhandle_t);
typedef Int (*CPredicate3)(yhandle_t, yhandle_t, yhandle_t); typedef Int (*CPredicate3)(yhandle_t, yhandle_t, yhandle_t);
typedef Int (*CPredicate4)(yhandle_t, yhandle_t, yhandle_t, yhandle_t); typedef Int (*CPredicate4)(yhandle_t, yhandle_t, yhandle_t, yhandle_t);
typedef Int (*CPredicate5)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate5)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t); yhandle_t);
typedef Int (*CPredicate6)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate6)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t); yhandle_t, yhandle_t);
typedef Int (*CPredicate7)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate7)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t); yhandle_t, yhandle_t, yhandle_t);
typedef Int (*CPredicate8)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate8)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t); yhandle_t, yhandle_t, yhandle_t, yhandle_t);
typedef Int (*CPredicate9)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate9)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t); yhandle_t);
typedef Int (*CPredicate10)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef Int (*CPredicate10)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t); yhandle_t, yhandle_t);
typedef Int (*CPredicateV)(yhandle_t, yhandle_t, struct foreign_context *); typedef Int (*CPredicateV)(yhandle_t, yhandle_t, struct foreign_context *);
static Int execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS) { static Int execute_cargs(PredEntry *pe, CPredicate exec_code USES_REGS) {
Int rc;
yhandle_t a1;
switch (pe->ArityOfPE) { switch (pe->ArityOfPE) {
case 0: { case 0: {
CPredicate0 code0 = (CPredicate0)exec_code; CPredicate0 code0 = (CPredicate0) exec_code;
return code0(); return code0();
} }
case 1: { case 1: {
CPredicate1 code1 = (CPredicate1)exec_code; CPredicate1 code1 = (CPredicate1) exec_code;
yhandle_t a1 = Yap_InitSlots(1, &ARG1); a1 = Yap_InitSlots(1, &ARG1);
return code1(a1); rc = code1(a1);
} }
break;
case 2: { case 2: {
CPredicate2 code2 = (CPredicate2)exec_code; CPredicate2 code2 = (CPredicate2) exec_code;
yhandle_t a1 = Yap_InitSlots(2, &ARG1); a1 = Yap_InitSlots(2, &ARG1);
return code2(a1, a1 + 1); rc = code2(a1, a1 + 1);
} }
break;
case 3: { case 3: {
CPredicate3 code3 = (CPredicate3)exec_code; CPredicate3 code3 = (CPredicate3) exec_code;
yhandle_t a1 = Yap_InitSlots(3, &ARG1); a1 = Yap_InitSlots(3, &ARG1);
return code3(a1, a1 + 1, a1 + 2); rc = code3(a1, a1 + 1, a1 + 2);
} }
break;
case 4: { case 4: {
CPredicate4 code4 = (CPredicate4)exec_code; CPredicate4 code4 = (CPredicate4) exec_code;
yhandle_t a1 = Yap_InitSlots(4, &ARG1); a1 = Yap_InitSlots(4, &ARG1);
return code4(a1, a1 + 1, a1 + 2, a1 + 3); rc = code4(a1, a1 + 1, a1 + 2, a1 + 3);
} }
break;
case 5: { case 5: {
CPredicate5 code5 = (CPredicate5)exec_code; CPredicate5 code5 = (CPredicate5) exec_code;
yhandle_t a1 = Yap_InitSlots(5, &ARG1); a1 = Yap_InitSlots(5, &ARG1);
return code5(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4); rc = code5(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4);
} }
break;
case 6: { case 6: {
CPredicate6 code6 = (CPredicate6)exec_code; CPredicate6 code6 = (CPredicate6) exec_code;
yhandle_t a1 = Yap_InitSlots(6, &ARG1); a1 = Yap_InitSlots(6, &ARG1);
return code6(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5); rc = code6(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5);
} }
break;
case 7: { case 7: {
CPredicate7 code7 = (CPredicate7)exec_code; CPredicate7 code7 = (CPredicate7) exec_code;
yhandle_t a1 = Yap_InitSlots(7, &ARG1); a1 = Yap_InitSlots(7, &ARG1);
return code7(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6); rc = code7(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6);
} }
break;
case 8: { case 8: {
CPredicate8 code8 = (CPredicate8)exec_code; CPredicate8 code8 = (CPredicate8) exec_code;
yhandle_t a1 = Yap_InitSlots(8, &ARG1); a1 = Yap_InitSlots(8, &ARG1);
return code8(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7); rc = code8(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7);
} }
break;
case 9: { case 9: {
CPredicate9 code9 = (CPredicate9)exec_code; CPredicate9 code9 = (CPredicate9) exec_code;
yhandle_t a1 = Yap_InitSlots(9, &ARG1); a1 = Yap_InitSlots(9, &ARG1);
return code9(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7, rc = code9(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7,
a1 + 8); a1 + 8);
} }
break;
case 10: { case 10: {
CPredicate10 code10 = (CPredicate10)exec_code; CPredicate10 code10 = (CPredicate10) exec_code;
yhandle_t a1 = Yap_InitSlots(10, &ARG1); a1 = Yap_InitSlots(10, &ARG1);
return code10(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7, rc = code10(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7,
a1 + 8, a1 + 9); a1 + 8, a1 + 9);
} }
break;
default: default:
YAP_Error(SYSTEM_ERROR_INTERNAL, TermNil, YAP_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"YAP only supports SWI C-call with arity =< 10"); "YAP only supports SWI C-call with arity =< 10");
return (FALSE); return false;
} }
Yap_RecoverSlots(pe->ArityOfPE, a1);
return rc;
} }
typedef uintptr_t (*CBPredicate0)(struct foreign_context *); typedef uintptr_t (*CBPredicate0)(struct foreign_context *);
typedef uintptr_t (*CBPredicate1)(yhandle_t, struct foreign_context *); typedef uintptr_t (*CBPredicate1)(yhandle_t, struct foreign_context *);
typedef uintptr_t (*CBPredicate2)(yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate2)(yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate3)(yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate3)(yhandle_t, yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate4)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate4)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate5)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate5)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, struct foreign_context *); yhandle_t, struct foreign_context *);
typedef uintptr_t (*CBPredicate6)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate6)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate7)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate7)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate8)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate8)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
struct foreign_context *); struct foreign_context *);
typedef uintptr_t (*CBPredicate9)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate9)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, struct foreign_context *); yhandle_t, struct foreign_context *);
typedef uintptr_t (*CBPredicate10)(yhandle_t, yhandle_t, yhandle_t, yhandle_t, typedef uintptr_t (*CBPredicate10)(yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t, yhandle_t,
yhandle_t, yhandle_t, yhandle_t, yhandle_t,
@ -970,58 +1017,58 @@ static uintptr_t execute_cargs_back(PredEntry *pe, CPredicate exec_code,
struct foreign_context *ctx USES_REGS) { struct foreign_context *ctx USES_REGS) {
switch (pe->ArityOfPE) { switch (pe->ArityOfPE) {
case 0: { case 0: {
CBPredicate0 code0 = (CBPredicate0)exec_code; CBPredicate0 code0 = (CBPredicate0) exec_code;
return code0(ctx); return code0(ctx);
} }
case 1: { case 1: {
CBPredicate1 code1 = (CBPredicate1)exec_code; CBPredicate1 code1 = (CBPredicate1) exec_code;
yhandle_t a1 = Yap_InitSlots(1, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(1, &B->cp_a1);
return code1(a1, ctx); return code1(a1, ctx);
} }
case 2: { case 2: {
CBPredicate2 code2 = (CBPredicate2)exec_code; CBPredicate2 code2 = (CBPredicate2) exec_code;
yhandle_t a1 = Yap_InitSlots(2, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(2, &B->cp_a1);
return code2(a1, a1 + 1, ctx); return code2(a1, a1 + 1, ctx);
} }
case 3: { case 3: {
CBPredicate3 code3 = (CBPredicate3)exec_code; CBPredicate3 code3 = (CBPredicate3) exec_code;
yhandle_t a1 = Yap_InitSlots(3, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(3, &B->cp_a1);
return code3(a1, a1 + 1, a1 + 2, ctx); return code3(a1, a1 + 1, a1 + 2, ctx);
} }
case 4: { case 4: {
CBPredicate4 code4 = (CBPredicate4)exec_code; CBPredicate4 code4 = (CBPredicate4) exec_code;
yhandle_t a1 = Yap_InitSlots(4, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(4, &B->cp_a1);
return code4(a1, a1 + 1, a1 + 2, a1 + 3, ctx); return code4(a1, a1 + 1, a1 + 2, a1 + 3, ctx);
} }
case 5: { case 5: {
CBPredicate5 code5 = (CBPredicate5)exec_code; CBPredicate5 code5 = (CBPredicate5) exec_code;
yhandle_t a1 = Yap_InitSlots(5, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(5, &B->cp_a1);
return code5(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, ctx); return code5(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, ctx);
} }
case 6: { case 6: {
CBPredicate6 code6 = (CBPredicate6)exec_code; CBPredicate6 code6 = (CBPredicate6) exec_code;
yhandle_t a1 = Yap_InitSlots(6, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(6, &B->cp_a1);
return code6(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, ctx); return code6(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, ctx);
} }
case 7: { case 7: {
CBPredicate7 code7 = (CBPredicate7)exec_code; CBPredicate7 code7 = (CBPredicate7) exec_code;
yhandle_t a1 = Yap_InitSlots(7, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(7, &B->cp_a1);
return code7(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, ctx); return code7(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, ctx);
} }
case 8: { case 8: {
CBPredicate8 code8 = (CBPredicate8)exec_code; CBPredicate8 code8 = (CBPredicate8) exec_code;
yhandle_t a1 = Yap_InitSlots(8, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(8, &B->cp_a1);
return code8(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7, return code8(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7,
ctx); ctx);
} }
case 9: { case 9: {
CBPredicate9 code9 = (CBPredicate9)exec_code; CBPredicate9 code9 = (CBPredicate9) exec_code;
yhandle_t a1 = Yap_InitSlots(9, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(9, &B->cp_a1);
return code9(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7, return code9(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7,
a1 + 8, ctx); a1 + 8, ctx);
} }
case 10: { case 10: {
CBPredicate10 code10 = (CBPredicate10)exec_code; CBPredicate10 code10 = (CBPredicate10) exec_code;
yhandle_t a1 = Yap_InitSlots(10, &B->cp_a1); yhandle_t a1 = Yap_InitSlots(10, &B->cp_a1);
return code10(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7, return code10(a1, a1 + 1, a1 + 2, a1 + 3, a1 + 4, a1 + 5, a1 + 6, a1 + 7,
a1 + 8, a1 + 9, ctx); a1 + 8, a1 + 9, ctx);
@ -1060,7 +1107,7 @@ static uintptr_t complete_exit(choiceptr ptr, int has_cp,
if (!ptr || B < ptr) { if (!ptr || B < ptr) {
// we're still not there yet // we're still not there yet
choiceptr new = B; choiceptr new = B;
while (new &&new < ptr) { while (new && new < ptr) {
if (new->cp_ap == NOCODE) /* separator */ if (new->cp_ap == NOCODE) /* separator */
new->cp_ap = FAILCODE; // there are choice-points above but at least, new->cp_ap = FAILCODE; // there are choice-points above but at least,
// these won't harm innocent code // these won't harm innocent code
@ -1085,13 +1132,13 @@ static uintptr_t complete_exit(choiceptr ptr, int has_cp,
X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) { X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
CACHE_REGS CACHE_REGS
Int ret; Int ret;
Int OASP = LCL0 - (CELL *)B; Int OASP = LCL0 - (CELL *) B;
// Term omod = CurrentModule; // Term omod = CurrentModule;
// if (pe->PredFlags & CArgsPredFlag) { // if (pe->PredFlags & CArgsPredFlag) {
// CurrentModule = pe->ModuleOfPred; // CurrentModule = pe->ModuleOfPred;
//} //}
if (pe->PredFlags & SWIEnvPredFlag) { if (pe->PredFlags & SWIEnvPredFlag) {
CPredicateV codev = (CPredicateV)exec_code; CPredicateV codev = (CPredicateV) exec_code;
struct foreign_context ctx; struct foreign_context ctx;
ctx.engine = NULL; ctx.engine = NULL;
@ -1108,9 +1155,9 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
PP = NULL; PP = NULL;
// check for junk: open frames, etc */ // check for junk: open frames, etc */
if (ret) if (ret)
complete_exit(((choiceptr)(LCL0 - OASP)), FALSE, FALSE PASS_REGS); complete_exit(((choiceptr) (LCL0 - OASP)), FALSE, FALSE PASS_REGS);
else else
complete_fail(((choiceptr)(LCL0 - OASP)), FALSE PASS_REGS); complete_fail(((choiceptr) (LCL0 - OASP)), FALSE PASS_REGS);
// CurrentModule = omod; // CurrentModule = omod;
if (!ret) { if (!ret) {
Yap_RaiseException(); Yap_RaiseException();
@ -1125,20 +1172,20 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) { X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) {
CACHE_REGS CACHE_REGS
CELL ocp = LCL0 - (CELL *)B; CELL ocp = LCL0 - (CELL *) B;
/* for slots to work */ /* for slots to work */
Int CurSlot = Yap_StartSlots(); Int CurSlot = Yap_StartSlots();
if (pe->PredFlags & if (pe->PredFlags &
(SWIEnvPredFlag | CArgsPredFlag | ModuleTransparentPredFlag)) { (SWIEnvPredFlag | CArgsPredFlag | ModuleTransparentPredFlag)) {
uintptr_t val; uintptr_t val;
CPredicateV codev = (CPredicateV)exec_code; CPredicateV codev = (CPredicateV) exec_code;
struct foreign_context *ctx = struct foreign_context *ctx =
(struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE, 1)); (struct foreign_context *) (&EXTRA_CBACK_ARG(pe->ArityOfPE, 1));
PP = pe; PP = pe;
ctx->control = FRG_FIRST_CALL; ctx->control = FRG_FIRST_CALL;
ctx->engine = NULL; //(PL_local_data *)Yap_regp; ctx->engine = NULL; //(PL_local_data *)Yap_regp;
ctx->context = (uintptr_t)NULL; ctx->context = (uintptr_t) NULL;
if (pe->PredFlags & CArgsPredFlag) { if (pe->PredFlags & CArgsPredFlag) {
val = execute_cargs_back(pe, exec_code, ctx PASS_REGS); val = execute_cargs_back(pe, exec_code, ctx PASS_REGS);
} else { } else {
@ -1150,16 +1197,16 @@ X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) {
if (Yap_RaiseException()) { if (Yap_RaiseException()) {
return false; return false;
} }
return complete_fail(((choiceptr)(LCL0 - ocp)), TRUE PASS_REGS); return complete_fail(((choiceptr) (LCL0 - ocp)), TRUE PASS_REGS);
} else if (val == 1) { /* TRUE */ } else if (val == 1) { /* TRUE */
return complete_exit(((choiceptr)(LCL0 - ocp)), TRUE, FALSE PASS_REGS); return complete_exit(((choiceptr) (LCL0 - ocp)), TRUE, FALSE PASS_REGS);
} else { } else {
if ((val & REDO_PTR) == REDO_PTR) if ((val & REDO_PTR) == REDO_PTR)
ctx->context = (uintptr_t)(val & ~REDO_PTR); ctx->context = (uintptr_t) (val & ~REDO_PTR);
else else
ctx->context = (uintptr_t)((val & ~REDO_PTR) >> FRG_REDO_BITS); ctx->context = (uintptr_t) ((val & ~REDO_PTR) >> FRG_REDO_BITS);
/* fix dropped cps */ /* fix dropped cps */
return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS); return complete_exit(((choiceptr) (LCL0 - ocp)), FALSE, FALSE PASS_REGS);
} }
} else { } else {
Int ret = (exec_code)(PASS_REGS1); Int ret = (exec_code)(PASS_REGS1);
@ -1174,24 +1221,24 @@ X_API Int YAP_ExecuteFirst(PredEntry *pe, CPredicate exec_code) {
X_API Int YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, X_API Int YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code,
struct cut_c_str *top) { struct cut_c_str *top) {
CACHE_REGS CACHE_REGS
Int oB = LCL0 - (CELL *)B; Int oB = LCL0 - (CELL *) B;
Int val; Int val;
/* for slots to work */ /* for slots to work */
yhandle_t CurSlot = Yap_StartSlots(); yhandle_t CurSlot = Yap_StartSlots();
/* find out where we belong */ /* find out where we belong */
while (B < (choiceptr)top) { while (B < (choiceptr) top) {
oB = LCL0 - (CELL *)B; oB = LCL0 - (CELL *) B;
B = B->cp_b; B = B->cp_b;
} }
PP = pe; PP = pe;
if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) { if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) {
// SWI Emulation // SWI Emulation
CPredicateV codev = (CPredicateV)exec_code; CPredicateV codev = (CPredicateV) exec_code;
struct foreign_context *ctx = struct foreign_context *ctx =
(struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE, 1)); (struct foreign_context *) (&EXTRA_CBACK_ARG(pe->ArityOfPE, 1));
CELL *args = B->cp_args; CELL *args = B->cp_args;
B = (choiceptr)(LCL0 - oB); B = (choiceptr) (LCL0 - oB);
ctx->control = FRG_CUTTED; ctx->control = FRG_CUTTED;
ctx->engine = NULL; //(PL_local_data *)Yap_regp; ctx->engine = NULL; //(PL_local_data *)Yap_regp;
if (pe->PredFlags & CArgsPredFlag) { if (pe->PredFlags & CArgsPredFlag) {
@ -1203,7 +1250,7 @@ X_API Int YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code,
Int oYENV = LCL0 - YENV; Int oYENV = LCL0 - YENV;
yamop *oP = P, *oCP = CP; yamop *oP = P, *oCP = CP;
// YAP Native // YAP Native
B = (choiceptr)(LCL0 - oB); B = (choiceptr) (LCL0 - oB);
val = exec_code(PASS_REGS1); val = exec_code(PASS_REGS1);
YENV = LCL0 - oYENV; YENV = LCL0 - oYENV;
P = oP; P = oP;
@ -1223,12 +1270,12 @@ X_API Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
CACHE_REGS CACHE_REGS
/* for slots to work */ /* for slots to work */
Yap_StartSlots(); Yap_StartSlots();
UInt ocp = LCL0 - (CELL *)B; UInt ocp = LCL0 - (CELL *) B;
if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) { if (pe->PredFlags & (SWIEnvPredFlag | CArgsPredFlag)) {
Int val; Int val;
CPredicateV codev = (CPredicateV)exec_code; CPredicateV codev = (CPredicateV) exec_code;
struct foreign_context *ctx = struct foreign_context *ctx =
(struct foreign_context *)(&EXTRA_CBACK_ARG(pe->ArityOfPE, 1)); (struct foreign_context *) (&EXTRA_CBACK_ARG(pe->ArityOfPE, 1));
PP = pe; PP = pe;
ctx->control = FRG_REDO; ctx->control = FRG_REDO;
@ -1244,18 +1291,18 @@ X_API Int YAP_ExecuteNext(PredEntry *pe, CPredicate exec_code) {
if (Yap_RaiseException()) { if (Yap_RaiseException()) {
return FALSE; return FALSE;
} else { } else {
return complete_fail(((choiceptr)(LCL0 - ocp)), TRUE PASS_REGS); return complete_fail(((choiceptr) (LCL0 - ocp)), TRUE PASS_REGS);
} }
} else if (val == 1) { /* TRUE */ } else if (val == 1) { /* TRUE */
return complete_exit(((choiceptr)(LCL0 - ocp)), TRUE, FALSE PASS_REGS); return complete_exit(((choiceptr) (LCL0 - ocp)), TRUE, FALSE PASS_REGS);
} else { } else {
if ((val & REDO_PTR) == REDO_PTR) if ((val & REDO_PTR) == REDO_PTR)
ctx->context = (uintptr_t)(val & ~REDO_PTR); ctx->context = (uintptr_t) (val & ~REDO_PTR);
else else
ctx->context = (uintptr_t)((val & ~REDO_PTR) >> FRG_REDO_BITS); ctx->context = (uintptr_t) ((val & ~REDO_PTR) >> FRG_REDO_BITS);
} }
/* fix dropped cps */ /* fix dropped cps */
return complete_exit(((choiceptr)(LCL0 - ocp)), FALSE, FALSE PASS_REGS); return complete_exit(((choiceptr) (LCL0 - ocp)), FALSE, FALSE PASS_REGS);
} else { } else {
Int ret = (exec_code)(PASS_REGS1); Int ret = (exec_code)(PASS_REGS1);
if (!ret) { if (!ret) {
@ -1406,7 +1453,7 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
else else
tv = 0; tv = 0;
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
const unsigned char *us = (const unsigned char *)s; const unsigned char *us = (const unsigned char *) s;
while (!(t = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil, while (!(t = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil,
GLOBAL_MaxPriority, tv))) { GLOBAL_MaxPriority, tv))) {
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
@ -1633,7 +1680,7 @@ X_API void YAP_Error(int myerrno, Term t, const char *buf, ...) {
if (buf != NULL) { if (buf != NULL) {
va_start(ap, buf); va_start(ap, buf);
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void)vsnprintf(tmpbuf, YAP_BUF_SIZE, buf, ap); (void) vsnprintf(tmpbuf, YAP_BUF_SIZE, buf, ap);
#else #else
(void)vsprintf(tmpbuf, buf, ap); (void)vsprintf(tmpbuf, buf, ap);
#endif #endif
@ -1686,7 +1733,7 @@ X_API bool YAP_EnterGoal(PredEntry *pe, CELL *ptr, YAP_dogoalinfo *dgi) {
// __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %d %x %x args=%x,%x // __android_log_print(ANDROID_LOG_INFO, "YAP ", "ap=%p %d %x %x args=%x,%x
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2), // slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
// LOCAL_CurSlot); // LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *) B;
out = Yap_exec_absmi(true, false); out = Yap_exec_absmi(true, false);
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
@ -1705,7 +1752,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
bool out; bool out;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b); myB = (choiceptr) (LCL0 - dgi->b);
CP = myB->cp_cp; CP = myB->cp_cp;
/* sanity check */ /* sanity check */
if (B >= myB) { if (B >= myB) {
@ -1713,7 +1760,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
} }
P = FAILCODE; P = FAILCODE;
/* make sure we didn't leave live slots when we backtrack */ /* make sure we didn't leave live slots when we backtrack */
ASP = (CELL *)B; ASP = (CELL *) B;
LOCAL_CurSlot = dgi->EndSlot; LOCAL_CurSlot = dgi->EndSlot;
out = run_emulator(PASS_REGS1); out = run_emulator(PASS_REGS1);
if (out) { if (out) {
@ -1731,7 +1778,7 @@ X_API bool YAP_LeaveGoal(bool backtrack, YAP_dogoalinfo *dgi) {
choiceptr myB; choiceptr myB;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b); myB = (choiceptr) (LCL0 - dgi->b);
if (B > myB) { if (B > myB) {
/* someone cut us */ /* someone cut us */
return FALSE; return FALSE;
@ -1765,12 +1812,12 @@ X_API bool YAP_LeaveGoal(bool backtrack, YAP_dogoalinfo *dgi) {
if (POP_CHOICE_POINT(B->cp_b)) { if (POP_CHOICE_POINT(B->cp_b)) {
POP_EXECUTE(); POP_EXECUTE();
} }
ENV = (CELL *)(ENV[E_E]); ENV = (CELL *) (ENV[E_E]);
/* ASP should be set to the top of the local stack when we /* ASP should be set to the top of the local stack when we
did the call */ did the call */
ASP = B->cp_env; ASP = B->cp_env;
/* YENV should be set to the current environment */ /* YENV should be set to the current environment */
YENV = ENV = (CELL *)((B->cp_env)[E_E]); YENV = ENV = (CELL *) ((B->cp_env)[E_E]);
B = B->cp_b; B = B->cp_b;
// SET_BB(B); // SET_BB(B);
HB = PROTECT_FROZEN_H(B); HB = PROTECT_FROZEN_H(B);
@ -1796,14 +1843,14 @@ X_API Int YAP_RunGoal(Term t) {
// We'll pass it through // We'll pass it through
Yap_RaiseException(); Yap_RaiseException();
if (out) { if (out) {
P = (yamop *)ENV[E_CP]; P = (yamop *) ENV[E_CP];
ENV = (CELL *)ENV[E_E]; ENV = (CELL *) ENV[E_E];
CP = old_CP; CP = old_CP;
LOCAL_AllowRestart = TRUE; LOCAL_AllowRestart = TRUE;
// we are back to user code again, need slots */ // we are back to user code again, need slots */
} else { } else {
ENV = B->cp_env; ENV = B->cp_env;
ENV = (CELL *)ENV[E_E]; ENV = (CELL *) ENV[E_E];
CP = old_CP; CP = old_CP;
HR = B->cp_h; HR = B->cp_h;
TR = B->cp_tr; TR = B->cp_tr;
@ -1851,14 +1898,14 @@ X_API YAP_opaque_tag_t YAP_NewOpaqueType(struct YAP_opaque_handler_struct *f) {
} }
X_API Term YAP_NewOpaqueObject(YAP_opaque_tag_t tag, size_t bytes) { X_API Term YAP_NewOpaqueObject(YAP_opaque_tag_t tag, size_t bytes) {
Term t = Yap_AllocExternalDataInStack((CELL)tag, bytes); Term t = Yap_AllocExternalDataInStack((CELL) tag, bytes);
if (t == TermNil) if (t == TermNil)
return 0L; return 0L;
return t; return t;
} }
X_API YAP_Bool YAP_IsOpaqueObjectTerm(Term t, YAP_opaque_tag_t tag) { X_API YAP_Bool YAP_IsOpaqueObjectTerm(Term t, YAP_opaque_tag_t tag) {
return IsExternalBlobTerm(t, (CELL)tag); return IsExternalBlobTerm(t, (CELL) tag);
} }
X_API void *YAP_OpaqueObjectFromTerm(Term t) { return ExternalBlobFromTerm(t); } X_API void *YAP_OpaqueObjectFromTerm(Term t) { return ExternalBlobFromTerm(t); }
@ -1915,12 +1962,12 @@ X_API Int YAP_RunGoalOnce(Term t) {
B = cut_pt; B = cut_pt;
} }
ASP = B->cp_env; ASP = B->cp_env;
ENV = (CELL *)ASP[E_E]; ENV = (CELL *) ASP[E_E];
B = (choiceptr)ASP[E_CB]; B = (choiceptr) ASP[E_CB];
#ifdef DEPTH_LIMITxs #ifdef DEPTH_LIMITxs
DEPTH = ASP[E_DEPTH]; DEPTH = ASP[E_DEPTH];
#endif #endif
P = (yamop *)ASP[E_CP]; P = (yamop *) ASP[E_CP];
CP = old_CP; CP = old_CP;
LOCAL_AllowRestart = FALSE; LOCAL_AllowRestart = FALSE;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
@ -1932,7 +1979,7 @@ X_API bool YAP_RestartGoal(void) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
bool out; bool out;
if (LOCAL_AllowRestart) { if (LOCAL_AllowRestart) {
P = (yamop *)FAILCODE; P = (yamop *) FAILCODE;
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
out = Yap_exec_absmi(TRUE, YAP_EXEC_ABSMI); out = Yap_exec_absmi(TRUE, YAP_EXEC_ABSMI);
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode = UserCCallMode;
@ -1977,8 +2024,8 @@ X_API bool YAP_ShutdownGoal(int backtrack) {
} }
/* we can always recover the stack */ /* we can always recover the stack */
ASP = cut_pt->cp_env; ASP = cut_pt->cp_env;
ENV = (CELL *)ASP[E_E]; ENV = (CELL *) ASP[E_E];
B = (choiceptr)ASP[E_CB]; B = (choiceptr) ASP[E_CB];
Yap_TrimTrail(); Yap_TrimTrail();
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = ASP[E_DEPTH]; DEPTH = ASP[E_DEPTH];
@ -2006,7 +2053,7 @@ X_API void YAP_PruneGoal(YAP_dogoalinfo *gi) {
CACHE_REGS CACHE_REGS
BACKUP_B(); BACKUP_B();
choiceptr myB = (choiceptr)(LCL0 - gi->b); choiceptr myB = (choiceptr) (LCL0 - gi->b);
while (B != myB) { while (B != myB) {
/* make sure we prune C-choicepoints */ /* make sure we prune C-choicepoints */
if (POP_CHOICE_POINT(B->cp_b)) { if (POP_CHOICE_POINT(B->cp_b)) {
@ -2155,7 +2202,7 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
inp.type = YAP_STRING_TERM; inp.type = YAP_STRING_TERM;
out.type = YAP_STRING_CHARS; out.type = YAP_STRING_CHARS;
out.val.c = buf; out.val.c = buf;
out.max = sze-1; out.max = sze - 1;
out.enc = LOCAL_encoding; out.enc = LOCAL_encoding;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return NULL; return NULL;
@ -2643,21 +2690,21 @@ X_API CELL *YAP_TopOfLocalStack(void) {
X_API void *YAP_Predicate(Atom a, UInt arity, Term m) { X_API void *YAP_Predicate(Atom a, UInt arity, Term m) {
if (arity == 0) { if (arity == 0) {
return ((void *)RepPredProp(PredPropByAtom(a, m))); return ((void *) RepPredProp(PredPropByAtom(a, m)));
} else { } else {
Functor f = Yap_MkFunctor(a, arity); Functor f = Yap_MkFunctor(a, arity);
return ((void *)RepPredProp(PredPropByFunc(f, m))); return ((void *) RepPredProp(PredPropByFunc(f, m)));
} }
} }
X_API void YAP_PredicateInfo(void *p, Atom *a, UInt *arity, Term *m) { X_API void YAP_PredicateInfo(void *p, Atom *a, UInt *arity, Term *m) {
PredEntry *pd = (PredEntry *)p; PredEntry *pd = (PredEntry *) p;
if (pd->ArityOfPE) { if (pd->ArityOfPE) {
*arity = pd->ArityOfPE; *arity = pd->ArityOfPE;
*a = NameOfFunctor(pd->FunctorOfPred); *a = NameOfFunctor(pd->FunctorOfPred);
} else { } else {
*arity = 0; *arity = 0;
*a = (Atom)(pd->FunctorOfPred); *a = (Atom) (pd->FunctorOfPred);
} }
if (pd->ModuleOfPred) if (pd->ModuleOfPred)
*m = pd->ModuleOfPred; *m = pd->ModuleOfPred;
@ -2809,15 +2856,15 @@ X_API Term YAP_FloatsToList(double *dblp, size_t sz) {
if (!sz) if (!sz)
return TermNil; return TermNil;
while (ASP - 1024 < HR + sz * (2 + 2 + SIZEOF_DOUBLE / SIZEOF_INT_P)) { while (ASP - 1024 < HR + sz * (2 + 2 + SIZEOF_DOUBLE / SIZEOF_INT_P)) {
if ((CELL *)dblp > H0 && (CELL *)dblp < HR) { if ((CELL *) dblp > H0 && (CELL *) dblp < HR) {
/* we are in trouble */ /* we are in trouble */
LOCAL_OpenArray = (CELL *)dblp; LOCAL_OpenArray = (CELL *) dblp;
} }
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
RECOVER_H(); RECOVER_H();
return 0L; return 0L;
} }
dblp = (double *)LOCAL_OpenArray; dblp = (double *) LOCAL_OpenArray;
LOCAL_OpenArray = NULL; LOCAL_OpenArray = NULL;
} }
t = AbsPair(HR); t = AbsPair(HR);
@ -2877,15 +2924,15 @@ X_API Term YAP_IntsToList(Int *dblp, size_t sz) {
if (!sz) if (!sz)
return TermNil; return TermNil;
while (ASP - 1024 < HR + sz * 3) { while (ASP - 1024 < HR + sz * 3) {
if ((CELL *)dblp > H0 && (CELL *)dblp < HR) { if ((CELL *) dblp > H0 && (CELL *) dblp < HR) {
/* we are in trouble */ /* we are in trouble */
LOCAL_OpenArray = (CELL *)dblp; LOCAL_OpenArray = (CELL *) dblp;
} }
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
RECOVER_H(); RECOVER_H();
return 0L; return 0L;
} }
dblp = (Int *)LOCAL_OpenArray; dblp = (Int *) LOCAL_OpenArray;
LOCAL_OpenArray = NULL; LOCAL_OpenArray = NULL;
} }
t = AbsPair(HR); t = AbsPair(HR);
@ -2958,7 +3005,7 @@ X_API int YAP_CloseList(Term t0, Term tail) {
CELL *ptr = RepPair(t0); CELL *ptr = RepPair(t0);
RESET_VARIABLE(ptr - 1); RESET_VARIABLE(ptr - 1);
if (!Yap_unify((Term)(ptr - 1), tail)) if (!Yap_unify((Term) (ptr - 1), tail))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
@ -3007,11 +3054,11 @@ X_API void *YAP_Record(Term t) {
dbterm = Yap_StoreTermInDB(Deref(t), 0); dbterm = Yap_StoreTermInDB(Deref(t), 0);
if (dbterm == NULL) if (dbterm == NULL)
return NULL; return NULL;
dbt = (struct record_list *)Yap_AllocCodeSpace(sizeof(struct record_list)); dbt = (struct record_list *) Yap_AllocCodeSpace(sizeof(struct record_list));
while (dbt == NULL) { while (dbt == NULL) {
if (!Yap_growheap(FALSE, sizeof(struct record_list), NULL)) { if (!Yap_growheap(FALSE, sizeof(struct record_list), NULL)) {
/* be a good neighbor */ /* be a good neighbor */
Yap_FreeCodeSpace((void *)dbterm); Yap_FreeCodeSpace((void *) dbterm);
Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "using YAP_Record"); Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "using YAP_Record");
return NULL; return NULL;
} }
@ -3029,7 +3076,7 @@ X_API void *YAP_Record(Term t) {
X_API Term YAP_Recorded(void *handle) { X_API Term YAP_Recorded(void *handle) {
CACHE_REGS CACHE_REGS
Term t; Term t;
DBTerm *dbterm = ((DBRecordList *)handle)->dbrecord; DBTerm *dbterm = ((DBRecordList *) handle)->dbrecord;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
do { do {
@ -3054,13 +3101,13 @@ X_API Term YAP_Recorded(void *handle) {
return FALSE; return FALSE;
} }
} }
} while (t == (CELL)0); } while (t == (CELL) 0);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return t; return t;
} }
X_API int YAP_Erase(void *handle) { X_API int YAP_Erase(void *handle) {
DBRecordList *dbr = (DBRecordList *)handle; DBRecordList *dbr = (DBRecordList *) handle;
if (dbr->next_rec) if (dbr->next_rec)
dbr->next_rec->prev_rec = dbr->prev_rec; dbr->next_rec->prev_rec = dbr->prev_rec;
if (dbr->prev_rec) if (dbr->prev_rec)
@ -3093,7 +3140,7 @@ X_API int YAP_SetYAPFlag(Term flag, Term val) { return setYapFlag(flag, val); }
/* yhandle_t YAP_VarSlotToNumber(yhandle_t) */ /* yhandle_t YAP_VarSlotToNumber(yhandle_t) */
X_API yhandle_t YAP_VarSlotToNumber(yhandle_t s) { X_API yhandle_t YAP_VarSlotToNumber(yhandle_t s) {
CACHE_REGS CACHE_REGS
Term *t = (CELL *)Deref(Yap_GetFromSlot(s)); Term *t = (CELL *) Deref(Yap_GetFromSlot(s));
if (t < HR) if (t < HR)
return t - H0; return t - H0;
return t - LCL0; return t - LCL0;
@ -3355,7 +3402,7 @@ X_API Int YAP_AtomToInt(Atom At) {
AtomTranslations++; AtomTranslations++;
if (AtomTranslations == MaxAtomTranslations) { if (AtomTranslations == MaxAtomTranslations) {
atom_t *ot = TR_Atoms; atom_t *ot = TR_Atoms;
atom_t *nt = (atom_t *)malloc(sizeof(atom_t) * 2 * MaxAtomTranslations); atom_t *nt = (atom_t *) malloc(sizeof(atom_t) * 2 * MaxAtomTranslations);
if (nt == NULL) { if (nt == NULL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, MkAtomTerm(At), Yap_Error(SYSTEM_ERROR_INTERNAL, MkAtomTerm(At),
"No more room for translations"); "No more room for translations");
@ -3381,7 +3428,7 @@ X_API Int YAP_FunctorToInt(Functor f) {
Yap_PutAtomTranslation(At, arity, FunctorTranslations); Yap_PutAtomTranslation(At, arity, FunctorTranslations);
FunctorTranslations++; FunctorTranslations++;
if (FunctorTranslations == MaxFunctorTranslations) { if (FunctorTranslations == MaxFunctorTranslations) {
functor_t *nt = (functor_t *)malloc(sizeof(functor_t) * 2 * functor_t *nt = (functor_t *) malloc(sizeof(functor_t) * 2 *
MaxFunctorTranslations), MaxFunctorTranslations),
*ot = TR_Functors; *ot = TR_Functors;
if (nt == NULL) { if (nt == NULL) {
@ -3397,24 +3444,23 @@ X_API Int YAP_FunctorToInt(Functor f) {
return FunctorTranslations - 1; return FunctorTranslations - 1;
} }
X_API void * YAP_foreign_stream(int sno){ return GLOBAL_Stream[sno].u.private_data; } X_API void *YAP_foreign_stream(int sno) { return GLOBAL_Stream[sno].u.private_data; }
X_API Functor YAP_IntToFunctor(Int i) { return TR_Functors[i]; } X_API Functor YAP_IntToFunctor(Int i) { return TR_Functors[i]; }
X_API void *YAP_shared(void) { return LOCAL_shared; } X_API void *YAP_shared(void) { return LOCAL_shared; }
X_API PredEntry *YAP_TopGoal(void) X_API PredEntry *YAP_TopGoal(void) {
{ YAP_Functor f = Yap_MkFunctor(Yap_LookupAtom("yap_query"), 3);
YAP_Functor f = Yap_MkFunctor(Yap_LookupAtom("yap_query"),3);
Term tmod = MkAtomTerm(Yap_LookupAtom("yapi")); Term tmod = MkAtomTerm(Yap_LookupAtom("yapi"));
PredEntry *p = RepPredProp(Yap_GetPredPropByFunc(f, tmod)); PredEntry *p = RepPredProp(Yap_GetPredPropByFunc(f, tmod));
return p; return p;
} }
void yap_init(void) {} void yap_init(void) {}
#endif // C_INTERFACE_C #endif // C_INTERFACE_C
/** /**
@} @}
*/ */

View File

@ -283,7 +283,7 @@ static inline bool Yap_RecoverHandles__(int n, yhandle_t topHandle USES_REGS) {
return false; return false;
} }
#endif #endif
LOCAL_CurHandle -= n; LOCAL_CurHandle = topHandle;
// fprintf(stderr,"RS %ld %s:%d\n", LOCAL_CurHandle, __FILE__, __LINE__); // fprintf(stderr,"RS %ld %s:%d\n", LOCAL_CurHandle, __FILE__, __LINE__);
return true; return true;
} }

View File

@ -1,46 +0,0 @@
#
# Copyright (c) 1998, 1999, 2000, 2001, 2002, 2003, 2010, 2011, 2013,
# 2015, 2016
# Tama Communications Corporation
#
# This file is part of GNU GLOBAL.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# *
# Configuration file for GNU GLOBAL source code tag system.
#
# Basically, GLOBAL doesn't need this file ('gtags.conf'), because it has
# default values in itsself. If you have the file as '/etc/gtags.conf' or
# "$HOME/.globalrc" in your system then GLOBAL overwrite the default values
# with the values in the file.
#
# The format is similar to termcap(5). You can specify a target with
# GTAGSLABEL environment variable. Default target is 'default'.
#
# If you want to have a common record for yourself, it is recommended to
# use the following method:
#
common:
:skip=Debug/,Release/,Threads/,mxe/,xcode/,codeblocks/,Qt/,xcode/,android/,compile_commands.json,xml/,YAPDroid/app/build/,YAPDroid/lib/build/:HTML/,HTML.pub/,tags,TAGS,ID,y.tab.c,y.tab.h,gtags.files,cscope.files,cscope.out,cscope.po.out,cscope.in.out,SCCS/,RCS/,CVS/,CVSROOT/,{arch}/,autom4te.cache/,*.orig,*.rej,*.bak,*~,#*#,*.swp,*.tmp,*_flymake.*,*_flymake:
#
# A common map for both Exuberant Ctags and Universal Ctags.
# Don't include definitions of ctagscom and ctagslib in this entry.
#
default:\
yap:native:user:
yap:\
:tc=common:\
:langmap=Prolog\:.pl.yap.ypp.P.prolog:\
:gtags_parser=Prolog\:$ctagslib:

View File

@ -801,7 +801,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
return false; return false;
} }
ARG1 = Yap_GetFromHandle(s1); ARG1 = Yap_GetFromHandle(s1);
Yap_RecoverHandles(sl, tnum - targ); Yap_RecoverHandles(tnum - targ, sl);
Yap_CloseSlots(sl0); Yap_CloseSlots(sl0);
} }
break; break;

View File

@ -70,6 +70,7 @@ class Type(object):
REFERENCE = re.compile("""^(.+)&$""") REFERENCE = re.compile("""^(.+)&$""")
def __init__(self, text): def __init__(self, text):
# type: (object) -> object
if isinstance(text, Type): if isinstance(text, Type):
self.clone_from(text) self.clone_from(text)
return return
@ -128,6 +129,7 @@ class Constraint(object):
ARG = re.compile("""((?:[^,<(]|<[^>]*>|\([^)]*\))+),?""") ARG = re.compile("""((?:[^,<(]|<[^>]*>|\([^)]*\))+),?""")
def __init__(self, line): def __init__(self, line):
# type: (object) -> object
if isinstance(line, Constraint): if isinstance(line, Constraint):
self.clone_from(line) self.clone_from(line)
return return
@ -182,6 +184,7 @@ def load_decls(filename):
class DeclsLoader(object): class DeclsLoader(object):
def __init__(self, filename): def __init__(self, filename):
# type: (object) -> object
self.decls = load_decls(filename) self.decls = load_decls(filename)
def print_decls(self): def print_decls(self):
@ -201,6 +204,7 @@ class PredGenerator(DeclsLoader):
"TieBreakVarBranch<SetVarBranch>") "TieBreakVarBranch<SetVarBranch>")
def __init__(self, filename): def __init__(self, filename):
# type: (object) -> object
super(PredGenerator, self).__init__(filename) super(PredGenerator, self).__init__(filename)
self._change_home_to_space() self._change_home_to_space()
self._change_intsharedarray_to_intargs() self._change_intsharedarray_to_intargs()
@ -291,6 +295,7 @@ class PredGenerator(DeclsLoader):
class Cluster(object): class Cluster(object):
def __init__(self, name, arity): def __init__(self, name, arity):
# type: (object, object) -> object
self.name = name self.name = name
self.arity = arity self.arity = arity
self.preds = [] self.preds = []
@ -299,6 +304,7 @@ class Cluster(object):
class DTree(object): class DTree(object):
def __init__(self, i, preds, cluster): def __init__(self, i, preds, cluster):
# type: (object, object, object) -> object
self.index = i self.index = i
self.cluster = cluster self.cluster = cluster
if len(preds) == 1 and len(preds[0].argtypes) == i: if len(preds) == 1 and len(preds[0].argtypes) == i:
@ -354,6 +360,7 @@ class DTree(object):
class YAPConstraintGeneratorBase(PredGenerator): class YAPConstraintGeneratorBase(PredGenerator):
def __init__(self, filename): def __init__(self, filename):
# type: (object) -> object
super(YAPConstraintGeneratorBase, self).__init__(filename) super(YAPConstraintGeneratorBase, self).__init__(filename)
self._classify() self._classify()
self._dtreefy() self._dtreefy()
@ -389,6 +396,7 @@ class YAPConstraintGeneratorBase(PredGenerator):
class YAPConstraintPrologGenerator(YAPConstraintGeneratorBase): class YAPConstraintPrologGenerator(YAPConstraintGeneratorBase):
def __init__(self, filename): def __init__(self, filename):
# type: (object) -> object
super(YAPConstraintPrologGenerator, self).__init__(filename) super(YAPConstraintPrologGenerator, self).__init__(filename)
def _prolog_clauses(self): def _prolog_clauses(self):
@ -410,6 +418,7 @@ class YAPConstraintPrologGenerator(YAPConstraintGeneratorBase):
class YAPConstraintCCGenerator(YAPConstraintGeneratorBase): class YAPConstraintCCGenerator(YAPConstraintGeneratorBase):
def __init__(self, filename): def __init__(self, filename):
# type: (object) -> object
super(YAPConstraintCCGenerator, self).__init__(filename) super(YAPConstraintCCGenerator, self).__init__(filename)
def _cc_descriptors(self): def _cc_descriptors(self):
@ -434,6 +443,7 @@ import sys
class OStream(object): class OStream(object):
def __init__(self, fd=sys.stdout): def __init__(self, fd=sys.stdout):
# type: (object) -> object
self.file = fd self.file = fd
self.column = 0 self.column = 0
@ -472,6 +482,7 @@ class PrologObject(object):
class PrologClause(PrologObject): class PrologClause(PrologObject):
def __init__(self, head, body): def __init__(self, head, body):
# type: (object, object) -> object
self.head = head self.head = head
self.body = body self.body = body
@ -486,6 +497,7 @@ class PrologClause(PrologObject):
class PrologLiteral(PrologObject): class PrologLiteral(PrologObject):
def __init__(self, lit): def __init__(self, lit):
# type: (object) -> object
self.literal = lit self.literal = lit
def pp(self, out, offset): def pp(self, out, offset):
@ -495,6 +507,7 @@ class PrologLiteral(PrologObject):
class PrologIF(PrologObject): class PrologIF(PrologObject):
def __init__(self, cond, left, right): def __init__(self, cond, left, right):
# type: (object, object, object) -> object
self.cond = cond self.cond = cond
self.left = left self.left = left
self.right = right self.right = right
@ -609,6 +622,7 @@ class YAPEnumPrologGenerator(object):
class CCDescriptor(object): class CCDescriptor(object):
def __init__(self, name, argtypes, api): def __init__(self, name, argtypes, api):
# type: (object, object, object) -> object
self.name = name self.name = name
self.argtypes = argtypes self.argtypes = argtypes
self.api = api self.api = api

View File

@ -6,6 +6,7 @@ from pyswip.easy import getList, registerForeign
class Notifier: class Notifier:
def __init__(self, fun): def __init__(self, fun):
# type: (object) -> object
self.fun = fun self.fun = fun
def notify(self, t): def notify(self, t):
@ -15,6 +16,7 @@ class Notifier:
class Tower: class Tower:
def __init__(self, N=3, interactive=False): def __init__(self, N=3, interactive=False):
# type: (object, object) -> object
"""N is the number of disks """N is the number of disks
""" """
self.N = N self.N = N

View File

@ -12,6 +12,7 @@ URL = "http://www.sudoku.org.uk/daily.asp"
class DailySudokuPuzzle(HTMLParser): class DailySudokuPuzzle(HTMLParser):
def __init__(self): def __init__(self):
# type: () -> object
self.puzzle = [] self.puzzle = []
self.__in_td = False self.__in_td = False
HTMLParser.__init__(self) HTMLParser.__init__(self)

View File

@ -22,6 +22,7 @@ from pyswip.core import *
class InvalidTypeError(TypeError): class InvalidTypeError(TypeError):
def __init__(self, *args): def __init__(self, *args):
# type: (object) -> object
type = args and args[0] or "Unknown" type = args and args[0] or "Unknown"
msg = "Term is expected to be of type: '%s'" % type msg = "Term is expected to be of type: '%s'" % type
Exception.__init__(self, msg, *args) Exception.__init__(self, msg, *args)
@ -31,6 +32,7 @@ class Atom(object):
__slots__ = "handle","chars" __slots__ = "handle","chars"
def __init__(self, handleOrChars): def __init__(self, handleOrChars):
# type: (object) -> object
"""Create an atom. """Create an atom.
``handleOrChars``: handle or string of the atom. ``handleOrChars``: handle or string of the atom.
""" """
@ -71,6 +73,7 @@ class Atom(object):
class Term(object): class Term(object):
__slots__ = "handle","chars","__value","a0" __slots__ = "handle","chars","__value","a0"
def __init__(self, handle=None, a0=None): def __init__(self, handle=None, a0=None):
# type: (object, object) -> object
if handle: if handle:
#self.handle = PL_copy_term_ref(handle) #self.handle = PL_copy_term_ref(handle)
self.handle = handle self.handle = handle
@ -89,6 +92,7 @@ class Variable(object):
__slots__ = "handle","chars" __slots__ = "handle","chars"
def __init__(self, handle=None, name=None): def __init__(self, handle=None, name=None):
# type: (object, object) -> object
self.chars = None self.chars = None
if name: if name:
self.chars = name self.chars = name
@ -147,6 +151,7 @@ class Functor(object):
func = {} func = {}
def __init__(self, handleOrName, arity=1, args=None, a0=None): def __init__(self, handleOrName, arity=1, args=None, a0=None):
# type: (object, object, object, object) -> object
"""Create a functor. """Create a functor.
``handleOrName``: functor handle, a string or an atom. ``handleOrName``: functor handle, a string or an atom.
""" """
@ -436,6 +441,7 @@ class Query(object):
fid = None fid = None
def __init__(self, *terms, **kwargs): def __init__(self, *terms, **kwargs):
# type: (object, object) -> object
for key in kwargs: for key in kwargs:
if key not in ["flags", "module"]: if key not in ["flags", "module"]:
raise Exception("Invalid kwarg: %s" % key, key) raise Exception("Invalid kwarg: %s" % key, key)

View File

@ -53,6 +53,7 @@ class Prolog:
__slots__ = "swipl_fid","swipl_qid","error" __slots__ = "swipl_fid","swipl_qid","error"
def __init__(self): def __init__(self):
# type: () -> object
self.error = False self.error = False
def __call__(self, query, maxresult, catcherrors, normalize): def __call__(self, query, maxresult, catcherrors, normalize):

View File

@ -18,7 +18,6 @@ else()
add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS}) add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
# arithmetic hassle. # arithmetic hassle.
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD 11)
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET Py4YAP PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES}) target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
@ -32,7 +31,6 @@ endif()
# arithmetic hassle. # arithmetic hassle.
set_property(TARGET YAPPython PROPERTY CXX_STANDARD 11)
set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES}) target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})

View File

@ -1233,6 +1233,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
Py_DECREF(o); Py_DECREF(o);
DebugPrintf("CallObject %p\n", rc); DebugPrintf("CallObject %p\n", rc);
return rc; return rc;
} }
} }

View File

@ -2,15 +2,15 @@
#include "py4yap.h" #include "py4yap.h"
X_API bool init_python_dll(void); O_API bool init_python_dll(void);
X_API bool init_python_dll(void) O_API bool init_python_dll(void) {
{
do_init_python(); do_init_python();
install_pypreds(); install_pypreds();
return 1; return 1;
} }
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>

View File

@ -1,11 +1,48 @@
import yap
import os.path import os.path
import sys import sys
# debugging support. # debugging support.
# import pdb # import pdb
from collections import namedtuple from collections import namedtuple
from yap import *
class Engine( YAPEngine ):
def __init__(self, args=None):
# type: (object) -> object
if not args:
args = YAPEngineArgs()
yap_lib_path = os.path.dirname(__file__)
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
args.setYapLibDir(yap_lib_path)
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
YAPEngine.__init__(self,args)
self.goal( set_prolog_flag('verbose', 'silent' ) )
self.goal( use_module(library('yapi') ) )
def run(self, g, m=None):
if m:
self.mgoal(g, m)
else:
self.goal(g)
def f(self, g):
self.E.fun(g)
class EngineArgs( YAPEngineArgs ):
""" Interface to Engine Options class"""
class Predicate( YAPPredicate ):
""" Interface to Generic Predicate"""
class PrologPredicate( YAPPrologPredicate ):
""" Interface to Prolog Predicate"""
global engine, handler global engine, handler
yap_lib_path = os.path.dirname(__file__) yap_lib_path = os.path.dirname(__file__)
@ -19,6 +56,7 @@ jupyter_query = namedtuple( 'jupyter_query', 'vars dict')
python_query = namedtuple( 'python_query', 'vars dict') python_query = namedtuple( 'python_query', 'vars dict')
yapi_query = namedtuple( 'yapi_query', 'vars dict') yapi_query = namedtuple( 'yapi_query', 'vars dict')
show_answer = namedtuple( 'show_answer', 'vars dict') show_answer = namedtuple( 'show_answer', 'vars dict')
set_prolog_flag = namedtuple('set_prolog_flag', 'flag new_value')
def v(): def v():
return yap.YAPVarTerm() return yap.YAPVarTerm()
@ -97,16 +135,6 @@ def query_prolog(engine, s):
q.close() q.close()
return return
def boot_yap(**kwargs):
yap_lib_path = os.path.dirname(__file__)
args = yap.YAPEngineArgs()
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
args.setYapLibDir(yap_lib_path)
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
engine = yap.YAPEngine(args)
engine.goal( use_module(library('yapi') ) )
return engine
def live(**kwargs): def live(**kwargs):
loop = True loop = True
while loop: while loop:

View File

@ -68,5 +68,5 @@
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap_kernel install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --no-index -f dist yap_kernel
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")
# install(FILES jupyter.yap # install(FILES jupyter.yap
# DESTINATION ${libpl} ) # DESTINATION ${libpl} )

View File

@ -28,6 +28,7 @@ from internal_yapkernel import InternalYAPKernel
class SimpleWindow(Qt.QWidget, InternalYAPKernel): class SimpleWindow(Qt.QWidget, InternalYAPKernel):
def __init__(self, app): def __init__(self, app):
# type: (object) -> object
Qt.QWidget.__init__(self) Qt.QWidget.__init__(self)
self.app = app self.app = app
self.add_widgets() self.add_widgets()

View File

@ -36,6 +36,7 @@ class MyFrame(wx.Frame, InternalYAPKernel):
""" """
def __init__(self, parent, title): def __init__(self, parent, title):
# type: (object, object) -> object
wx.Frame.__init__(self, parent, -1, title, wx.Frame.__init__(self, parent, -1, title,
pos=(150, 150), size=(350, 285)) pos=(150, 150), size=(350, 285))

View File

@ -85,10 +85,6 @@ if 'develop' in sys.argv or any(a.startswith('bdist') for a in sys.argv):
setuptools_args = {} setuptools_args = {}
install_requires = setuptools_args['install_requires'] = [ install_requires = setuptools_args['install_requires'] = [
'ipython>=4.0.0',
'traitlets>=4.1.0',
'jupyter_client',
'tornado>=4.0',
] ]
if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv): if any(a.startswith(('bdist', 'build', 'install')) for a in sys.argv):

View File

@ -48,6 +48,7 @@ class Comm(LoggingConfigurable):
_closed = Bool(True) _closed = Bool(True)
def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs): def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs):
# type: (object, object, object, object, object) -> object
if target_name: if target_name:
kwargs['target_name'] = target_name kwargs['target_name'] = target_name
super(Comm, self).__init__(**kwargs) super(Comm, self).__init__(**kwargs)

View File

@ -18,6 +18,7 @@ class ZMQDisplayHook(object):
topic = b'execute_result' topic = b'execute_result'
def __init__(self, session, pub_socket): def __init__(self, session, pub_socket):
# type: (object, object) -> object
self.session = session self.session = session
self.pub_socket = pub_socket self.pub_socket = pub_socket
self.parent_header = {} self.parent_header = {}

View File

@ -138,6 +138,7 @@ def loop_wx(kernel):
# We make the Frame hidden when we create it in the main app below. # We make the Frame hidden when we create it in the main app below.
class TimerFrame(wx.Frame): class TimerFrame(wx.Frame):
def __init__(self, func): def __init__(self, func):
# type: (object) -> object
wx.Frame.__init__(self, None, -1) wx.Frame.__init__(self, None, -1)
self.timer = wx.Timer(self) self.timer = wx.Timer(self)
# Units for the timer are in milliseconds # Units for the timer are in milliseconds
@ -184,6 +185,7 @@ def loop_tk(kernel):
# For Tkinter, we create a Tk object and call its withdraw method. # For Tkinter, we create a Tk object and call its withdraw method.
class Timer(object): class Timer(object):
def __init__(self, func): def __init__(self, func):
# type: (object) -> object
self.app = Tk() self.app = Tk()
self.app.withdraw() self.app.withdraw()
self.func = func self.func = func

View File

@ -27,6 +27,7 @@ class GTKEmbed(object):
"""A class to embed a kernel into the GTK main event loop. """A class to embed a kernel into the GTK main event loop.
""" """
def __init__(self, kernel): def __init__(self, kernel):
# type: (object) -> object
self.kernel = kernel self.kernel = kernel
# These two will later store the real gtk functions when we hijack them # These two will later store the real gtk functions when we hijack them
self.gtk_main = None self.gtk_main = None

View File

@ -25,6 +25,7 @@ class GTKEmbed(object):
"""A class to embed a kernel into the GTK main event loop. """A class to embed a kernel into the GTK main event loop.
""" """
def __init__(self, kernel): def __init__(self, kernel):
# type: (object) -> object
self.kernel = kernel self.kernel = kernel
# These two will later store the real gtk functions when we hijack them # These two will later store the real gtk functions when we hijack them
self.gtk_main = None self.gtk_main = None

View File

@ -30,6 +30,7 @@ class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread." "A simple ping-pong style heartbeat that runs in a thread."
def __init__(self, context, addr=None): def __init__(self, context, addr=None):
# type: (object, object) -> object
if addr is None: if addr is None:
addr = ('tcp', localhost(), 0) addr = ('tcp', localhost(), 0)
Thread.__init__(self) Thread.__init__(self)

View File

@ -27,6 +27,7 @@ from .client import InProcessKernelClient
class BlockingInProcessChannel(InProcessChannel): class BlockingInProcessChannel(InProcessChannel):
def __init__(self, *args, **kwds): def __init__(self, *args, **kwds):
# type: (object, object) -> object
super(BlockingInProcessChannel, self).__init__(*args, **kwds) super(BlockingInProcessChannel, self).__init__(*args, **kwds)
self._in_queue = Queue() self._in_queue = Queue()

View File

@ -16,6 +16,7 @@ class InProcessChannel(object):
proxy_methods = [] proxy_methods = []
def __init__(self, client=None): def __init__(self, client=None):
# type: (object) -> object
super(InProcessChannel, self).__init__() super(InProcessChannel, self).__init__()
self.client = client self.client = client
self._is_alive = False self._is_alive = False
@ -70,6 +71,7 @@ class InProcessHBChannel(object):
time_to_dead = 3.0 time_to_dead = 3.0
def __init__(self, client=None): def __init__(self, client=None):
# type: (object) -> object
super(InProcessHBChannel, self).__init__() super(InProcessHBChannel, self).__init__()
self.client = client self.client = client
self._is_alive = False self._is_alive = False

View File

@ -70,6 +70,7 @@ class InProcessKernel(YAPKernel):
stdin_socket = Instance(DummySocket, ()) stdin_socket = Instance(DummySocket, ())
def __init__(self, **traits): def __init__(self, **traits):
# type: (object) -> object
super(InProcessKernel, self).__init__(**traits) super(InProcessKernel, self).__init__(**traits)
self._underlying_iopub_socket.observe(self._io_dispatch, names=['message_sent']) self._underlying_iopub_socket.observe(self._io_dispatch, names=['message_sent'])

View File

@ -98,6 +98,7 @@ class YAPInteraction:
"""An enhanced, interactive shell for YAP.""" """An enhanced, interactive shell for YAP."""
def __init__(self, shell, **kwargs): def __init__(self, shell, **kwargs):
# type: (object, object) -> object
try: try:
if self.yapeng: if self.yapeng:
return return

View File

@ -43,6 +43,7 @@ class IOPubThread(object):
""" """
def __init__(self, socket, pipe=False): def __init__(self, socket, pipe=False):
# type: (object, object) -> object
"""Create IOPub thread """Create IOPub thread
Parameters Parameters
@ -220,6 +221,7 @@ class BackgroundSocket(object):
io_thread = None io_thread = None
def __init__(self, io_thread): def __init__(self, io_thread):
# type: (object) -> object
self.io_thread = io_thread self.io_thread = io_thread
def __getattr__(self, attr): def __getattr__(self, attr):
@ -261,6 +263,7 @@ class OutStream(TextIOBase):
encoding = 'UTF-8' encoding = 'UTF-8'
def __init__(self, session, pub_thread, name, pipe=None): def __init__(self, session, pub_thread, name, pipe=None):
# type: (object, object, object, object) -> object
if pipe is not None: if pipe is not None:
warnings.warn("pipe argument to OutStream is deprecated and ignored", warnings.warn("pipe argument to OutStream is deprecated and ignored",
DeprecationWarning) DeprecationWarning)

View File

@ -134,6 +134,7 @@ class Kernel(SingletonConfigurable):
control_msg_types = msg_types + ['clear_request', 'abort_request'] control_msg_types = msg_types + ['clear_request', 'abort_request']
def __init__(self, **kwargs): def __init__(self, **kwargs):
# type: (object) -> object
super(Kernel, self).__init__(**kwargs) super(Kernel, self).__init__(**kwargs)
# Build dict of handlers for message types # Build dict of handlers for message types

View File

@ -10,6 +10,7 @@ class EnginePUBHandler(PUBHandler):
engine=None engine=None
def __init__(self, engine, *args, **kwargs): def __init__(self, engine, *args, **kwargs):
# type: (object, object, object) -> object
PUBHandler.__init__(self,*args, **kwargs) PUBHandler.__init__(self,*args, **kwargs)
self.engine = engine self.engine = engine

View File

@ -25,6 +25,7 @@ class ParentPollerUnix(Thread):
""" """
def __init__(self): def __init__(self):
# type: () -> object
super(ParentPollerUnix, self).__init__() super(ParentPollerUnix, self).__init__()
self.daemon = True self.daemon = True
@ -50,6 +51,7 @@ class ParentPollerWindows(Thread):
""" """
def __init__(self, interrupt_handle=None, parent_handle=None): def __init__(self, interrupt_handle=None, parent_handle=None):
# type: (object, object) -> object
""" Create the poller. At least one of the optional parameters must be """ Create the poller. At least one of the optional parameters must be
provided. provided.

View File

@ -127,6 +127,7 @@ def use_cloudpickle():
class CannedObject(object): class CannedObject(object):
def __init__(self, obj, keys=[], hook=None): def __init__(self, obj, keys=[], hook=None):
# type: (object, object, object) -> object
"""can an object for safe pickling """can an object for safe pickling
Parameters Parameters
@ -167,6 +168,7 @@ class CannedObject(object):
class Reference(CannedObject): class Reference(CannedObject):
"""object for wrapping a remote reference by name.""" """object for wrapping a remote reference by name."""
def __init__(self, name): def __init__(self, name):
# type: (object) -> object
if not isinstance(name, string_types): if not isinstance(name, string_types):
raise TypeError("illegal name: %r"%name) raise TypeError("illegal name: %r"%name)
self.name = name self.name = name
@ -185,6 +187,7 @@ class Reference(CannedObject):
class CannedCell(CannedObject): class CannedCell(CannedObject):
"""Can a closure cell""" """Can a closure cell"""
def __init__(self, cell): def __init__(self, cell):
# type: (object) -> object
self.cell_contents = can(cell.cell_contents) self.cell_contents = can(cell.cell_contents)
def get_object(self, g=None): def get_object(self, g=None):
@ -197,6 +200,7 @@ class CannedCell(CannedObject):
class CannedFunction(CannedObject): class CannedFunction(CannedObject):
def __init__(self, f): def __init__(self, f):
# type: (object) -> object
self._check_type(f) self._check_type(f)
self.code = f.__code__ self.code = f.__code__
if f.__defaults__: if f.__defaults__:
@ -239,6 +243,7 @@ class CannedFunction(CannedObject):
class CannedClass(CannedObject): class CannedClass(CannedObject):
def __init__(self, cls): def __init__(self, cls):
# type: (object) -> object
self._check_type(cls) self._check_type(cls)
self.name = cls.__name__ self.name = cls.__name__
self.old_style = not isinstance(cls, type) self.old_style = not isinstance(cls, type)
@ -263,6 +268,7 @@ class CannedClass(CannedObject):
class CannedArray(CannedObject): class CannedArray(CannedObject):
def __init__(self, obj): def __init__(self, obj):
# type: (object) -> object
from numpy import ascontiguousarray from numpy import ascontiguousarray
self.shape = obj.shape self.shape = obj.shape
self.dtype = obj.dtype.descr if obj.dtype.fields else obj.dtype.str self.dtype = obj.dtype.descr if obj.dtype.fields else obj.dtype.str
@ -300,6 +306,7 @@ class CannedBytes(CannedObject):
wrap = staticmethod(buffer_to_bytes) wrap = staticmethod(buffer_to_bytes)
def __init__(self, obj): def __init__(self, obj):
# type: (object) -> object
self.buffers = [obj] self.buffers = [obj]
def get_object(self, g=None): def get_object(self, g=None):

View File

@ -61,6 +61,7 @@ class Reference(HasTraits):
class Version(Unicode): class Version(Unicode):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# type: (object, object) -> object
self.min = kwargs.pop('min', None) self.min = kwargs.pop('min', None)
self.max = kwargs.pop('max', None) self.max = kwargs.pop('max', None)
kwargs['default_value'] = self.min kwargs['default_value'] = self.min

View File

@ -35,6 +35,7 @@ class YAPKernel(KernelBase):
_sys_eval_input = Any() _sys_eval_input = Any()
def __init__(self, **kwargs): def __init__(self, **kwargs):
# type: (object) -> object
super(YAPKernel, self).__init__(**kwargs) super(YAPKernel, self).__init__(**kwargs)
# Initialize the InteractiveShell subclass # Initialize the InteractiveShell subclass
@ -376,6 +377,7 @@ class YAPKernel(KernelBase):
class Kernel(YAPKernel): class Kernel(YAPKernel):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# type: (object, object) -> object
import warnings import warnings
warnings.warn('Kernel is a deprecated alias of yap_kernel.yapkernel.YAPKernel', warnings.warn('Kernel is a deprecated alias of yap_kernel.yapkernel.YAPKernel',
DeprecationWarning) DeprecationWarning)

View File

@ -950,4 +950,4 @@ prolog:message( r_root ) -->
:- initialization( set_prolog_flag( double_quotes, string) ). :- initialization( set_prolog_flag( double_quotes, string) ).
@} %%% @}