Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap
This commit is contained in:
commit
644606d8bb
1
.gitignore
vendored
1
.gitignore
vendored
@ -215,3 +215,4 @@ cmake/docs/Doxyfile
|
|||||||
|
|
||||||
*.stackdump
|
*.stackdump
|
||||||
*.gz
|
*.gz
|
||||||
|
.Rproj.user
|
||||||
|
@ -1142,6 +1142,8 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
|
|||||||
// if (pe->PredFlags & CArgsPredFlag) {
|
// if (pe->PredFlags & CArgsPredFlag) {
|
||||||
// CurrentModule = pe->ModuleOfPred;
|
// CurrentModule = pe->ModuleOfPred;
|
||||||
//}
|
//}
|
||||||
|
int lvl = push_text_stack();
|
||||||
|
yhandle_t hdl = Yap_CurrentHandle();
|
||||||
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;
|
||||||
@ -1161,12 +1163,15 @@ X_API Int YAP_Execute(PredEntry *pe, CPredicate exec_code) {
|
|||||||
// 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();
|
||||||
}
|
}
|
||||||
|
Yap_RecoverHandles(0, hdl);
|
||||||
|
pop_text_stack( lvl );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1739,17 +1744,18 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
PredEntry *pe = ape;
|
PredEntry *pe = ape;
|
||||||
bool out;
|
bool out;
|
||||||
// fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
// fprintf(stderr,"1EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
||||||
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
dgi->lvl = push_text_stack();
|
||||||
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
|
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
dgi->p = P;
|
dgi->p = P;
|
||||||
dgi->cp = CP;
|
dgi->cp = CP;
|
||||||
dgi->b0 = LCL0 - (CELL *)B;
|
dgi->b0 = LCL0 - (CELL *)B;
|
||||||
dgi->CurSlot = LOCAL_CurSlot;
|
dgi->env0 = LCL0 - ENV;
|
||||||
// ensure our current ENV receives current P.
|
// ensure our current ENV receives current P.
|
||||||
|
|
||||||
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS);
|
Yap_PrepGoal(pe->ArityOfPE, nullptr, B PASS_REGS);
|
||||||
@ -1757,7 +1763,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, 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_entry = LCL0 - (CELL *)B;
|
||||||
dgi->h = HR - H0;
|
dgi->h = HR - H0;
|
||||||
dgi->tr = (CELL *)TR - LCL0;
|
dgi->tr = (CELL *)TR - LCL0;
|
||||||
// fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
// fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
|
||||||
@ -1766,7 +1772,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
|
|||||||
// fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
// fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
||||||
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
dgi->b = LCL0 - (CELL *)B;
|
dgi->b_exit = LCL0 - (CELL *)B;
|
||||||
if (out) {
|
if (out) {
|
||||||
dgi->EndSlot = LOCAL_CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
Yap_StartSlots();
|
Yap_StartSlots();
|
||||||
@ -1774,6 +1780,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
|
|||||||
LOCAL_CurSlot =
|
LOCAL_CurSlot =
|
||||||
dgi->CurSlot; // ignore any slots created within the called goal
|
dgi->CurSlot; // ignore any slots created within the called goal
|
||||||
}
|
}
|
||||||
|
pop_text_stack(dgi->lvl);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -1784,8 +1791,9 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
|||||||
bool out;
|
bool out;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
myB = (choiceptr)(LCL0 - dgi->b);
|
dgi->lvl = push_text_stack();
|
||||||
myB0 = (choiceptr)(LCL0 - dgi->b0);
|
myB = (choiceptr)(LCL0 - dgi->b_exit);
|
||||||
|
myB0 = (choiceptr)(LCL0 - dgi->b_entry);
|
||||||
CP = myB->cp_cp;
|
CP = myB->cp_cp;
|
||||||
/* sanity check */
|
/* sanity check */
|
||||||
if (B >= myB0) {
|
if (B >= myB0) {
|
||||||
@ -1804,50 +1812,47 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
|||||||
out = Yap_exec_absmi(true, true );
|
out = Yap_exec_absmi(true, true );
|
||||||
if (out) {
|
if (out) {
|
||||||
dgi->EndSlot = LOCAL_CurSlot;
|
dgi->EndSlot = LOCAL_CurSlot;
|
||||||
dgi->b = LCL0 - (CELL *)B;
|
dgi->b_exit = LCL0 - (CELL *)B;
|
||||||
} else {
|
} else {
|
||||||
|
printf("F %ld\n", dgi->CurSlot);
|
||||||
LOCAL_CurSlot =
|
LOCAL_CurSlot =
|
||||||
dgi->CurSlot; // ignore any slots created within the called goal
|
dgi->CurSlot; // ignore any slots created within the called goal
|
||||||
}
|
}
|
||||||
|
pop_text_stack(dgi->lvl);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
choiceptr myB, handler;
|
|
||||||
|
|
||||||
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
|
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
|
||||||
// P=%p CP=%p Slots=%d\n",
|
// P=%p CP=%p Slots=%d\n",
|
||||||
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
|
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
|
||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
myB = (choiceptr)(LCL0 - dgi->b);
|
|
||||||
if (LOCAL_PrologMode & AsyncIntMode) {
|
dgi->lvl = push_text_stack();
|
||||||
Yap_signal(YAP_FAIL_SIGNAL);
|
|
||||||
}
|
|
||||||
handler = B;
|
|
||||||
while (handler &&
|
|
||||||
LCL0 - LOCAL_CBorder > (CELL *)handler
|
|
||||||
//&& handler->cp_ap != NOCODE
|
|
||||||
&& handler->cp_b != NULL && handler != myB) {
|
|
||||||
if (handler < myB) {
|
|
||||||
handler->cp_ap = TRUSTFAILCODE;
|
|
||||||
}
|
|
||||||
B = handler;
|
|
||||||
handler = handler->cp_b;
|
|
||||||
if (successful) {
|
if (successful) {
|
||||||
|
choiceptr nB = (choiceptr)(LCL0 - dgi->b_entry);
|
||||||
|
if (B <= nB) {
|
||||||
|
B = nB;
|
||||||
|
}
|
||||||
Yap_TrimTrail();
|
Yap_TrimTrail();
|
||||||
} else if (!(LOCAL_PrologMode & AsyncIntMode)) {
|
B = B->cp_b;
|
||||||
P = FAILCODE;
|
} else if (LOCAL_PrologMode & AsyncIntMode) {
|
||||||
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (LOCAL_PrologMode & AsyncIntMode) {
|
|
||||||
Yap_signal(YAP_FAIL_SIGNAL);
|
Yap_signal(YAP_FAIL_SIGNAL);
|
||||||
}
|
}
|
||||||
|
B = (choiceptr)(LCL0 - dgi->b0);
|
||||||
|
#ifdef DEPTH_LIMIT
|
||||||
|
DEPTH = B->cp_depth;
|
||||||
|
#endif
|
||||||
P = dgi->p;
|
P = dgi->p;
|
||||||
CP = dgi->cp;
|
CP = dgi->cp;
|
||||||
|
YENV = ENV = LCL0-dgi->env0;
|
||||||
|
LOCAL_CurSlot =
|
||||||
|
dgi->CurSlot; // ignore any slots created within the called goal
|
||||||
|
pop_text_stack(dgi->lvl);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
// fprintf(stderr," LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
// fprintf(stderr," LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
|
||||||
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
|
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
|
||||||
@ -1861,6 +1866,8 @@ X_API Int YAP_RunGoal(Term t) {
|
|||||||
yhandle_t cslot = LOCAL_CurSlot;
|
yhandle_t cslot = LOCAL_CurSlot;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
|
||||||
|
int lvl = push_text_stack();
|
||||||
|
|
||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
out = Yap_RunTopGoal(t, true);
|
out = Yap_RunTopGoal(t, true);
|
||||||
@ -1869,6 +1876,7 @@ X_API Int YAP_RunGoal(Term t) {
|
|||||||
// We'll pass it through
|
// We'll pass it through
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
LOCAL_CurSlot = cslot;
|
LOCAL_CurSlot = cslot;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1942,11 +1950,12 @@ X_API CELL *YAP_HeapStoreOpaqueTerm(Term t) {
|
|||||||
X_API Int YAP_RunGoalOnce(Term t) {
|
X_API Int YAP_RunGoalOnce(Term t) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term out;
|
Term out;
|
||||||
yamop *old_CP = CP;
|
yamop *old_CP = CP, *old_P = P;
|
||||||
Int oldPrologMode = LOCAL_PrologMode;
|
Int oldPrologMode = LOCAL_PrologMode;
|
||||||
yhandle_t CSlot;
|
yhandle_t CSlot;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
int lvl = push_text_stack();
|
||||||
CSlot = Yap_StartSlots();
|
CSlot = Yap_StartSlots();
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
// Yap_heap_regs->yap_do_low_level_trace=true;
|
// Yap_heap_regs->yap_do_low_level_trace=true;
|
||||||
@ -1955,6 +1964,7 @@ X_API Int YAP_RunGoalOnce(Term t) {
|
|||||||
// Yap_CloseSlots(CSlot);
|
// Yap_CloseSlots(CSlot);
|
||||||
if (!(oldPrologMode & UserCCallMode)) {
|
if (!(oldPrologMode & UserCCallMode)) {
|
||||||
/* called from top-level */
|
/* called from top-level */
|
||||||
|
pop_text_stack( lvl);
|
||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return out;
|
return out;
|
||||||
@ -1989,13 +1999,14 @@ X_API Int YAP_RunGoalOnce(Term t) {
|
|||||||
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_LIMIT
|
||||||
DEPTH = ASP[E_DEPTH];
|
DEPTH = ASP[E_DEPTH];
|
||||||
#endif
|
#endif
|
||||||
P = (yamop *)ASP[E_CP];
|
P = old_P;
|
||||||
CP = old_CP;
|
CP = old_CP;
|
||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
|
pop_text_stack( lvl);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2078,7 +2089,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_entry);
|
||||||
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)) {
|
||||||
@ -2271,6 +2282,7 @@ X_API char *YAP_WriteBuffer(Term t, char *buf, size_t sze, int flags) {
|
|||||||
} else {
|
} else {
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
if (buf == out.val.c) {
|
if (buf == out.val.c) {
|
||||||
|
pop_text_stack(l);
|
||||||
return buf;
|
return buf;
|
||||||
} else {
|
} else {
|
||||||
if ( strlen(out.val.c ) < sze) {
|
if ( strlen(out.val.c ) < sze) {
|
||||||
|
12
C/exec.c
12
C/exec.c
@ -804,11 +804,11 @@ static Int execute_in_mod(USES_REGS1) { /* '$execute'(Goal) */
|
|||||||
static void prune_inner_computation(choiceptr parent) {
|
static void prune_inner_computation(choiceptr parent) {
|
||||||
/* code */
|
/* code */
|
||||||
choiceptr cut_pt;
|
choiceptr cut_pt;
|
||||||
yamop *oP = P, *oCP = CP;
|
|
||||||
Int oENV = LCL0 - ENV;
|
|
||||||
|
|
||||||
cut_pt = B;
|
cut_pt = B;
|
||||||
while (cut_pt && cut_pt->cp_b < parent) {
|
while (cut_pt && cut_pt->cp_b < parent) {
|
||||||
|
if (cut_pt->cp_ap == NOCODE)
|
||||||
|
break;
|
||||||
cut_pt = cut_pt->cp_b;
|
cut_pt = cut_pt->cp_b;
|
||||||
}
|
}
|
||||||
if (!cut_pt)
|
if (!cut_pt)
|
||||||
@ -819,9 +819,6 @@ static void prune_inner_computation(choiceptr parent) {
|
|||||||
B = cut_pt;
|
B = cut_pt;
|
||||||
Yap_TrimTrail();
|
Yap_TrimTrail();
|
||||||
LOCAL_AllowRestart = FALSE;
|
LOCAL_AllowRestart = FALSE;
|
||||||
P = oP;
|
|
||||||
CP = oCP;
|
|
||||||
ENV = LCL0 - oENV;
|
|
||||||
B = parent;
|
B = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1062,8 +1059,6 @@ static Int cleanup_on_exit(USES_REGS1) {
|
|||||||
complete_pt[0] = TermExit;
|
complete_pt[0] = TermExit;
|
||||||
}
|
}
|
||||||
Yap_ignore(cleanup, false);
|
Yap_ignore(cleanup, false);
|
||||||
if (B0->cp_ap == NOCODE)
|
|
||||||
B0->cp_ap = TRUSTFAILCODE;
|
|
||||||
if (Yap_RaiseException()) {
|
if (Yap_RaiseException()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1617,7 +1612,6 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
|||||||
CalculateStackGap(PASS_REGS1);
|
CalculateStackGap(PASS_REGS1);
|
||||||
LOCAL_CBorder = OldBorder;
|
LOCAL_CBorder = OldBorder;
|
||||||
LOCAL_RestartEnv = sighold;
|
LOCAL_RestartEnv = sighold;
|
||||||
pop_text_stack(i + 1);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2272,7 +2266,7 @@ void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
|
|||||||
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
|
REMOTE_AttsMutableList(myworker_id) = Yap_NewTimedVar(h0var);
|
||||||
#endif
|
#endif
|
||||||
size_t defsz = 128*1024;
|
size_t defsz = 128*1024;
|
||||||
Yap_AllocateDefaultArena(defsz, myworker_id);
|
Yap_AllocateDefaultArena(defsz, myworker_id, NULL);
|
||||||
} else {
|
} else {
|
||||||
HR = Yap_ArenaLimit(REMOTE_GlobalArena(myworker_id));
|
HR = Yap_ArenaLimit(REMOTE_GlobalArena(myworker_id));
|
||||||
}
|
}
|
||||||
|
265
C/globals.c
265
C/globals.c
@ -78,7 +78,7 @@ assert/1 or recorda/3.
|
|||||||
+ The value lives on the Prolog (global) stack. This implies
|
+ The value lives on the Prolog (global) stack. This implies
|
||||||
that lookup time is independent from the size of the term.
|
that lookup time is independent from the size of the term.
|
||||||
This is particulary interesting for large data structures
|
This is particulary interesting for large data structures
|
||||||
such as parsed XML documents or the CHR global constraint
|
qqqsuch as parsed XML documents or the CHR global constraint
|
||||||
store.
|
store.
|
||||||
|
|
||||||
They support both global assignment using nb_setval/2 and
|
They support both global assignment using nb_setval/2 and
|
||||||
@ -139,6 +139,26 @@ threads that are created <em>after</em> the registration.
|
|||||||
#define HEAP_ARENA 2
|
#define HEAP_ARENA 2
|
||||||
#define HEAP_START 3
|
#define HEAP_START 3
|
||||||
|
|
||||||
|
/// A cell_space is a short code region, where we want bindings to proceed locally.
|
||||||
|
/// It is used in copy_term,,,,,,,,,,,,,,,,,,,,,,,
|
||||||
|
///
|
||||||
|
typedef struct cell_space {
|
||||||
|
struct cell_space *parent; //`
|
||||||
|
CELL *oASP, *oH, *oHB;
|
||||||
|
} cell_space_t;
|
||||||
|
|
||||||
|
INLINE_ONLY void enter_cell_space(cell_space_t *cs) {
|
||||||
|
cs->oH = HR;
|
||||||
|
cs->oHB = HB;
|
||||||
|
cs->oASP = ASP;
|
||||||
|
}
|
||||||
|
|
||||||
|
INLINE_ONLY void exit_cell_space(cell_space_t *cs) {
|
||||||
|
HR = cs->oH;
|
||||||
|
HB = cs->oHB;
|
||||||
|
ASP = cs->oASP;
|
||||||
|
}
|
||||||
|
|
||||||
#define MIN_ARENA_SIZE (1048L)
|
#define MIN_ARENA_SIZE (1048L)
|
||||||
|
|
||||||
#define MAX_ARENA_SIZE (2048 * 16)
|
#define MAX_ARENA_SIZE (2048 * 16)
|
||||||
@ -186,33 +206,37 @@ static Term CreateNewArena(CELL *ptr, UInt size) {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term NewArena(UInt size, int wid, UInt arity, CELL *where) {
|
static Term NewArena(UInt size, int wid, UInt arity, CELL *where, struct cell_space *cellSpace) {
|
||||||
Term t;
|
Term t;
|
||||||
UInt new_size;
|
UInt new_size;
|
||||||
WORKER_REGS(wid)
|
WORKER_REGS(wid)
|
||||||
|
exit_cell_space(cellSpace);
|
||||||
if (where == NULL || where == HR) {
|
// make sure we have enough room
|
||||||
while (HR + size > ASP - 1024) {
|
while (HR + size > ASP - MIN_ARENA_SIZE) {
|
||||||
if (!Yap_gcl(size * sizeof(CELL), arity, ENV, P)) {
|
if (!Yap_gcl(size * sizeof(CELL), arity, ENV, P)) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_ThrowError(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (where == NULL || where == HR) {
|
||||||
t = CreateNewArena(HR, size);
|
t = CreateNewArena(HR, size);
|
||||||
HR += size;
|
HR += size;
|
||||||
|
new_size = size;
|
||||||
} else {
|
} else {
|
||||||
if ((new_size = Yap_InsertInGlobal(where, size * sizeof(CELL))) == 0) {
|
if ((new_size = Yap_InsertInGlobal(where, size * sizeof(CELL))) == 0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil,
|
Yap_ThrowError(RESOURCE_ERROR_STACK, TermNil,
|
||||||
"No Stack Space for Non-Backtrackable terms");
|
"No Stack Space for Non-Backtrackable terms");
|
||||||
return TermNil;
|
return TermNil;
|
||||||
}
|
}
|
||||||
size = new_size / sizeof(CELL);
|
size = new_size / sizeof(CELL);
|
||||||
t = CreateNewArena(where, size);
|
t = CreateNewArena(where, size);
|
||||||
}
|
}
|
||||||
|
enter_cell_space(cellSpace);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_allocate_arena(USES_REGS1) {
|
static Int p_allocate_arena(USES_REGS1) {
|
||||||
|
cell_space_t cspace;
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, t, "allocate_arena");
|
Yap_Error(INSTANTIATION_ERROR, t, "allocate_arena");
|
||||||
@ -221,15 +245,21 @@ static Int p_allocate_arena(USES_REGS1) {
|
|||||||
Yap_Error(TYPE_ERROR_INTEGER, t, "allocate_arena");
|
Yap_Error(TYPE_ERROR_INTEGER, t, "allocate_arena");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return Yap_unify(ARG2, NewArena(IntegerOfTerm(t), worker_id, 1, NULL));
|
enter_cell_space(&cspace);
|
||||||
|
return Yap_unify(ARG2, NewArena(IntegerOfTerm(t), worker_id, 1, NULL, &cspace));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_default_arena_size(USES_REGS1) {
|
static Int p_default_arena_size(USES_REGS1) {
|
||||||
return Yap_unify(ARG1, MkIntegerTerm(ArenaSz(LOCAL_GlobalArena)));
|
return Yap_unify(ARG1, MkIntegerTerm(ArenaSz(LOCAL_GlobalArena)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_AllocateDefaultArena(size_t gsize, int wid) {
|
void Yap_AllocateDefaultArena(size_t gsize, int wid, void *cs) {
|
||||||
REMOTE_GlobalArena(wid) = NewArena(gsize, wid, 2, NULL);
|
cell_space_t ics;
|
||||||
|
if (cs == NULL) {
|
||||||
|
enter_cell_space(&ics);
|
||||||
|
cs = &ics;
|
||||||
|
}
|
||||||
|
REMOTE_GlobalArena(wid) = NewArena(gsize, wid, 2, NULL, cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void adjust_cps(UInt size USES_REGS) {
|
static void adjust_cps(UInt size USES_REGS) {
|
||||||
@ -241,8 +271,9 @@ static void adjust_cps(UInt size USES_REGS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GrowArena(Term arena, CELL *pt, size_t old_size, size_t size,
|
static Term GrowArena(Term arena, CELL *pt, size_t old_size, size_t size,
|
||||||
UInt arity USES_REGS) {
|
UInt arity, cell_space_t *cspace USES_REGS) {
|
||||||
|
size_t sz;
|
||||||
LOCAL_ArenaOverflows++;
|
LOCAL_ArenaOverflows++;
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
if (old_size < 128 * 1024) {
|
if (old_size < 128 * 1024) {
|
||||||
@ -251,59 +282,52 @@ static int GrowArena(Term arena, CELL *pt, size_t old_size, size_t size,
|
|||||||
size = old_size + 128 * 1024;
|
size = old_size + 128 * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (size < 4096) {
|
if (size < 4*MIN_ARENA_SIZE) {
|
||||||
size = 4096;
|
size = 4*MIN_ARENA_SIZE;
|
||||||
}
|
}
|
||||||
if (pt == HR) {
|
exit_cell_space(cspace);
|
||||||
if (HR + size > ASP - 1024) {
|
while (HR + size > ASP - MIN_ARENA_SIZE) {
|
||||||
|
|
||||||
XREGS[arity + 1] = arena;
|
XREGS[arity + 1] = arena;
|
||||||
if (!Yap_gcl(size * sizeof(CELL), arity + 1, ENV, gc_P(P, CP))) {
|
if (!Yap_gcl(size * sizeof(CELL), arity + 1, ENV, gc_P(P, CP))) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
arena = XREGS[arity + 1];
|
arena = XREGS[arity + 1];
|
||||||
/* we don't know if the GC added junk on top of the global */
|
|
||||||
pt = ArenaLimit(arena);
|
|
||||||
return GrowArena(arena, pt, old_size, size, arity PASS_REGS);
|
|
||||||
}
|
|
||||||
adjust_cps(size PASS_REGS);
|
adjust_cps(size PASS_REGS);
|
||||||
HR += size;
|
}
|
||||||
|
pt = ArenaLimit(arena)+1;
|
||||||
|
sz = old_size + size;
|
||||||
|
if (pt == HR) {
|
||||||
|
HR += size+1;
|
||||||
|
HR[ - 1] = EndSpecials;
|
||||||
} else {
|
} else {
|
||||||
XREGS[arity + 1] = arena;
|
if ((sz = Yap_InsertInGlobal(pt, size * sizeof(CELL))) == 0) {
|
||||||
/* try to recover some room */
|
|
||||||
Yap_gcl(size * sizeof(CELL), arity + 1, ENV, gc_P(P, CP));
|
|
||||||
arena = XREGS[arity + 1];
|
|
||||||
pt = ArenaLimit(arena);
|
|
||||||
if ((size = Yap_InsertInGlobal(pt, size * sizeof(CELL))) == 0) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
size = size / sizeof(CELL);
|
pt[size-1] = EndSpecials;
|
||||||
arena = XREGS[arity + 1];
|
|
||||||
}
|
}
|
||||||
CreateNewArena(ArenaPt(arena), size + old_size);
|
arena = XREGS[arity + 1];
|
||||||
return TRUE;
|
MP_INT *dst = (MP_INT *)(RepAppl(arena) + 2);
|
||||||
|
dst->_mp_alloc+= size;
|
||||||
|
arena = XREGS[arity + 1];
|
||||||
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) {
|
CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
restart : {
|
|
||||||
Term arena = *arenap;
|
Term arena = *arenap;
|
||||||
CELL *max = ArenaLimit(arena);
|
CELL *max = ArenaLimit(arena);
|
||||||
CELL *base = ArenaPt(arena);
|
CELL *base = ArenaPt(arena);
|
||||||
CELL *newH;
|
CELL *newH;
|
||||||
UInt old_sz = ArenaSz(arena), new_size;
|
UInt old_sz = ArenaSz(arena), new_size;
|
||||||
|
while(true) {
|
||||||
if (IN_BETWEEN(base, HR, max)) {
|
if (IN_BETWEEN(base, HR, max)) {
|
||||||
base = HR;
|
base = HR;
|
||||||
HR += cells;
|
HR += cells;
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
if (base + cells > max - 1024) {
|
if (base + cells > ASP - 1024) {
|
||||||
if (!GrowArena(arena, max, old_sz, old_sz + sizeof(CELL) * 1024,
|
continue;
|
||||||
arity PASS_REGS))
|
|
||||||
return NULL;
|
|
||||||
goto restart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newH = base + cells;
|
newH = base + cells;
|
||||||
@ -313,17 +337,15 @@ restart : {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CloseArena(CELL *oldH, CELL *oldHB, CELL *oldASP, Term *oldArenaP,
|
static void CloseArena(cell_space_t *region, Term *oldArenaP,
|
||||||
UInt old_size USES_REGS) {
|
UInt old_size USES_REGS) {
|
||||||
UInt new_size;
|
UInt new_size;
|
||||||
|
|
||||||
if (HR == oldH)
|
if (HR == region->oH)
|
||||||
return;
|
return;
|
||||||
new_size = old_size - (HR - RepAppl(*oldArenaP));
|
new_size = old_size - (HR - RepAppl(*oldArenaP));
|
||||||
*oldArenaP = CreateNewArena(HR, new_size);
|
*oldArenaP = CreateNewArena(HR, new_size);
|
||||||
HR = oldH;
|
exit_cell_space( region );
|
||||||
HB = oldHB;
|
|
||||||
ASP = oldASP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
|
static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
|
||||||
@ -474,6 +496,8 @@ loop:
|
|||||||
HR += ap2[1] + 3;
|
HR += ap2[1] + 3;
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
|
|
||||||
|
|
||||||
/* big int */
|
/* big int */
|
||||||
UInt sz = (sizeof(MP_INT) + 3 * CellSize +
|
UInt sz = (sizeof(MP_INT) + 3 * CellSize +
|
||||||
((MP_INT *)(ap2 + 2))->_mp_alloc * sizeof(mp_limb_t)) /
|
((MP_INT *)(ap2 + 2))->_mp_alloc * sizeof(mp_limb_t)) /
|
||||||
@ -494,6 +518,7 @@ loop:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*ptf = AbsAppl(HR);
|
*ptf = AbsAppl(HR);
|
||||||
|
|
||||||
ptf++;
|
ptf++;
|
||||||
/* store the terms to visit */
|
/* store the terms to visit */
|
||||||
#ifdef RATIONAL_TREES
|
#ifdef RATIONAL_TREES
|
||||||
@ -643,9 +668,8 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
UInt arity, Term *newarena,
|
UInt arity, Term *newarena,
|
||||||
size_t min_grow USES_REGS) {
|
size_t min_grow USES_REGS) {
|
||||||
size_t old_size = ArenaSz(arena);
|
size_t old_size = ArenaSz(arena);
|
||||||
CELL *oldH = HR;
|
cell_space_t cspace;
|
||||||
CELL *oldHB = HB;
|
enter_cell_space( & cspace);
|
||||||
CELL *oldASP = ASP;
|
|
||||||
int res = 0;
|
int res = 0;
|
||||||
Term tn;
|
Term tn;
|
||||||
|
|
||||||
@ -664,12 +688,12 @@ restart:
|
|||||||
if ((res = copy_complex_term(Hi - 2, Hi - 1, share, copy_att_vars, Hi,
|
if ((res = copy_complex_term(Hi - 2, Hi - 1, share, copy_att_vars, Hi,
|
||||||
Hi PASS_REGS)) < 0)
|
Hi PASS_REGS)) < 0)
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return Hi[0];
|
return Hi[0];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (share && VarOfTerm(t) > ArenaPt(arena)) {
|
if (share && VarOfTerm(t) > ArenaPt(arena)) {
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
tn = MkVarTerm();
|
tn = MkVarTerm();
|
||||||
@ -677,7 +701,7 @@ restart:
|
|||||||
res = -1;
|
res = -1;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return tn;
|
return tn;
|
||||||
} else if (IsAtomOrIntTerm(t)) {
|
} else if (IsAtomOrIntTerm(t)) {
|
||||||
return t;
|
return t;
|
||||||
@ -699,7 +723,7 @@ restart:
|
|||||||
Hi PASS_REGS)) < 0) {
|
Hi PASS_REGS)) < 0) {
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
} else {
|
} else {
|
||||||
Functor f;
|
Functor f;
|
||||||
@ -720,7 +744,7 @@ restart:
|
|||||||
if (IsExtensionFunctor(f)) {
|
if (IsExtensionFunctor(f)) {
|
||||||
switch ((CELL)f) {
|
switch ((CELL)f) {
|
||||||
case (CELL) FunctorDBRef:
|
case (CELL) FunctorDBRef:
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return t;
|
return t;
|
||||||
case (CELL) FunctorLongInt:
|
case (CELL) FunctorLongInt:
|
||||||
if (HR > ASP - (MIN_ARENA_SIZE + 3)) {
|
if (HR > ASP - (MIN_ARENA_SIZE + 3)) {
|
||||||
@ -779,25 +803,23 @@ restart:
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
error_handler:
|
error_handler:
|
||||||
HR = HB;
|
HR = HB;
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cspace, newarena, old_size PASS_REGS);
|
||||||
XREGS[arity + 1] = t;
|
XREGS[arity + 1] = t;
|
||||||
XREGS[arity + 2] = arena;
|
XREGS[arity + 2] = arena;
|
||||||
XREGS[arity + 3] = (CELL)newarena;
|
XREGS[arity + 3] = (CELL)newarena;
|
||||||
{
|
{
|
||||||
CELL *old_top = ArenaLimit(*newarena);
|
CELL *old_top = ArenaLimit(*newarena);
|
||||||
ASP = oldASP;
|
exit_cell_space(&cspace);
|
||||||
HR = oldH;
|
|
||||||
HB = oldHB;
|
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case -1:
|
case -1:
|
||||||
if (arena == LOCAL_GlobalArena)
|
if (arena == LOCAL_GlobalArena)
|
||||||
LOCAL_GlobalArenaOverflows++;
|
LOCAL_GlobalArenaOverflows++;
|
||||||
if (!GrowArena(arena, old_top, old_size, min_grow, arity + 3 PASS_REGS)) {
|
if ((arena=GrowArena(arena, old_top, old_size, min_grow, arity + 3, &cspace PASS_REGS))==0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
@ -807,9 +829,7 @@ error_handler:
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
oldASP = ASP;
|
|
||||||
newarena = (CELL *)XREGS[arity + 3];
|
newarena = (CELL *)XREGS[arity + 3];
|
||||||
arena = Deref(XREGS[arity + 2]);
|
arena = Deref(XREGS[arity + 2]);
|
||||||
t = XREGS[arity + 1];
|
t = XREGS[arity + 1];
|
||||||
@ -819,10 +839,9 @@ error_handler:
|
|||||||
|
|
||||||
static Term CreateTermInArena(Term arena, Atom Na, UInt Nar, UInt arity,
|
static Term CreateTermInArena(Term arena, Atom Na, UInt Nar, UInt arity,
|
||||||
Term *newarena, Term init USES_REGS) {
|
Term *newarena, Term init USES_REGS) {
|
||||||
|
cell_space_t cells;
|
||||||
UInt old_size = ArenaSz(arena);
|
UInt old_size = ArenaSz(arena);
|
||||||
CELL *oldH = HR;
|
enter_cell_space(&cells);
|
||||||
CELL *oldHB = HB;
|
|
||||||
CELL *oldASP = ASP;
|
|
||||||
Term tf;
|
Term tf;
|
||||||
CELL *HB0;
|
CELL *HB0;
|
||||||
Functor f = Yap_MkFunctor(Na, Nar);
|
Functor f = Yap_MkFunctor(Na, Nar);
|
||||||
@ -838,26 +857,20 @@ restart:
|
|||||||
if (HR > ASP - MIN_ARENA_SIZE) {
|
if (HR > ASP - MIN_ARENA_SIZE) {
|
||||||
/* overflow */
|
/* overflow */
|
||||||
HR = HB;
|
HR = HB;
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cells, newarena, old_size PASS_REGS);
|
||||||
XREGS[arity + 1] = arena;
|
XREGS[arity + 1] = arena;
|
||||||
XREGS[arity + 2] = (CELL)newarena;
|
XREGS[arity + 2] = (CELL)newarena;
|
||||||
{
|
{
|
||||||
CELL *old_top = ArenaLimit(*newarena);
|
CELL *old_top = ArenaLimit(*newarena);
|
||||||
ASP = oldASP;
|
|
||||||
HR = oldH;
|
|
||||||
HB = oldHB;
|
|
||||||
if (arena == LOCAL_GlobalArena)
|
if (arena == LOCAL_GlobalArena)
|
||||||
LOCAL_GlobalArenaOverflows++;
|
LOCAL_GlobalArenaOverflows++;
|
||||||
if (!GrowArena(arena, old_top, old_size, Nar * sizeof(CELL),
|
if ((arena=GrowArena(arena, old_top, old_size, Nar * sizeof(CELL),
|
||||||
arity + 2 PASS_REGS)) {
|
arity + 2, &cells PASS_REGS))==0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil,
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil,
|
||||||
"while creating large global term");
|
"while creating large global term");
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldH = HR;
|
|
||||||
oldHB = HB;
|
|
||||||
oldASP = ASP;
|
|
||||||
newarena = (CELL *)XREGS[arity + 2];
|
newarena = (CELL *)XREGS[arity + 2];
|
||||||
arena = Deref(XREGS[arity + 1]);
|
arena = Deref(XREGS[arity + 1]);
|
||||||
old_size = ArenaSz(arena);
|
old_size = ArenaSz(arena);
|
||||||
@ -872,7 +885,7 @@ restart:
|
|||||||
HB0[i] = init;
|
HB0[i] = init;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CloseArena(oldH, oldHB, oldASP, newarena, old_size PASS_REGS);
|
CloseArena(&cells, newarena, old_size PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1534,9 +1547,10 @@ static Int p_nb_create2(USES_REGS1) {
|
|||||||
|
|
||||||
|
|
||||||
static Int nb_queue(UInt arena_sz USES_REGS) {
|
static Int nb_queue(UInt arena_sz USES_REGS) {
|
||||||
|
cell_space_t cspace;
|
||||||
Term queue_arena, queue, ar[QUEUE_FUNCTOR_ARITY], *nar;
|
Term queue_arena, queue, ar[QUEUE_FUNCTOR_ARITY], *nar;
|
||||||
Term t = Deref(ARG1);
|
Term t = Deref(ARG1);
|
||||||
|
enter_cell_space(&cspace);
|
||||||
LOCAL_DepthArenas++;
|
LOCAL_DepthArenas++;
|
||||||
if (!IsVarTerm(t)) {
|
if (!IsVarTerm(t)) {
|
||||||
if (!IsApplTerm(t)) {
|
if (!IsApplTerm(t)) {
|
||||||
@ -1549,9 +1563,9 @@ static Int nb_queue(UInt arena_sz USES_REGS) {
|
|||||||
queue = Yap_MkApplTerm(FunctorNBQueue, QUEUE_FUNCTOR_ARITY, ar);
|
queue = Yap_MkApplTerm(FunctorNBQueue, QUEUE_FUNCTOR_ARITY, ar);
|
||||||
if (!Yap_unify(queue, ARG1))
|
if (!Yap_unify(queue, ARG1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (arena_sz < 4 * 1024)
|
if (arena_sz < 32 * 1024)
|
||||||
arena_sz = 4 * 1024;
|
arena_sz = 32 * 1024;
|
||||||
queue_arena = NewArena(arena_sz, worker_id, 1, NULL);
|
queue_arena = NewArena(arena_sz, worker_id, 1, NULL, &cspace);
|
||||||
if (queue_arena == 0L) {
|
if (queue_arena == 0L) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1656,7 +1670,7 @@ static Int p_nb_queue_close(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_nb_queue_enqueue(USES_REGS1) {
|
static Int p_nb_queue_enqueue(USES_REGS1) {
|
||||||
CELL *qd = GetQueue(ARG1, "enqueue"), *oldH, *oldHB;
|
CELL *qd = GetQueue(ARG1, "enqueue");
|
||||||
UInt old_sz;
|
UInt old_sz;
|
||||||
Term arena, qsize, to;
|
Term arena, qsize, to;
|
||||||
UInt min_size;
|
UInt min_size;
|
||||||
@ -1675,37 +1689,15 @@ static Int p_nb_queue_enqueue(USES_REGS1) {
|
|||||||
min_size PASS_REGS);
|
min_size PASS_REGS);
|
||||||
if (to == 0L)
|
if (to == 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
cell_space_t cspace;
|
||||||
qd = GetQueue(ARG1, "enqueue");
|
qd = GetQueue(ARG1, "enqueue");
|
||||||
arena = GetQueueArena(qd, "enqueue");
|
arena = GetQueueArena(qd, "enqueue");
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
|
qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
|
||||||
while (old_sz < MIN_ARENA_SIZE) {
|
|
||||||
UInt gsiz = HR - RepPair(qd[QUEUE_HEAD]);
|
|
||||||
HR = oldH;
|
|
||||||
HB = oldHB;
|
|
||||||
if (gsiz > 1024 * 1024) {
|
|
||||||
gsiz = 1024 * 1024;
|
|
||||||
} else if (gsiz < 1024) {
|
|
||||||
gsiz = 1024;
|
|
||||||
}
|
|
||||||
ARG3 = to;
|
|
||||||
/* fprintf(stderr,"growing %ld cells\n",(unsigned long int)gsiz);*/
|
|
||||||
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
|
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
to = ARG3;
|
|
||||||
qd = RepAppl(Deref(ARG1)) + 1;
|
|
||||||
arena = GetQueueArena(qd, "enqueue");
|
|
||||||
oldH = HR;
|
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
|
||||||
old_sz = ArenaSz(arena);
|
|
||||||
}
|
|
||||||
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsize + 1);
|
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsize + 1);
|
||||||
if (qsize == 0) {
|
if (qsize == 0) {
|
||||||
qd[QUEUE_HEAD] = AbsPair(HR);
|
qd[QUEUE_HEAD] = AbsPair(HR);
|
||||||
@ -1716,7 +1708,7 @@ static Int p_nb_queue_enqueue(USES_REGS1) {
|
|||||||
RESET_VARIABLE(HR);
|
RESET_VARIABLE(HR);
|
||||||
qd[QUEUE_TAIL] = (CELL)HR;
|
qd[QUEUE_TAIL] = (CELL)HR;
|
||||||
HR++;
|
HR++;
|
||||||
CloseArena(oldH, oldHB, ASP, qd + QUEUE_ARENA, old_sz PASS_REGS);
|
CloseArena(&cspace, qd + QUEUE_ARENA, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1724,7 +1716,7 @@ static Int p_nb_queue_dequeue(USES_REGS1) {
|
|||||||
CELL *qd = GetQueue(ARG1, "dequeue");
|
CELL *qd = GetQueue(ARG1, "dequeue");
|
||||||
UInt old_sz, qsz;
|
UInt old_sz, qsz;
|
||||||
Term arena, out;
|
Term arena, out;
|
||||||
CELL *oldH, *oldHB;
|
cell_space_t cspace;
|
||||||
|
|
||||||
if (!qd)
|
if (!qd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1738,10 +1730,9 @@ static Int p_nb_queue_dequeue(USES_REGS1) {
|
|||||||
out = HeadOfTerm(qd[QUEUE_HEAD]);
|
out = HeadOfTerm(qd[QUEUE_HEAD]);
|
||||||
qd[QUEUE_HEAD] = TailOfTerm(qd[QUEUE_HEAD]);
|
qd[QUEUE_HEAD] = TailOfTerm(qd[QUEUE_HEAD]);
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
||||||
CloseArena(oldH, oldHB, ASP, &arena, old_sz PASS_REGS);
|
CloseArena(&cspace, &arena, old_sz PASS_REGS);
|
||||||
return Yap_unify(out, ARG2);
|
return Yap_unify(out, ARG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1838,6 +1829,7 @@ static Term MkZeroApplTerm(Functor f, UInt sz USES_REGS) {
|
|||||||
static Int p_nb_heap(USES_REGS1) {
|
static Int p_nb_heap(USES_REGS1) {
|
||||||
Term heap_arena, heap, *ar, *nar;
|
Term heap_arena, heap, *ar, *nar;
|
||||||
UInt hsize;
|
UInt hsize;
|
||||||
|
cell_space_t cspace;
|
||||||
Term tsize = Deref(ARG1);
|
Term tsize = Deref(ARG1);
|
||||||
UInt arena_sz = (ASP-HR) / 16;
|
UInt arena_sz = (ASP-HR) / 16;
|
||||||
|
|
||||||
@ -1868,7 +1860,7 @@ static Int p_nb_heap(USES_REGS1) {
|
|||||||
ar[HEAP_MAX] = tsize;
|
ar[HEAP_MAX] = tsize;
|
||||||
if (arena_sz < 1024)
|
if (arena_sz < 1024)
|
||||||
arena_sz = 1024;
|
arena_sz = 1024;
|
||||||
heap_arena = NewArena(arena_sz, worker_id, 1, NULL);
|
heap_arena = NewArena(arena_sz, worker_id, 1, NULL, &cspace);
|
||||||
if (heap_arena == 0L) {
|
if (heap_arena == 0L) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -1946,10 +1938,11 @@ static void DelHeapRoot(CELL *pt, UInt sz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_nb_heap_add_to_heap(USES_REGS1) {
|
static Int p_nb_heap_add_to_heap(USES_REGS1) {
|
||||||
CELL *qd = GetHeap(ARG1, "add_to_heap"), *oldH, *oldHB, *pt;
|
CELL *qd = GetHeap(ARG1, "add_to_heap"), *pt;
|
||||||
UInt hsize, hmsize, old_sz;
|
UInt hsize, hmsize, old_sz;
|
||||||
Term arena, to, key;
|
Term arena, to, key;
|
||||||
UInt mingrow;
|
UInt mingrow;
|
||||||
|
cell_space_t cspace;
|
||||||
|
|
||||||
if (!qd)
|
if (!qd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1971,6 +1964,7 @@ restart:
|
|||||||
"No Stack Space for Non-Backtrackable terms");
|
"No Stack Space for Non-Backtrackable terms");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
enter_cell_space(&cspace);
|
||||||
extra_size = extra_size / (2 * sizeof(CELL));
|
extra_size = extra_size / (2 * sizeof(CELL));
|
||||||
qd = GetHeap(ARG1, "add_to_heap");
|
qd = GetHeap(ARG1, "add_to_heap");
|
||||||
hmsize += extra_size;
|
hmsize += extra_size;
|
||||||
@ -1986,11 +1980,9 @@ restart:
|
|||||||
}
|
}
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
oldH = HR;
|
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
qd[HEAP_MAX] = Global_MkIntegerTerm(hmsize);
|
qd[HEAP_MAX] = Global_MkIntegerTerm(hmsize);
|
||||||
CloseArena(oldH, oldHB, ASP, qd + HEAP_ARENA, old_sz PASS_REGS);
|
CloseArena(&cspace, qd + HEAP_ARENA, old_sz PASS_REGS);
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
@ -2010,30 +2002,25 @@ restart:
|
|||||||
qd = GetHeap(ARG1, "add_to_heap");
|
qd = GetHeap(ARG1, "add_to_heap");
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
while (old_sz < MIN_ARENA_SIZE) {
|
while (old_sz < MIN_ARENA_SIZE) {
|
||||||
UInt gsiz = hsize * 2;
|
UInt gsiz = hsize * 2;
|
||||||
|
|
||||||
HR = oldH;
|
|
||||||
HB = oldHB;
|
|
||||||
if (gsiz > 1024 * 1024) {
|
if (gsiz > 1024 * 1024) {
|
||||||
gsiz = 1024 * 1024;
|
gsiz = 1024 * 1024;
|
||||||
} else if (gsiz < 1024) {
|
} else if (gsiz < 1024) {
|
||||||
gsiz = 1024;
|
gsiz = 1024;
|
||||||
}
|
}
|
||||||
ARG3 = to;
|
ARG3 = to;
|
||||||
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
|
if ((arena=GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3, &cspace PASS_REGS))==0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
to = ARG3;
|
to = ARG3;
|
||||||
qd = RepAppl(Deref(ARG1)) + 1;
|
qd = RepAppl(Deref(ARG1)) + 1;
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
oldH = HR;
|
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
}
|
}
|
||||||
@ -2042,7 +2029,7 @@ restart:
|
|||||||
pt[2 * hsize + 1] = to;
|
pt[2 * hsize + 1] = to;
|
||||||
PushHeap(pt, hsize);
|
PushHeap(pt, hsize);
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
||||||
CloseArena(oldH, oldHB, ASP, qd + HEAP_ARENA, old_sz PASS_REGS);
|
CloseArena(&cspace, qd + HEAP_ARENA, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2100,6 +2087,7 @@ static Int p_nb_heap_size(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_nb_beam(USES_REGS1) {
|
static Int p_nb_beam(USES_REGS1) {
|
||||||
|
cell_space_t cspace;
|
||||||
Term beam_arena, beam, *ar, *nar;
|
Term beam_arena, beam, *ar, *nar;
|
||||||
UInt hsize;
|
UInt hsize;
|
||||||
Term tsize = Deref(ARG1);
|
Term tsize = Deref(ARG1);
|
||||||
@ -2130,7 +2118,7 @@ static Int p_nb_beam(USES_REGS1) {
|
|||||||
ar[HEAP_MAX] = tsize;
|
ar[HEAP_MAX] = tsize;
|
||||||
if (arena_sz < 1024)
|
if (arena_sz < 1024)
|
||||||
arena_sz = 1024;
|
arena_sz = 1024;
|
||||||
beam_arena = NewArena(arena_sz, worker_id, 1, NULL);
|
beam_arena = NewArena(arena_sz, worker_id, 1, NULL, &cspace);
|
||||||
if (beam_arena == 0L) {
|
if (beam_arena == 0L) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -2339,10 +2327,11 @@ static Term DelBeamMin(CELL *pt, CELL *pt2, UInt sz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_nb_beam_add_to_beam(USES_REGS1) {
|
static Int p_nb_beam_add_to_beam(USES_REGS1) {
|
||||||
CELL *qd = GetHeap(ARG1, "add_to_beam"), *oldH, *oldHB, *pt;
|
CELL *qd = GetHeap(ARG1, "add_to_beam"), *pt;
|
||||||
UInt hsize, hmsize, old_sz;
|
UInt hsize, hmsize, old_sz;
|
||||||
Term arena, to, key;
|
Term arena, to, qsize, key;
|
||||||
UInt mingrow;
|
UInt mingrow;
|
||||||
|
cell_space_t cspace;
|
||||||
|
|
||||||
if (!qd)
|
if (!qd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -2373,37 +2362,32 @@ static Int p_nb_beam_add_to_beam(USES_REGS1) {
|
|||||||
qd = GetHeap(ARG1, "add_to_beam");
|
qd = GetHeap(ARG1, "add_to_beam");
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
|
qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
|
||||||
while (old_sz < MIN_ARENA_SIZE) {
|
while (old_sz < MIN_ARENA_SIZE) {
|
||||||
UInt gsiz = hsize * 2;
|
UInt gsiz = HR - RepPair(qd[QUEUE_HEAD]);
|
||||||
|
|
||||||
HR = oldH;
|
|
||||||
HB = oldHB;
|
|
||||||
if (gsiz > 1024 * 1024) {
|
if (gsiz > 1024 * 1024) {
|
||||||
gsiz = 1024 * 1024;
|
gsiz = 1024 * 1024;
|
||||||
} else if (gsiz < 1024) {
|
} else if (gsiz < 1024) {
|
||||||
gsiz = 1024;
|
gsiz = 1024;
|
||||||
}
|
}
|
||||||
ARG3 = to;
|
ARG3 = to;
|
||||||
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3 PASS_REGS)) {
|
/* fprintf(stderr,"growing %ld cells\n",(unsigned long int)gsiz);*/
|
||||||
|
if (!GrowArena(arena, ArenaLimit(arena), old_sz, gsiz, 3, &cspace PASS_REGS)) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
to = ARG3;
|
to = ARG3;
|
||||||
qd = RepAppl(Deref(ARG1)) + 1;
|
qd = RepAppl(Deref(ARG1)) + 1;
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
oldH = HR;
|
|
||||||
oldHB = HB;
|
|
||||||
HR = HB = ArenaPt(arena);
|
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
}
|
}
|
||||||
pt = qd + HEAP_START;
|
pt = qd + HEAP_START;
|
||||||
PushBeam(pt, pt + 2 * hmsize, hsize, key, to);
|
PushBeam(pt, pt + 2 * hmsize, hsize, key, to);
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
||||||
CloseArena(oldH, oldHB, ASP, qd + HEAP_ARENA, old_sz PASS_REGS);
|
CloseArena(&cspace, qd + HEAP_ARENA, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2411,8 +2395,8 @@ static Int p_nb_beam_del(USES_REGS1) {
|
|||||||
CELL *qd = GetHeap(ARG1, "debeam");
|
CELL *qd = GetHeap(ARG1, "debeam");
|
||||||
UInt old_sz, qsz;
|
UInt old_sz, qsz;
|
||||||
Term arena;
|
Term arena;
|
||||||
CELL *oldH, *oldHB;
|
|
||||||
Term tk, tv;
|
Term tk, tv;
|
||||||
|
cell_space_t cspace;
|
||||||
|
|
||||||
if (!qd)
|
if (!qd)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -2424,10 +2408,9 @@ static Int p_nb_beam_del(USES_REGS1) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
oldH = HR;
|
enter_cell_space(&cspace);
|
||||||
oldHB = HB;
|
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
||||||
CloseArena(oldH, oldHB, ASP, &arena, old_sz PASS_REGS);
|
CloseArena(&cspace, &arena, old_sz PASS_REGS);
|
||||||
tk = qd[HEAP_START];
|
tk = qd[HEAP_START];
|
||||||
tv = DelBeamMin(qd + HEAP_START,
|
tv = DelBeamMin(qd + HEAP_START,
|
||||||
qd + (HEAP_START + 2 * IntegerOfTerm(qd[HEAP_MAX])), qsz);
|
qd + (HEAP_START + 2 * IntegerOfTerm(qd[HEAP_MAX])), qsz);
|
||||||
|
107
C/grow.c
107
C/grow.c
@ -324,15 +324,15 @@ MoveGlobalWithHole( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
MoveHalfGlobal(CELL *OldPt USES_REGS)
|
MoveHalfGlobal(CELL *OldPt, size_t request USES_REGS)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in
|
* cpcellsd(To,From,NOfCells) - copy the cells downwards - in
|
||||||
* absmi.asm
|
* absmi.asm
|
||||||
*/
|
*/
|
||||||
UInt diff = LOCAL_OldH-OldPt;
|
UInt diff = LOCAL_OldH-OldPt;
|
||||||
CELL *NewPt = (CELL *)((char*)OldPt+LOCAL_GDiff);
|
|
||||||
CELL *IntPt = (CELL *)((char*)OldPt+LOCAL_GDiff0);
|
CELL *IntPt = (CELL *)((char*)OldPt+LOCAL_GDiff0);
|
||||||
|
CELL *NewPt = IntPt+request/sizeof(CELL);
|
||||||
cpcellsd(NewPt, IntPt, diff);
|
cpcellsd(NewPt, IntPt, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,6 +436,8 @@ fixPointerCells(CELL *pt, CELL *pt_bot, bool thread_copying USES_REGS)
|
|||||||
{
|
{
|
||||||
while (pt > pt_bot) {
|
while (pt > pt_bot) {
|
||||||
CELL reg = *--pt;
|
CELL reg = *--pt;
|
||||||
|
// if (pt-pt_bot> 4300 && pt-pt_bot < 4500)
|
||||||
|
// printf("%d %d %lx\n", pt-pt_bot, pt-LOCAL_GSplit, reg);
|
||||||
if (IsVarTerm(reg)) {
|
if (IsVarTerm(reg)) {
|
||||||
if (IsOldLocal(reg))
|
if (IsOldLocal(reg))
|
||||||
*pt = LocalAdjust(reg);
|
*pt = LocalAdjust(reg);
|
||||||
@ -450,6 +452,8 @@ fixPointerCells(CELL *pt, CELL *pt_bot, bool thread_copying USES_REGS)
|
|||||||
} else if (IsPairTerm(reg)) {
|
} else if (IsPairTerm(reg)) {
|
||||||
*pt = AdjustPair(reg PASS_REGS);
|
*pt = AdjustPair(reg PASS_REGS);
|
||||||
}
|
}
|
||||||
|
// if (pt-pt_bot> 4300 && pt-pt_bot < 4500)
|
||||||
|
// printf("%lx\n", *pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,12 +893,14 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
char *omax = (char *)H0;
|
char *omax = (char *)H0;
|
||||||
ADDR old_GlobalBase = LOCAL_GlobalBase;
|
ADDR old_GlobalBase = LOCAL_GlobalBase;
|
||||||
UInt minimal_request = 0L;
|
UInt minimal_request = 0L;
|
||||||
Int size = request;
|
Int size = request/sizeof(CELL);
|
||||||
char vb_msg1 = '\0', *vb_msg2;
|
char vb_msg1 = '\0', *vb_msg2;
|
||||||
bool do_grow = true;
|
bool do_grow = true;
|
||||||
bool insert_in_delays = false;
|
|
||||||
|
printf("request=%ld at %p, shift %p, %ld <-> %ld\n",request, hsplit, ptr,hsplit-H0,HR-hsplit);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
request is the amount of memory we requested, in bytes;
|
request is the amount of memory we requesd, in bytes;
|
||||||
base_move is the shift in global stacks we had to do
|
base_move is the shift in global stacks we had to do
|
||||||
size is how much space we allocate: it's negative if we just expand
|
size is how much space we allocate: it's negative if we just expand
|
||||||
the delay stack.
|
the delay stack.
|
||||||
@ -902,55 +908,44 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (hsplit) {
|
if (hsplit) {
|
||||||
/* just a little bit of sanity checking */
|
if (hsplit < H0 ||
|
||||||
if (hsplit < H0 && hsplit > (CELL *)LOCAL_GlobalBase) {
|
|
||||||
insert_in_delays = TRUE;
|
|
||||||
/* expanding attributed variables */
|
|
||||||
if (omax - size > LOCAL_GlobalBase+4096*sizeof(CELL)) {
|
|
||||||
/* we can just ask for more room */
|
|
||||||
size = 0;
|
|
||||||
do_grow = FALSE;
|
|
||||||
}
|
|
||||||
} else if (hsplit < (CELL*)omax ||
|
|
||||||
hsplit > HR)
|
hsplit > HR)
|
||||||
return FALSE;
|
return false;
|
||||||
else if (hsplit == (CELL *)omax)
|
if (hsplit == H0)
|
||||||
hsplit = NULL;
|
hsplit = NULL;
|
||||||
|
if (hsplit == HR && Unsigned(HR)+request < Unsigned(ASP)-StackGap( PASS_REGS1 )) {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (size < 0 ||
|
if (size < 0 ||
|
||||||
(Unsigned(HR)+size < Unsigned(ASP)-StackGap( PASS_REGS1 ) &&
|
(Unsigned(HR)+request < Unsigned(ASP-StackGap( PASS_REGS1 )))) {
|
||||||
hsplit > H0)) {
|
do_grow = false;
|
||||||
/* don't need to expand stacks */
|
|
||||||
insert_in_delays = FALSE;
|
|
||||||
do_grow = FALSE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (Unsigned(HR)+size < Unsigned(ASP)-CreepFlag) {
|
|
||||||
/* we can just ask for more room */
|
|
||||||
do_grow = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (do_grow) {
|
if (do_grow) {
|
||||||
if (size < YAP_ALLOC_SIZE)
|
if (request < YAP_ALLOC_SIZE)
|
||||||
size = YAP_ALLOC_SIZE;
|
request = YAP_ALLOC_SIZE;
|
||||||
size = AdjustPageSize(size);
|
request = AdjustPageSize(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("grow=%d\n", do_grow);
|
||||||
/* adjust to a multiple of 256) */
|
/* adjust to a multiple of 256) */
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
LOCAL_PrologMode |= GrowStackMode;
|
LOCAL_PrologMode |= GrowStackMode;
|
||||||
start_growth_time = Yap_cputime();
|
start_growth_time = Yap_cputime();
|
||||||
|
|
||||||
if (do_grow) {
|
if (do_grow) {
|
||||||
if (!GLOBAL_AllowGlobalExpansion) {
|
if (!GLOBAL_AllowGlobalExpansion) {
|
||||||
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
|
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
|
||||||
LeaveGrowMode(GrowStackMode);
|
LeaveGrowMode(GrowStackMode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!GLOBAL_AllowGlobalExpansion || !Yap_ExtendWorkSpace(size)) {
|
if (!GLOBAL_AllowGlobalExpansion || !Yap_ExtendWorkSpace(request)) {
|
||||||
/* always fails when using malloc */
|
/* always fails when using malloc */
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
size += AdjustPageSize(((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)+MinHeapGap);
|
request += AdjustPageSize(((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)+MinHeapGap);
|
||||||
minimal_request = size;
|
minimal_request = request;
|
||||||
size = Yap_ExtendWorkSpaceThroughHole(size);
|
request = Yap_ExtendWorkSpaceThroughHole(request);
|
||||||
if (size < 0) {
|
if (request < 0) {
|
||||||
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
|
LOCAL_ErrorMessage = "Global Stack crashed against Local Stack";
|
||||||
LeaveGrowMode(GrowStackMode);
|
LeaveGrowMode(GrowStackMode);
|
||||||
return 0;
|
return 0;
|
||||||
@ -958,15 +953,11 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gc_verbose = Yap_is_gc_verbose();
|
gc_verbose = Yap_is_gc_verbose();
|
||||||
LOCAL_delay_overflows++;
|
|
||||||
if (gc_verbose) {
|
if (gc_verbose) {
|
||||||
if (hsplit) {
|
if (hsplit) {
|
||||||
if (hsplit > H0) {
|
if (hsplit > H0) {
|
||||||
vb_msg1 = 'H';
|
vb_msg1 = 'H';
|
||||||
vb_msg2 = "Global Variable Space";
|
vb_msg2 = "Global Variable Space";
|
||||||
} else {
|
|
||||||
vb_msg1 = 'D';
|
|
||||||
vb_msg2 = "Global Variable Delay Space";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vb_msg1 = 'D';
|
vb_msg1 = 'D';
|
||||||
@ -976,8 +967,9 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
fprintf(stderr, "%% Worker Id %d:\n", worker_id);
|
fprintf(stderr, "%% Worker Id %d:\n", worker_id);
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr, "%% %cO %s Overflow %d\n", vb_msg1, vb_msg2, LOCAL_delay_overflows);
|
fprintf(stderr, "%% %cO %s Overflow %d\n", vb_msg1, vb_msg2, LOCAL_delay_overflows);
|
||||||
fprintf(stderr, "%% %cO growing the stacks " UInt_FORMAT " bytes\n", vb_msg1, size);
|
fprintf(stderr, "%% %cO growing the stacks " UInt_FORMAT " bytes\n", vb_msg1, request);
|
||||||
}
|
}
|
||||||
|
printf("grow=%d %p\n", do_grow, ASP);
|
||||||
ASP -= 256;
|
ASP -= 256;
|
||||||
YAPEnterCriticalSection();
|
YAPEnterCriticalSection();
|
||||||
/* we always shift the local and the stack by the same amount */
|
/* we always shift the local and the stack by the same amount */
|
||||||
@ -985,13 +977,13 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
/* we got over a hole */
|
/* we got over a hole */
|
||||||
if (minimal_request) {
|
if (minimal_request) {
|
||||||
/* we went over a hole */
|
/* we went over a hole */
|
||||||
LOCAL_BaseDiff = size+((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)-minimal_request;
|
LOCAL_BaseDiff = request+((CELL)LOCAL_TrailTop-(CELL)LOCAL_GlobalBase)-minimal_request;
|
||||||
LOCAL_LDiff = LOCAL_TrDiff = size;
|
LOCAL_LDiff = LOCAL_TrDiff = request;
|
||||||
} else {
|
} else {
|
||||||
/* we may still have an overflow */
|
/* we may still have an overflow */
|
||||||
LOCAL_BaseDiff = LOCAL_GlobalBase - old_GlobalBase;
|
LOCAL_BaseDiff = LOCAL_GlobalBase - old_GlobalBase;
|
||||||
/* if we grow, we need to move the stacks */
|
/* if we grow, we need to move the stacks */
|
||||||
LOCAL_LDiff = LOCAL_TrDiff = LOCAL_BaseDiff+size;
|
LOCAL_LDiff = LOCAL_TrDiff = LOCAL_BaseDiff+request;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* stay still */
|
/* stay still */
|
||||||
@ -1002,19 +994,15 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
hole in global */
|
hole in global */
|
||||||
if (!hsplit) {
|
if (!hsplit) {
|
||||||
if (!do_grow) {
|
if (!do_grow) {
|
||||||
LOCAL_DelayDiff = LOCAL_GDiff = LOCAL_GDiff0 = size;
|
LOCAL_GDiff = LOCAL_GDiff0 = request;
|
||||||
request = 0L;
|
request = 0L;
|
||||||
} else {
|
} else {
|
||||||
/* expand delay stack */
|
|
||||||
LOCAL_DelayDiff = LOCAL_GDiff = LOCAL_GDiff0 = LOCAL_LDiff;
|
|
||||||
}
|
|
||||||
} else if (insert_in_delays) {
|
|
||||||
/* we want to expand a hole for the delay stack */
|
/* we want to expand a hole for the delay stack */
|
||||||
LOCAL_DelayDiff = size-request;
|
LOCAL_GDiff = LOCAL_GDiff0 = LOCAL_LDiff;
|
||||||
LOCAL_GDiff = LOCAL_GDiff0 = size;
|
}
|
||||||
} else {
|
} else {
|
||||||
/* we want to expand a hole for the delay stack */
|
/* we want to expand a hole for the delay stack */
|
||||||
LOCAL_GDiff0 = LOCAL_DelayDiff = LOCAL_BaseDiff;
|
LOCAL_GDiff0 = LOCAL_BaseDiff;
|
||||||
LOCAL_GDiff = LOCAL_BaseDiff+request;
|
LOCAL_GDiff = LOCAL_BaseDiff+request;
|
||||||
}
|
}
|
||||||
LOCAL_GSplit = hsplit;
|
LOCAL_GSplit = hsplit;
|
||||||
@ -1042,17 +1030,13 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
*ptr = PtoLocAdjust(*ptr);
|
*ptr = PtoLocAdjust(*ptr);
|
||||||
}
|
}
|
||||||
if (hsplit) {
|
if (hsplit) {
|
||||||
if (insert_in_delays) {
|
MoveHalfGlobal(hsplit, request PASS_REGS);
|
||||||
/* we have things not quite where we want to have them */
|
printf("done\n");
|
||||||
cpcellsd((CELL *)(omax+LOCAL_DelayDiff), (CELL *)(omax+LOCAL_GDiff0), (ADDR)hsplit-omax);
|
|
||||||
} else {
|
|
||||||
MoveHalfGlobal(hsplit PASS_REGS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
YAPLeaveCriticalSection();
|
YAPLeaveCriticalSection();
|
||||||
ASP += 256;
|
ASP += 256;
|
||||||
if (minimal_request) {
|
if (minimal_request) {
|
||||||
Yap_AllocHole(minimal_request, size);
|
Yap_AllocHole(minimal_request, request);
|
||||||
}
|
}
|
||||||
growth_time = Yap_cputime()-start_growth_time;
|
growth_time = Yap_cputime()-start_growth_time;
|
||||||
LOCAL_total_delay_overflow_time += growth_time;
|
LOCAL_total_delay_overflow_time += growth_time;
|
||||||
@ -1063,9 +1047,10 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS)
|
|||||||
LeaveGrowMode(GrowStackMode);
|
LeaveGrowMode(GrowStackMode);
|
||||||
if (hsplit) {
|
if (hsplit) {
|
||||||
return request;
|
return request;
|
||||||
} else
|
} else {
|
||||||
return LOCAL_GDiff-LOCAL_BaseDiff;
|
return LOCAL_GDiff-LOCAL_BaseDiff;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fix_compiler_instructions(PInstr *pcpc USES_REGS)
|
fix_compiler_instructions(PInstr *pcpc USES_REGS)
|
||||||
@ -1548,6 +1533,7 @@ UInt
|
|||||||
Yap_InsertInGlobal(CELL *where, size_t howmuch)
|
Yap_InsertInGlobal(CELL *where, size_t howmuch)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
printf("where=%p, hm=%d\n",where,howmuch);
|
||||||
if ((howmuch = static_growglobal(howmuch, NULL, where PASS_REGS)) == 0)
|
if ((howmuch = static_growglobal(howmuch, NULL, where PASS_REGS)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
@ -1576,6 +1562,7 @@ Yap_growstack(size_t size)
|
|||||||
int res;
|
int res;
|
||||||
|
|
||||||
LOCAL_PrologMode |= GrowStackMode;
|
LOCAL_PrologMode |= GrowStackMode;
|
||||||
|
printf("extra %dBs\n",size);
|
||||||
res=growstack(size PASS_REGS);
|
res=growstack(size PASS_REGS);
|
||||||
LeaveGrowMode(GrowStackMode);
|
LeaveGrowMode(GrowStackMode);
|
||||||
return res;
|
return res;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/**************************************************************************
|
/*************************************************************************
|
||||||
* *
|
* *
|
||||||
* YAP Prolog *
|
* YAP Prolog *
|
||||||
* *
|
* *
|
||||||
@ -4194,7 +4194,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop USES_REGS)
|
|||||||
int gc_on = FALSE, gc_t = FALSE;
|
int gc_on = FALSE, gc_t = FALSE;
|
||||||
|
|
||||||
if (Yap_GetValue(AtomGc) != TermNil)
|
if (Yap_GetValue(AtomGc) != TermNil)
|
||||||
gc_on = TRUE;
|
gc_on = false;
|
||||||
if (IsIntegerTerm(Tgc_margin = Yap_GetValue(AtomGcMargin)) &&
|
if (IsIntegerTerm(Tgc_margin = Yap_GetValue(AtomGcMargin)) &&
|
||||||
gc_margin > 0) {
|
gc_margin > 0) {
|
||||||
gc_margin = (UInt)IntegerOfTerm(Tgc_margin);
|
gc_margin = (UInt)IntegerOfTerm(Tgc_margin);
|
||||||
@ -4346,3 +4346,4 @@ Yap_inc_mark_variable()
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_total_marked++;
|
LOCAL_total_marked++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2039,7 +2039,7 @@ static UInt suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap,
|
|||||||
/* give it some slack */
|
/* give it some slack */
|
||||||
tels = cls + 4;
|
tels = cls + 4;
|
||||||
} else {
|
} else {
|
||||||
tels = cls;
|
tels = cls+1;
|
||||||
}
|
}
|
||||||
sz = (UInt)NEXTOP((yamop *)NULL, sssllp) + tels * sizeof(yamop *);
|
sz = (UInt)NEXTOP((yamop *)NULL, sssllp) + tels * sizeof(yamop *);
|
||||||
if ((ncode = (yamop *)Yap_AllocCodeSpace(sz)) == NULL) {
|
if ((ncode = (yamop *)Yap_AllocCodeSpace(sz)) == NULL) {
|
||||||
|
@ -1949,11 +1949,12 @@
|
|||||||
Op(p_arg_vv, xxx);
|
Op(p_arg_vv, xxx);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.xxx.x1);
|
Term ts[3];
|
||||||
HR[1] = XREG(PREG->y_u.xxx.x2);
|
ts[0] = XREG(PREG->y_u.xxx.x1);
|
||||||
RESET_VARIABLE(HR + 2);
|
ts[1] = XREG(PREG->y_u.xxx.x2);
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
|
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -2045,12 +2046,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
CELL *Ho = HR;
|
CELL *Ho = HR;
|
||||||
|
Term ts[3];
|
||||||
Term t = MkIntegerTerm(PREG->y_u.xxn.c);
|
Term t = MkIntegerTerm(PREG->y_u.xxn.c);
|
||||||
HR[0] = t;
|
ts[0] = t;
|
||||||
HR[1] = XREG(PREG->y_u.xxn.xi);
|
ts[1] = XREG(PREG->y_u.xxn.xi);
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
|
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), ts);
|
||||||
HR = Ho;
|
HR = Ho;
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
@ -2118,12 +2120,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
Op(p_arg_y_vv, yxx);
|
Op(p_arg_y_vv, yxx);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.yxx.x1);
|
Term ts[3];
|
||||||
HR[1] = XREG(PREG->y_u.yxx.x2);
|
ts[0] = XREG(PREG->y_u.yxx.x1);
|
||||||
HR[2] = YREG[PREG->y_u.yxx.y];
|
ts[1] = XREG(PREG->y_u.yxx.x2);
|
||||||
RESET_VARIABLE(HR + 2);
|
ts[2] = YREG[PREG->y_u.yxx.y];
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
|
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -2216,13 +2219,14 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
CELL *Ho = HR;
|
CELL *Ho = HR;
|
||||||
|
Term ts[3];
|
||||||
Term t = MkIntegerTerm(PREG->y_u.yxn.c);
|
Term t = MkIntegerTerm(PREG->y_u.yxn.c);
|
||||||
HR[0] = t;
|
ts[0] = t;
|
||||||
HR[1] = XREG(PREG->y_u.yxn.xi);
|
ts[1] = XREG(PREG->y_u.yxn.xi);
|
||||||
HR[2] = YREG[PREG->y_u.yxn.y];
|
ts[2] = YREG[PREG->y_u.yxn.y];
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR);
|
RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), ts);
|
||||||
HR = Ho;
|
HR = Ho;
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
@ -2295,12 +2299,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
restart_func2s:
|
restart_func2s:
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
RESET_VARIABLE(HR);
|
Term ts[3];
|
||||||
HR[1] = XREG(PREG->y_u.xxx.x1);
|
RESET_VARIABLE(ts);
|
||||||
HR[2] = XREG(PREG->y_u.xxx.x2);
|
ts[1] = XREG(PREG->y_u.xxx.x1);
|
||||||
|
ts[2] = XREG(PREG->y_u.xxx.x2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
/* We have to build the structure */
|
/* We have to build the structure */
|
||||||
@ -2412,12 +2417,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
restart_func2s_cv:
|
restart_func2s_cv:
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
RESET_VARIABLE(HR);
|
Term ts[3];
|
||||||
HR[1] = PREG->y_u.xxc.c;
|
RESET_VARIABLE(ts);
|
||||||
HR[2] = XREG(PREG->y_u.xxc.xi);
|
ts[1] = PREG->y_u.xxc.c;
|
||||||
|
ts[2] = XREG(PREG->y_u.xxc.xi);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -2517,15 +2523,16 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
Term ti;
|
Term ti;
|
||||||
|
Term ts[3];
|
||||||
CELL *hi = HR;
|
CELL *hi = HR;
|
||||||
|
|
||||||
ti = MkIntegerTerm(PREG->y_u.xxn.c);
|
ti = MkIntegerTerm(PREG->y_u.xxn.c);
|
||||||
RESET_VARIABLE(HR);
|
RESET_VARIABLE(ts);
|
||||||
HR[1] = XREG(PREG->y_u.xxn.xi);
|
ts[1] = XREG(PREG->y_u.xxn.xi);
|
||||||
HR[2] = ti;
|
ts[2] = ti;
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
HR = hi;
|
HR = hi;
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
@ -2611,12 +2618,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
restart_func2s_y:
|
restart_func2s_y:
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
RESET_VARIABLE(HR);
|
Term ts[3];
|
||||||
HR[1] = XREG(PREG->y_u.yxx.x1);
|
RESET_VARIABLE(ts);
|
||||||
HR[2] = XREG(PREG->y_u.yxx.x2);
|
ts[1] = XREG(PREG->y_u.yxx.x1);
|
||||||
|
ts[2] = XREG(PREG->y_u.yxx.x2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
/* We have to build the structure */
|
/* We have to build the structure */
|
||||||
@ -2735,12 +2743,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
restart_func2s_y_cv:
|
restart_func2s_y_cv:
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
RESET_VARIABLE(HR);
|
Term ts[3];
|
||||||
HR[1] = PREG->y_u.yxc.c;
|
RESET_VARIABLE(ts);
|
||||||
HR[2] = XREG(PREG->y_u.yxc.xi);
|
ts[1] = PREG->y_u.yxc.c;
|
||||||
|
ts[2] = XREG(PREG->y_u.yxc.xi);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
/* We have to build the structure */
|
/* We have to build the structure */
|
||||||
@ -2847,14 +2856,15 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
Term ti;
|
Term ti;
|
||||||
CELL *hi = HR;
|
CELL *hi = HR;
|
||||||
|
Term ts[3];
|
||||||
|
|
||||||
ti = MkIntegerTerm((Int)(PREG->y_u.yxn.c));
|
ti = MkIntegerTerm((Int)(PREG->y_u.yxn.c));
|
||||||
RESET_VARIABLE(HR);
|
RESET_VARIABLE(ts);
|
||||||
HR[1] = XREG(PREG->y_u.yxn.xi);
|
ts[1] = XREG(PREG->y_u.yxn.xi);
|
||||||
HR[2] = ti;
|
ts[2] = ti;
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
HR = hi;
|
HR = hi;
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
@ -2952,12 +2962,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
Op(p_func2f_xx, xxx);
|
Op(p_func2f_xx, xxx);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.xxx.x);
|
Term ts[3];
|
||||||
RESET_VARIABLE(HR + 1);
|
ts[0] = XREG(PREG->y_u.xxx.x);
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 1);
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -3000,12 +3011,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
Op(p_func2f_xy, xxy);
|
Op(p_func2f_xy, xxy);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.xxy.x);
|
Term ts[3];
|
||||||
RESET_VARIABLE(HR + 1);
|
ts[0] = XREG(PREG->y_u.xxy.x);
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 1);
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -3051,12 +3063,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
Op(p_func2f_yx, yxx);
|
Op(p_func2f_yx, yxx);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.yxx.x2);
|
Term ts[3];
|
||||||
RESET_VARIABLE(HR + 1);
|
ts[0] = XREG(PREG->y_u.yxx.x2);
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 1);
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
@ -3102,12 +3115,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO );
|
|||||||
Op(p_func2f_yy, yyx);
|
Op(p_func2f_yy, yyx);
|
||||||
#ifdef LOW_LEVEL_TRACER
|
#ifdef LOW_LEVEL_TRACER
|
||||||
if (Yap_do_low_level_trace) {
|
if (Yap_do_low_level_trace) {
|
||||||
HR[0] = XREG(PREG->y_u.yyx.x);
|
Term ts[3];
|
||||||
RESET_VARIABLE(HR + 1);
|
ts[0] = XREG(PREG->y_u.yyx.x);
|
||||||
RESET_VARIABLE(HR + 2);
|
RESET_VARIABLE(ts + 1);
|
||||||
|
RESET_VARIABLE(ts + 2);
|
||||||
low_level_trace(enter_pred,
|
low_level_trace(enter_pred,
|
||||||
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)),
|
||||||
HR);
|
ts);
|
||||||
}
|
}
|
||||||
#endif /* LOW_LEVEL_TRACE */
|
#endif /* LOW_LEVEL_TRACE */
|
||||||
BEGD(d0);
|
BEGD(d0);
|
||||||
|
35
C/scanner.c
35
C/scanner.c
@ -1319,6 +1319,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
TokEntry *t, *l, *p;
|
TokEntry *t, *l, *p;
|
||||||
enum TokenKinds kind;
|
enum TokenKinds kind;
|
||||||
int solo_flag = TRUE;
|
int solo_flag = TRUE;
|
||||||
|
int lvl = push_text_stack();
|
||||||
int32_t ch, och = ' ';
|
int32_t ch, och = ' ';
|
||||||
struct qq_struct_t *cur_qq = NULL;
|
struct qq_struct_t *cur_qq = NULL;
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
@ -1348,6 +1349,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
t = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
t->TokNext = NULL;
|
t->TokNext = NULL;
|
||||||
if (t == NULL) {
|
if (t == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
}
|
}
|
||||||
if (!l)
|
if (!l)
|
||||||
@ -1418,6 +1420,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE);
|
imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE);
|
||||||
TokImage = Realloc(p0, imgsz);
|
TokImage = Realloc(p0, imgsz);
|
||||||
if (TokImage == NULL) {
|
if (TokImage == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
charp =(unsigned char *) TokImage + (charp - p0);
|
charp =(unsigned char *) TokImage + (charp - p0);
|
||||||
@ -1427,6 +1430,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
while (ch == '\'' && isvar &&
|
while (ch == '\'' && isvar &&
|
||||||
trueGlobalPrologFlag(VARIABLE_NAMES_MAY_END_WITH_QUOTES_FLAG)) {
|
trueGlobalPrologFlag(VARIABLE_NAMES_MAY_END_WITH_QUOTES_FLAG)) {
|
||||||
if (charp == (unsigned char *)AuxSp - 1024) {
|
if (charp == (unsigned char *)AuxSp - 1024) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
@ -1438,6 +1442,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
/* don't do this in iso */
|
/* don't do this in iso */
|
||||||
ae = Yap_LookupAtom(TokImage);
|
ae = Yap_LookupAtom(TokImage);
|
||||||
if (ae == NIL) {
|
if (ae == NIL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->TokInfo = MkAtomTerm(ae);
|
t->TokInfo = MkAtomTerm(ae);
|
||||||
@ -1470,6 +1475,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokInfo = TermError;
|
t->TokInfo = TermError;
|
||||||
}
|
}
|
||||||
/* serious error now */
|
/* serious error now */
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
ch = cha;
|
ch = cha;
|
||||||
@ -1480,6 +1486,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokLine = GetCurInpLine(st);
|
t->TokLine = GetCurInpLine(st);
|
||||||
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1506,6 +1513,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokLine = GetCurInpLine(st);
|
t->TokLine = GetCurInpLine(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
} else {
|
} else {
|
||||||
e2->TokNext = NULL;
|
e2->TokNext = NULL;
|
||||||
@ -1540,6 +1548,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokPos = GetCurInpPos(st);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
} else {
|
} else {
|
||||||
e2->TokNext = NULL;
|
e2->TokNext = NULL;
|
||||||
@ -1570,6 +1579,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
size_t sz = charp-(unsigned char *)TokImage;
|
size_t sz = charp-(unsigned char *)TokImage;
|
||||||
TokImage = Realloc(TokImage, (imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE)));
|
TokImage = Realloc(TokImage, (imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE)));
|
||||||
if (TokImage == NULL) {
|
if (TokImage == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
charp = (unsigned char *)TokImage+sz;
|
charp = (unsigned char *)TokImage+sz;
|
||||||
@ -1609,6 +1619,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokInfo = Yap_CharsToTDQ((char *)TokImage, CurrentModule,
|
t->TokInfo = Yap_CharsToTDQ((char *)TokImage, CurrentModule,
|
||||||
LOCAL_encoding PASS_REGS);
|
LOCAL_encoding PASS_REGS);
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = String_tok);
|
t->Tok = Ord(kind = String_tok);
|
||||||
@ -1616,12 +1627,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokInfo = Yap_CharsToTBQ((char *)TokImage, CurrentModule,
|
t->TokInfo = Yap_CharsToTBQ((char *)TokImage, CurrentModule,
|
||||||
LOCAL_encoding PASS_REGS);
|
LOCAL_encoding PASS_REGS);
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = String_tok);
|
t->Tok = Ord(kind = String_tok);
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = MkAtomTerm(Yap_LookupAtom(TokImage));
|
t->TokInfo = MkAtomTerm(Yap_LookupAtom(TokImage));
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
@ -1642,6 +1655,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
}
|
}
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
} else
|
} else
|
||||||
ch = getchr(st);
|
ch = getchr(st);
|
||||||
@ -1656,8 +1670,10 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
// consume...
|
// consume...
|
||||||
if (pch == '%') {
|
if (pch == '%') {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (ch == '`')
|
if (ch == '`')
|
||||||
@ -1669,6 +1685,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
@ -1677,6 +1694,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
}
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1726,6 +1744,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
@ -1734,6 +1753,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNl;
|
t->TokInfo = TermNl;
|
||||||
}
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
} else {
|
} else {
|
||||||
Atom ae;
|
Atom ae;
|
||||||
@ -1744,8 +1764,10 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
size_t sz = charp - (unsigned char *)TokImage;
|
size_t sz = charp - (unsigned char *)TokImage;
|
||||||
imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE);
|
imgsz = Yap_Min(imgsz * 2, imgsz + MBYTE);
|
||||||
TokImage = Realloc(TokImage, imgsz);
|
TokImage = Realloc(TokImage, imgsz);
|
||||||
if (!TokImage)
|
if (!TokImage) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
|
}
|
||||||
charp = (unsigned char *)TokImage+sz;
|
charp = (unsigned char *)TokImage+sz;
|
||||||
}
|
}
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
@ -1753,10 +1775,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
add_ch_to_buff('\0');
|
add_ch_to_buff('\0');
|
||||||
ae = Yap_LookupAtom(TokImage);
|
ae = Yap_LookupAtom(TokImage);
|
||||||
if (ae == NIL) {
|
if (ae == NIL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->TokInfo = MkAtomTerm(ae);
|
t->TokInfo = MkAtomTerm(ae);
|
||||||
if (t->TokInfo == (CELL)NIL) {
|
if (t->TokInfo == (CELL)NIL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
@ -1820,6 +1844,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
LOCAL_ErrorMessage = "not enough heap space to read in quasi quote";
|
LOCAL_ErrorMessage = "not enough heap space to read in quasi quote";
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermOutOfHeapError;
|
t->TokInfo = TermOutOfHeapError;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (cur_qq) {
|
if (cur_qq) {
|
||||||
@ -1827,7 +1852,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermOutOfHeapError;
|
t->TokInfo = TermOutOfHeapError;
|
||||||
Free(qq);
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
} else {
|
} else {
|
||||||
cur_qq = qq;
|
cur_qq = qq;
|
||||||
@ -1865,6 +1890,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
cur_qq = NULL;
|
cur_qq = NULL;
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermError;
|
t->TokInfo = TermError;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
cur_qq = NULL;
|
cur_qq = NULL;
|
||||||
@ -1910,6 +1936,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
LOCAL_ErrorMessage = "not enough heap space to read in quasi quote";
|
LOCAL_ErrorMessage = "not enough heap space to read in quasi quote";
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermOutOfHeapError;
|
t->TokInfo = TermOutOfHeapError;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
||||||
@ -1923,6 +1950,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
qq->end.linepos = st->linepos - 1;
|
qq->end.linepos = st->linepos - 1;
|
||||||
qq->end.charno = st->charcount - 1;
|
qq->end.charno = st->charcount - 1;
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
@ -1936,6 +1964,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
mark_eof(st);
|
mark_eof(st);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
|
pop_text_stack(lvl);
|
||||||
return l;
|
return l;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
@ -1951,6 +1980,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
/* insert an error token to inform the system of what happened */
|
/* insert an error token to inform the system of what happened */
|
||||||
TokEntry *e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
TokEntry *e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
}
|
}
|
||||||
p->TokNext = e;
|
p->TokNext = e;
|
||||||
@ -1963,6 +1993,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
|||||||
p = e;
|
p = e;
|
||||||
}
|
}
|
||||||
} while (kind != eot_tok);
|
} while (kind != eot_tok);
|
||||||
|
pop_text_stack(lvl);
|
||||||
|
|
||||||
return (l);
|
return (l);
|
||||||
}
|
}
|
||||||
|
76
CXX/yapi.cpp
76
CXX/yapi.cpp
@ -411,6 +411,23 @@ std::vector<Term> YAPPairTerm::listToArray() {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<YAPTerm> YAPPairTerm::listToVector() {
|
||||||
|
Term *tailp;
|
||||||
|
Term t1 = gt();
|
||||||
|
Int l = Yap_SkipList(&t1, &tailp);
|
||||||
|
if (l < 0) {
|
||||||
|
throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
|
||||||
|
}
|
||||||
|
std::vector<YAPTerm> o = *new std::vector<YAPTerm>(l);
|
||||||
|
int i = 0;
|
||||||
|
Term t = gt();
|
||||||
|
while (t != TermNil) {
|
||||||
|
o[i++] = YAPTerm(HeadOfTerm(t));
|
||||||
|
t = TailOfTerm(t);
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
YAP_tag_t YAPTerm::tag() {
|
YAP_tag_t YAPTerm::tag() {
|
||||||
Term tt = gt();
|
Term tt = gt();
|
||||||
if (IsVarTerm(tt)) {
|
if (IsVarTerm(tt)) {
|
||||||
@ -569,18 +586,18 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
|||||||
q.p = P;
|
q.p = P;
|
||||||
|
|
||||||
q.cp = CP;
|
q.cp = CP;
|
||||||
|
q.b0 = LCL0-CellPtr(B);
|
||||||
|
q.env0 = LCL0-ENV;
|
||||||
for (arity_t i = 0; i < arity; i++)
|
for (arity_t i = 0; i < arity; i++)
|
||||||
XREGS[i + 1] = ts[i].term();
|
XREGS[i + 1] = ts[i].term();
|
||||||
|
|
||||||
// allow Prolog style exceotion handling
|
// allow Prolog style exceotion handling
|
||||||
// don't forget, on success these bindings will still be there);
|
// don't forget, on success these bindings will still be there);
|
||||||
result = YAP_LeaveGoal(true, &q);
|
result = YAP_EnterGoal(ap.ap, nullptr, &q);
|
||||||
|
YAP_LeaveGoal(result, &q);
|
||||||
|
|
||||||
YAPCatchError();
|
YAPCatchError();
|
||||||
|
|
||||||
Yap_CloseHandles(q.CurSlot);
|
|
||||||
pop_text_stack(q.lvl + 1);
|
|
||||||
|
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -594,11 +611,14 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
|||||||
// _save = PyEval_SaveThread();
|
// _save = PyEval_SaveThread();
|
||||||
#endif
|
#endif
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
YAP_dogoalinfo q;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term *ts = nullptr;
|
Term *ts = nullptr;
|
||||||
q.CurSlot = Yap_StartSlots();
|
q.CurSlot = Yap_StartSlots();
|
||||||
q.p = P;
|
q.p = P;
|
||||||
q.cp = CP;
|
q.cp = CP;
|
||||||
|
Int oenv = LCL0-ENV;
|
||||||
|
Int oB = LCL0-CellPtr(B);
|
||||||
Term omod = CurrentModule;
|
Term omod = CurrentModule;
|
||||||
PredEntry *ap = nullptr;
|
PredEntry *ap = nullptr;
|
||||||
if (IsStringTerm(tmod))
|
if (IsStringTerm(tmod))
|
||||||
@ -625,9 +645,10 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
|||||||
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||||
|
|
||||||
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||||
// std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n";
|
// std::cerr << "mgoal " << YAPTerm(tmod).text() << ":" << YAPTerm(t).text() << "\n
|
||||||
|
|
||||||
YAP_LeaveGoal(result && !release, &q);
|
YAP_LeaveGoal(result && !release, &q);
|
||||||
|
ENV = LCL0-oenv;
|
||||||
|
B = (choiceptr)(LCL0-oB);
|
||||||
CurrentModule = LOCAL_SourceModule = omod;
|
CurrentModule = LOCAL_SourceModule = omod;
|
||||||
// PyEval_RestoreThread(_save);
|
// PyEval_RestoreThread(_save);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
@ -640,19 +661,25 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) {
|
|||||||
void YAPEngine::release() {
|
void YAPEngine::release() {
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
YAP_LeaveGoal(FALSE, &q);
|
// YAP_LeaveGoal(FALSE, &q);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
Term YAPEngine::fun(Term t) {
|
Term YAPEngine::fun(Term t) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
|
YAP_dogoalinfo q;
|
||||||
Term tmod = Yap_CurrentModule(), *ts = nullptr;
|
Term tmod = Yap_CurrentModule(), *ts = nullptr;
|
||||||
PredEntry *ap;
|
PredEntry *ap;
|
||||||
arity_t arity;
|
arity_t arity;
|
||||||
Functor f;
|
Functor f;
|
||||||
Atom name;
|
Atom name;
|
||||||
|
q.CurSlot = Yap_StartSlots();
|
||||||
|
q.p = P;
|
||||||
|
q.cp = CP;
|
||||||
|
|
||||||
|
Int oenv = LCL0-ENV;
|
||||||
|
Int oB = LCL0-CellPtr(B);
|
||||||
if (IsApplTerm(t)) {
|
if (IsApplTerm(t)) {
|
||||||
ts = RepAppl(t) + 1;
|
ts = RepAppl(t) + 1;
|
||||||
f = (Functor)ts[-1];
|
f = (Functor)ts[-1];
|
||||||
@ -684,9 +711,6 @@ Term YAPEngine::fun(Term t) {
|
|||||||
Term g = (Yap_MkApplTerm(f, arity, ts));
|
Term g = (Yap_MkApplTerm(f, arity, ts));
|
||||||
ap = rewriteUndefEngineQuery(ap, g, (ap->ModuleOfPred));
|
ap = rewriteUndefEngineQuery(ap, g, (ap->ModuleOfPred));
|
||||||
}
|
}
|
||||||
q.CurSlot = Yap_StartSlots();
|
|
||||||
q.p = P;
|
|
||||||
q.cp = CP;
|
|
||||||
// make sure this is safe
|
// make sure this is safe
|
||||||
// allow Prolog style exception handling
|
// allow Prolog style exception handling
|
||||||
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
//__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||||
@ -699,6 +723,8 @@ Term YAPEngine::fun(Term t) {
|
|||||||
YAPCatchError();
|
YAPCatchError();
|
||||||
{
|
{
|
||||||
YAP_LeaveGoal(result, &q);
|
YAP_LeaveGoal(result, &q);
|
||||||
|
ENV = LCL0-oenv;
|
||||||
|
B = (choiceptr)(LCL0-oB);
|
||||||
// PyEval_RestoreThread(_save);
|
// PyEval_RestoreThread(_save);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return ot;
|
return ot;
|
||||||
@ -727,6 +753,27 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, Term ts[])
|
||||||
|
: YAPPredicate(f, mod) {
|
||||||
|
|
||||||
|
/* ignore flags for now */
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
Term goal;
|
||||||
|
|
||||||
|
if (ts) {
|
||||||
|
size_t arity = f.arity();
|
||||||
|
goal = Yap_MkApplTerm(Yap_MkFunctor(f.name().asAtom(),arity), arity, ts);
|
||||||
|
nts = RepAppl(goal) + 1;
|
||||||
|
for (arity_t i = 0; i < arity; i++)
|
||||||
|
XREGS[i + 1] = ts[i];
|
||||||
|
} else {
|
||||||
|
goal = MkVarTerm();
|
||||||
|
}
|
||||||
|
openQuery();
|
||||||
|
names = YAPPairTerm(TermNil);
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
|
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
|
||||||
/* ignore flags for now */
|
/* ignore flags for now */
|
||||||
@ -766,6 +813,9 @@ bool YAPQuery::next() {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
bool result = false;
|
bool result = false;
|
||||||
// std::cerr << "next " << YAPTerm(goal).text() << "\n";
|
// std::cerr << "next " << YAPTerm(goal).text() << "\n";
|
||||||
|
q_h.CurSlot = Yap_StartSlots();
|
||||||
|
q_h.p = P;
|
||||||
|
q_h.cp = CP;
|
||||||
|
|
||||||
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
|
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
|
||||||
e = nullptr;
|
e = nullptr;
|
||||||
@ -827,7 +877,7 @@ bool YAPQuery::deterministic() {
|
|||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!q_open || q_state == 0)
|
if (!q_open || q_state == 0)
|
||||||
return false;
|
return false;
|
||||||
choiceptr myB = (choiceptr)(LCL0 - q_h.b);
|
choiceptr myB = (choiceptr)(LCL0 - q_h.b_entry);
|
||||||
return (B >= myB);
|
return (B >= myB);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
@ -1093,13 +1143,15 @@ std::stringstream s;
|
|||||||
void YAPEngine::reSet() {
|
void YAPEngine::reSet() {
|
||||||
/* ignore flags for now */
|
/* ignore flags for now */
|
||||||
if (B && B->cp_b && B->cp_ap != NOCODE)
|
if (B && B->cp_b && B->cp_ap != NOCODE)
|
||||||
YAP_LeaveGoal(false, &q);
|
// YAP_LeaveGoal(false, &q);
|
||||||
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
|
LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
|
||||||
if (LOCAL_CommittedError) {
|
if (LOCAL_CommittedError) {
|
||||||
LOCAL_CommittedError->errorNo = YAP_NO_ERROR;
|
LOCAL_CommittedError->errorNo = YAP_NO_ERROR;
|
||||||
free(LOCAL_CommittedError);
|
free(LOCAL_CommittedError);
|
||||||
LOCAL_CommittedError = NULL;
|
LOCAL_CommittedError = NULL;
|
||||||
}
|
}
|
||||||
|
pop_text_stack(0);
|
||||||
|
LOCAL_CurSlot = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Term YAPEngine::top_level(std::string s) {
|
Term YAPEngine::top_level(std::string s) {
|
||||||
|
@ -39,7 +39,6 @@ class X_API YAPQuery : public YAPPredicate {
|
|||||||
bool q_open;
|
bool q_open;
|
||||||
int q_state;
|
int q_state;
|
||||||
yhandle_t q_handles;
|
yhandle_t q_handles;
|
||||||
struct yami *q_p, *q_cp;
|
|
||||||
int q_flags;
|
int q_flags;
|
||||||
YAP_dogoalinfo q_h;
|
YAP_dogoalinfo q_h;
|
||||||
YAPPairTerm names;
|
YAPPairTerm names;
|
||||||
@ -54,10 +53,10 @@ class X_API YAPQuery : public YAPPredicate {
|
|||||||
q_state = 0;
|
q_state = 0;
|
||||||
q_flags = true; // PL_Q_PASS_EXCEPTION;
|
q_flags = true; // PL_Q_PASS_EXCEPTION;
|
||||||
|
|
||||||
q_p = P;
|
q_h.p = P;
|
||||||
q_cp = CP;
|
q_h.cp = CP;
|
||||||
// make sure this is safe
|
// make sure this is safe
|
||||||
q_handles = LOCAL_CurSlot;
|
q_h.CurSlot = LOCAL_CurSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
void openQuery();
|
void openQuery();
|
||||||
@ -321,7 +320,6 @@ private:
|
|||||||
YAPCallback *_callback;
|
YAPCallback *_callback;
|
||||||
YAPError yerror;
|
YAPError yerror;
|
||||||
void doInit(YAP_file_type_t BootMode, YAPEngineArgs *cargs);
|
void doInit(YAP_file_type_t BootMode, YAPEngineArgs *cargs);
|
||||||
YAP_dogoalinfo q;
|
|
||||||
YAPError e;
|
YAPError e;
|
||||||
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term &t, Term tmod);
|
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term &t, Term tmod);
|
||||||
|
|
||||||
|
1
H/Yap.h
1
H/Yap.h
@ -91,7 +91,6 @@ typedef YAP_Term Term;
|
|||||||
#define CellSize sizeof(CELL)
|
#define CellSize sizeof(CELL)
|
||||||
#define SmallSize sizeof(SMALLUNSGN)
|
#define SmallSize sizeof(SMALLUNSGN)
|
||||||
|
|
||||||
typedef YAP_Int Int;
|
|
||||||
typedef YAP_Float Float;
|
typedef YAP_Float Float;
|
||||||
typedef YAP_handle_t yhandle_t;
|
typedef YAP_handle_t yhandle_t;
|
||||||
|
|
||||||
|
12
H/YapText.h
12
H/YapText.h
@ -47,20 +47,20 @@ extern const void *MallocExportAsRO(const void *blk);
|
|||||||
extern int AllocLevel(void);
|
extern int AllocLevel(void);
|
||||||
|
|
||||||
#define push_text_stack() \
|
#define push_text_stack() \
|
||||||
(/* fprintf(stderr, " + *** %d %s:%s:%d\n", AllocLevel(),*/ \
|
( fprintf(stderr, " + *** %d %s:%s:%d\n", AllocLevel(), \
|
||||||
/* __FILE__, __FUNCTION__, __LINE__), */ \
|
__FILE__, __FUNCTION__, __LINE__), \
|
||||||
push_text_stack__(PASS_REGS1))
|
push_text_stack__(PASS_REGS1))
|
||||||
extern int push_text_stack__(USES_REGS1);
|
extern int push_text_stack__(USES_REGS1);
|
||||||
|
|
||||||
#define pop_text_stack(lvl) \
|
#define pop_text_stack(lvl) \
|
||||||
(/* fprintf(stderr, " - *** %d %s:%s:%d\n", AllocLevel(), __FILE__,*/ \
|
( fprintf(stderr, " - *** %d %s:%s:%d\n", AllocLevel(), __FILE__, \
|
||||||
/* __FUNCTION__, __LINE__), */ \
|
__FUNCTION__, __LINE__), \
|
||||||
pop_text_stack__(lvl))
|
pop_text_stack__(lvl))
|
||||||
extern int pop_text_stack__(int lvl USES_REGS);
|
extern int pop_text_stack__(int lvl USES_REGS);
|
||||||
|
|
||||||
#define pop_output_text_stack(lvl,p) \
|
#define pop_output_text_stack(lvl,p) \
|
||||||
(/*fprintf(stderr, "-- *** %d %s:%s:%d\n", AllocLevel(), __FILE__,*/ \
|
(fprintf(stderr, "-- *** %d %s:%s:%d\n", AllocLevel(), __FILE__, \
|
||||||
/* __FUNCTION__, __LINE__),*/ \
|
__FUNCTION__, __LINE__), \
|
||||||
pop_output_text_stack__(lvl,p))
|
pop_output_text_stack__(lvl,p))
|
||||||
extern void *pop_output_text_stack__(int lvl, const void *ox USES_REGS);
|
extern void *pop_output_text_stack__(int lvl, const void *ox USES_REGS);
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ extern Term Yap_SaveTerm(Term);
|
|||||||
extern Term Yap_SetGlobalVal(Atom, Term);
|
extern Term Yap_SetGlobalVal(Atom, Term);
|
||||||
extern Term Yap_GetGlobal(Atom);
|
extern Term Yap_GetGlobal(Atom);
|
||||||
extern Int Yap_DeleteGlobal(Atom);
|
extern Int Yap_DeleteGlobal(Atom);
|
||||||
extern void Yap_AllocateDefaultArena(size_t gsize, int wid);
|
extern void Yap_AllocateDefaultArena(size_t gsize, int wid, void *cs);
|
||||||
extern CELL *Yap_ArenaLimit(Term arena);
|
extern CELL *Yap_ArenaLimit(Term arena);
|
||||||
|
|
||||||
/* grow.c */
|
/* grow.c */
|
||||||
|
@ -297,6 +297,7 @@ check_function_exists(mkstemp HAVE_MKSTEMP)
|
|||||||
check_function_exists(mktemp HAVE_MKTEMP)
|
check_function_exists(mktemp HAVE_MKTEMP)
|
||||||
check_function_exists(nanosleep HAVE_NANOSLEEP)
|
check_function_exists(nanosleep HAVE_NANOSLEEP)
|
||||||
check_function_exists(mktime HAVE_MKTIME)
|
check_function_exists(mktime HAVE_MKTIME)
|
||||||
|
check_function_exists(mtrace HAVE_MTRACE)
|
||||||
check_function_exists(opendir HAVE_OPENDIR)
|
check_function_exists(opendir HAVE_OPENDIR)
|
||||||
if (NOT APPLE)
|
if (NOT APPLE)
|
||||||
check_function_exists(open_memstream HAVE_OPEN_MEMSTREAM)
|
check_function_exists(open_memstream HAVE_OPEN_MEMSTREAM)
|
||||||
|
@ -31,6 +31,7 @@ set (ENGINE_SOURCES
|
|||||||
C/corout.c
|
C/corout.c
|
||||||
C/cut_c.c
|
C/cut_c.c
|
||||||
C/dbase.c
|
C/dbase.c
|
||||||
|
C/dbload.c
|
||||||
C/dlmalloc.c
|
C/dlmalloc.c
|
||||||
C/errors.c
|
C/errors.c
|
||||||
C/eval.c
|
C/eval.c
|
||||||
|
@ -942,6 +942,11 @@ function. */
|
|||||||
#cmakedefine HAVE_MPI_H ${HAVE_MPI_H}
|
#cmakedefine HAVE_MPI_H ${HAVE_MPI_H}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <mtrace> glibc extension. */
|
||||||
|
#ifndef HAVE_MPI_H
|
||||||
|
#cmakedefine HAVE_MTRACE ${HAVE_TRACE}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Older versions of MPZ didn't have XOR */
|
/* Older versions of MPZ didn't have XOR */
|
||||||
#ifndef HAVE_MPZ_XOR
|
#ifndef HAVE_MPZ_XOR
|
||||||
#cmakedefine HAVE_MPZ_XOR ${HAVE_MPZ_XOR}
|
#cmakedefine HAVE_MPZ_XOR ${HAVE_MPZ_XOR}
|
||||||
|
@ -138,12 +138,13 @@ typedef enum {
|
|||||||
|
|
||||||
/* this should be opaque to the user */
|
/* this should be opaque to the user */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long b, b0; //> choice-point at entry
|
unsigned long b0, b_entry, b_exit; //> choice-point at entry
|
||||||
YAP_handle_t CurSlot; //> variables at entry
|
YAP_handle_t CurSlot; //> variables at entry
|
||||||
YAP_handle_t EndSlot; //> variables at successful execution
|
YAP_handle_t EndSlot; //> variables at successful execution
|
||||||
struct yami *p; //> Program Counter at entry
|
struct yami *p; //> Program Counter at entry
|
||||||
struct yami *cp; //> Continuation PC at entry
|
struct yami *cp; //> Continuation PC at entry
|
||||||
int lvl;
|
int lvl;
|
||||||
|
long env0;
|
||||||
unsigned long tr, h;
|
unsigned long tr, h;
|
||||||
} YAP_dogoalinfo;
|
} YAP_dogoalinfo;
|
||||||
|
|
||||||
|
@ -73,7 +73,8 @@ Yap_Error__(false, __FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
|
|||||||
{ if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; \
|
{ if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
|
//INLINE_ONLY
|
||||||
|
static Term Yap_ensure_atom__(const char *fu, const char *fi, int line,
|
||||||
Term in) {
|
Term in) {
|
||||||
Term t = Deref(in);
|
Term t = Deref(in);
|
||||||
// Term Context = Deref(ARG2);
|
// Term Context = Deref(ARG2);
|
||||||
|
14
os/sysbits.c
14
os/sysbits.c
@ -1934,6 +1934,19 @@ static Int p_sleep(USES_REGS1) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_mtrace()
|
||||||
|
{
|
||||||
|
#ifdef HAVE_MTRACE
|
||||||
|
Term t = Deref(ARG1);
|
||||||
|
if (t == TermTrue) mtrace();
|
||||||
|
else if (t == TermFalse) return muntrace();
|
||||||
|
else return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Yap_InitSysPreds(void) {
|
void Yap_InitSysPreds(void) {
|
||||||
Yap_InitCPred("log_event", 1, p_log_event, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("log_event", 1, p_log_event, SafePredFlag | SyncPredFlag);
|
||||||
Yap_InitCPred("sh", 0, p_sh, SafePredFlag | SyncPredFlag);
|
Yap_InitCPred("sh", 0, p_sh, SafePredFlag | SyncPredFlag);
|
||||||
@ -1972,5 +1985,6 @@ void Yap_InitSysPreds(void) {
|
|||||||
Yap_InitCPred("rmdir", 2, p_rmdir, SyncPredFlag);
|
Yap_InitCPred("rmdir", 2, p_rmdir, SyncPredFlag);
|
||||||
Yap_InitCPred("sleep", 1, p_sleep, SyncPredFlag);
|
Yap_InitCPred("sleep", 1, p_sleep, SyncPredFlag);
|
||||||
Yap_InitCPred("make_directory", 1, make_directory, SyncPredFlag);
|
Yap_InitCPred("make_directory", 1, make_directory, SyncPredFlag);
|
||||||
|
Yap_InitCPred("mtrace", 1, p_mtrace, SyncPredFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,6 +729,7 @@ char *Yap_TermToBuffer(Term t, int flags) {
|
|||||||
t = Deref(t);
|
t = Deref(t);
|
||||||
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
||||||
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
|
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
|
||||||
|
GLOBAL_Stream[sno].status &= ~FreeOnClose_Stream_f;
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
|
||||||
|
|
||||||
char *new = Yap_MemExportStreamPtr(sno);
|
char *new = Yap_MemExportStreamPtr(sno);
|
||||||
|
47
packages/bee/glucose-4/LICENCE
Normal file
47
packages/bee/glucose-4/LICENCE
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
Glucose -- Copyright (c) 2009-2014, Gilles Audemard, Laurent Simon
|
||||||
|
CRIL - Univ. Artois, France
|
||||||
|
LRI - Univ. Paris Sud, France (2009-2013)
|
||||||
|
Labri - Univ. Bordeaux, France
|
||||||
|
|
||||||
|
Syrup (Glucose Parallel) -- Copyright (c) 2013-2014, Gilles Audemard, Laurent Simon
|
||||||
|
CRIL - Univ. Artois, France
|
||||||
|
Labri - Univ. Bordeaux, France
|
||||||
|
|
||||||
|
Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
|
||||||
|
Glucose (sources until 2013, Glucose 3.0, single core) are exactly the same as Minisat on which it
|
||||||
|
is based on. (see below).
|
||||||
|
|
||||||
|
Glucose-Syrup sources are based on another copyright. Permissions and copyrights for the parallel
|
||||||
|
version of Glucose-Syrup (the "Software") are granted, free of charge, to deal with the Software
|
||||||
|
without restriction, including the rights to use, copy, modify, merge, publish, distribute,
|
||||||
|
sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
- The above and below copyrights notices and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software;
|
||||||
|
- The parallel version of Glucose (all files modified since Glucose 3.0 releases, 2013) cannot
|
||||||
|
be used in any competitive event (sat competitions/evaluations) without the express permission of
|
||||||
|
the authors (Gilles Audemard / Laurent Simon). This is also the case for any competitive event
|
||||||
|
using Glucose Parallel as an embedded SAT engine (single core or not).
|
||||||
|
|
||||||
|
|
||||||
|
--------------- Original Minisat Copyrights
|
||||||
|
|
||||||
|
Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
|
||||||
|
Copyright (c) 2007-2010, Niklas Sorensson
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||||
|
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||||
|
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||||
|
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||||
|
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
24
packages/bee/glucose-4/README
Normal file
24
packages/bee/glucose-4/README
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Directory overview:
|
||||||
|
==================
|
||||||
|
|
||||||
|
mtl/ Minisat Template Library
|
||||||
|
core/ A core version of the solver glucose (no main here)
|
||||||
|
simp/ An extended solver with simplification capabilities
|
||||||
|
parallel/ A multicore version of glucose
|
||||||
|
README
|
||||||
|
LICENSE
|
||||||
|
Changelog
|
||||||
|
|
||||||
|
To build (release version: without assertions, statically linked, etc):
|
||||||
|
======================================================================
|
||||||
|
Like minisat....
|
||||||
|
|
||||||
|
cd { simp | parallel }
|
||||||
|
make rs
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
======
|
||||||
|
|
||||||
|
in simp directory: ./glucose --help
|
||||||
|
|
||||||
|
in parallel directory: ./glucose-syrup --help
|
@ -114,6 +114,7 @@ static foreign_t array_to_python_view(term_t addr, term_t type, term_t szt,
|
|||||||
|
|
||||||
static foreign_t prolog_list_to_python_list(term_t plist, term_t pyt, term_t tlen) {
|
static foreign_t prolog_list_to_python_list(term_t plist, term_t pyt, term_t tlen) {
|
||||||
size_t sz, i;
|
size_t sz, i;
|
||||||
|
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
PyObject *pyl = term_to_python(pyt, true, NULL, true);
|
PyObject *pyl = term_to_python(pyt, true, NULL, true);
|
||||||
term_t targ = PL_new_term_ref();
|
term_t targ = PL_new_term_ref();
|
||||||
|
@ -197,11 +197,13 @@ X_API YAP_Term pythonToYAP(PyObject *pVal) {
|
|||||||
/* fputs("***>>\n", stderr); */
|
/* fputs("***>>\n", stderr); */
|
||||||
if (pVal == NULL)
|
if (pVal == NULL)
|
||||||
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, 0, NULL);
|
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, 0, NULL);
|
||||||
|
yhandle_t h0 = Yap_CurrentHandle();
|
||||||
Term t = python_to_term__(pVal);
|
Term t = python_to_term__(pVal);
|
||||||
/* fputs("<< *** ", stderr); */
|
/* fputs("<< *** ", stderr); */
|
||||||
/* Yap_DebugPlWrite(t); */
|
/* Yap_DebugPlWrite(t); */
|
||||||
/* fputs(" ***\n", stderr); */
|
/* fputs(" ***\n", stderr); */
|
||||||
// Py_DECREF(pVal);
|
// Py_DECREF(pVal);
|
||||||
|
Yap_CloseHandles(h0);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,13 +227,18 @@ PyObject *py_Local, *py_Global;
|
|||||||
*python_assign.
|
*python_assign.
|
||||||
*/
|
*/
|
||||||
bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
||||||
|
bool rc = true;
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
|
term_t inp = Yap_CurrentHandle();
|
||||||
context = find_obj(context, t, false);
|
context = find_obj(context, t, false);
|
||||||
// Yap_DebugPlWriteln(yt);
|
// Yap_DebugPlWriteln(yt);
|
||||||
switch (PL_term_type(t)) {
|
switch (PL_term_type(t)) {
|
||||||
case PL_VARIABLE: {
|
case PL_VARIABLE: {
|
||||||
if (context == NULL) // prevent a.V= N*N[N-1]
|
if (context == NULL) // prevent a.V= N*N[N-1]
|
||||||
return python_to_term(exp, t);
|
PL_reset_term_refs(inp);
|
||||||
|
|
||||||
|
rc = python_to_term(exp, t);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PL_STRING: {
|
case PL_STRING: {
|
||||||
@ -240,24 +247,34 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
PL_get_string_chars(t, &s,&l);
|
PL_get_string_chars(t, &s,&l);
|
||||||
if (!context)
|
if (!context)
|
||||||
context = py_Main;
|
context = py_Main;
|
||||||
if (PyObject_SetAttrString(context, s, exp) == 0)
|
if (PyObject_SetAttrString(context, s, exp) == 0) {
|
||||||
return true;
|
PL_reset_term_refs(inp);
|
||||||
|
;
|
||||||
|
rc = true;
|
||||||
|
} else {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
return false;
|
PL_reset_term_refs(inp);
|
||||||
|
rc = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case PL_ATOM: {
|
case PL_ATOM: {
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
PL_get_atom_chars(t, &s);
|
PL_get_atom_chars(t, &s);
|
||||||
if (!context)
|
if (!context)
|
||||||
context = py_Main;
|
context = py_Main;
|
||||||
if (PyObject_SetAttrString(context, s, exp) == 0)
|
if (PyObject_SetAttrString(context, s, exp) == 0){
|
||||||
return true;
|
rc = true;
|
||||||
return false;
|
} else {
|
||||||
|
rc = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case PL_INTEGER:
|
case PL_INTEGER:
|
||||||
case PL_FLOAT:
|
case PL_FLOAT:
|
||||||
// domain or type erro?
|
// domain or type erro?
|
||||||
return false;
|
rc = false;
|
||||||
|
break;
|
||||||
default: {
|
default: {
|
||||||
term_t tail = PL_new_term_ref(), arg = PL_new_term_ref();
|
term_t tail = PL_new_term_ref(), arg = PL_new_term_ref();
|
||||||
size_t len, i;
|
size_t len, i;
|
||||||
@ -271,60 +288,69 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *p;
|
PyObject *p;
|
||||||
if (!PL_get_list(t, arg, t)) {
|
if (!PL_get_list(t, arg, t)) {
|
||||||
PL_reset_term_refs(tail);
|
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
}
|
rc = false;
|
||||||
|
} else {
|
||||||
if ((p = PySequence_GetItem(exp, i)) == NULL)
|
if ((p = PySequence_GetItem(exp, i)) == NULL)
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
if (!python_assign(arg, p, context)) {
|
rc = rc && python_assign(arg, p, context);
|
||||||
PL_reset_term_refs(tail);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
while(PL_is_pair(t)) {
|
||||||
|
context = find_obj(context, t, false);
|
||||||
}
|
}
|
||||||
|
rc = python_assign(t, exp, context);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
functor_t fun;
|
functor_t fun;
|
||||||
|
|
||||||
if (!PL_get_functor(t, &fun)) {
|
if (!PL_get_functor(t, &fun)) {
|
||||||
PL_reset_term_refs(tail);
|
rc = false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fun == FUNCTOR_sqbrackets2) {
|
if (fun == FUNCTOR_sqbrackets2) {
|
||||||
// tail is the object o
|
// tail is the object o
|
||||||
if (!PL_get_arg(2, t, tail)) {
|
if (!PL_get_arg(2, t, tail)) {
|
||||||
PL_reset_term_refs(tail);
|
rc = false;
|
||||||
return false;
|
} else {
|
||||||
}
|
|
||||||
PyObject *o = term_to_python(tail, true, context, false);
|
PyObject *o = term_to_python(tail, true, context, false);
|
||||||
// t now refers to the index
|
// t now refers to the index
|
||||||
if (!PL_get_arg(1, t, t) || !PL_get_list(t, t, tail) ||
|
if (!PL_get_arg(1, t, t) || !PL_get_list(t, t, tail) ||
|
||||||
!PL_get_nil(tail)) {
|
!PL_get_nil(tail)) {
|
||||||
PL_reset_term_refs(tail);
|
rc = false;
|
||||||
return false;
|
} else {
|
||||||
}
|
|
||||||
PyObject *i = term_to_python(t, true, NULL, false);
|
PyObject *i = term_to_python(t, true, NULL, false);
|
||||||
// check numeric
|
// check numeric
|
||||||
if (PySequence_Check(o) && PyLong_Check(i)) {
|
if (PySequence_Check(o) && PyLong_Check(i)) {
|
||||||
long int j;
|
long int j;
|
||||||
j = PyLong_AsLong(i);
|
j = PyLong_AsLong(i);
|
||||||
return PySequence_SetItem(o, j, exp) == 0;
|
rc = PySequence_SetItem(o, j, exp) == 0;
|
||||||
}
|
}
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
if (PySequence_Check(o) && PyInt_Check(i)) {
|
if (PySequence_Check(o) && PyInt_Check(i)) {
|
||||||
long int j;
|
long int j;
|
||||||
j = PyInt_AsLong(i);
|
j = PyInt_AsLong(i);
|
||||||
return PySequence_SetItem(o, i, exp) == 0;
|
szzb rc = PySequence_SetItem(o, i, exp) == 0;
|
||||||
}
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (PyDict_Check(o)) {
|
if (PyDict_Check(o)) {
|
||||||
if (PyDict_SetItem(o, i, exp) == 0) {
|
if (PyDict_SetItem(o, i, exp) == 0) {
|
||||||
return true;
|
PL_reset_term_refs(inp);
|
||||||
|
;
|
||||||
|
rc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (PyObject_SetAttr(o, i, exp) == 0) {
|
if (PyObject_SetAttr(o, i, exp) == 0) {
|
||||||
return true;
|
PL_reset_term_refs(inp);
|
||||||
|
;
|
||||||
|
rc = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
atom_t s;
|
atom_t s;
|
||||||
int n, i;
|
int n, i;
|
||||||
PL_get_name_arity(t, &s, &n);
|
PL_get_name_arity(t, &s, &n);
|
||||||
@ -334,27 +360,24 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
|
|||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++) {
|
||||||
PyObject *p;
|
PyObject *p;
|
||||||
if (!PL_get_arg(i, t, arg)) {
|
if (!PL_get_arg(i, t, arg)) {
|
||||||
PL_reset_term_refs(tail);
|
o = NULL;
|
||||||
o = false;
|
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = PySequence_GetItem(exp, i - 1)) == NULL)
|
if ((p = PySequence_GetItem(exp, i - 1)) == NULL)
|
||||||
p = Py_None;
|
p = Py_None;
|
||||||
else if (!python_assign(arg, p, NULL)) {
|
rc = python_assign(arg, p, NULL);
|
||||||
PL_reset_term_refs(tail);
|
|
||||||
o = NULL;
|
}
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
PL_reset_term_refs(inp);
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
return rc;
|
||||||
}
|
|
||||||
}
|
|
||||||
PL_reset_term_refs(tail);
|
|
||||||
}
|
|
||||||
PyErr_Print();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,14 @@
|
|||||||
#undef _XOPEN_SOURCE // python does its own thing
|
#undef _XOPEN_SOURCE // python does its own thing
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#undef _POSIX_C_SOURCE
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
#include <Yap.h>
|
#include <Yap.h>
|
||||||
|
|
||||||
|
|
||||||
#include <SWI-Prolog.h>
|
#include <SWI-Prolog.h>
|
||||||
#ifdef HAVE_STAT
|
#ifdef HAVE_STAT
|
||||||
#undef HAVE_STATa
|
#undef HAVE_STATa
|
||||||
@ -201,22 +205,21 @@ extern PyObject *YEC(PyObject *c,PyObject *a ,PyObject *d , int line, const char
|
|||||||
extern void YEM(const char *ex, int line, const char *file, const char *code);
|
extern void YEM(const char *ex, int line, const char *file, const char *code);
|
||||||
extern void pyErrorHandler__(int line, const char *file, const char *code);
|
extern void pyErrorHandler__(int line, const char *file, const char *code);
|
||||||
|
|
||||||
#define pyErrorHandler() \
|
#define PyStart() PyErr_Clear()
|
||||||
{ \
|
|
||||||
if (PyErr_Occurred()) { \
|
|
||||||
|
#define pyErrorHandler() if (PyErr_Occurred()) { \
|
||||||
pyErrorHandler__(__LINE__, __FILE__, __FUNCTION__); \
|
pyErrorHandler__(__LINE__, __FILE__, __FUNCTION__); \
|
||||||
} \
|
} \
|
||||||
}
|
|
||||||
|
|
||||||
#define pyErrorAndReturn(x) \
|
#define pyErrorAndReturn(x) \
|
||||||
{ \
|
|
||||||
if (PyErr_Occurred()) { \
|
if (PyErr_Occurred()) { \
|
||||||
pyErrorHandler__(__LINE__, __FILE__, __FUNCTION__); \
|
pyErrorHandler__(__LINE__, __FILE__, __FUNCTION__); \
|
||||||
} \
|
} \
|
||||||
return (x); \
|
return (x)
|
||||||
}
|
|
||||||
// #define pyErrorAndReturn( x, y ) return x
|
|
||||||
|
|
||||||
|
// #define pyErrorAndReturn( x, y ) return x
|
||||||
extern PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt);
|
extern PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt);
|
||||||
extern PyObject *compound_to_pytree(term_t t, PyObject *context, bool cvt);
|
extern PyObject *compound_to_pytree(term_t t, PyObject *context, bool cvt);
|
||||||
|
|
||||||
|
@ -112,12 +112,12 @@ find_obj(PyObject *ob, term_t l, bool eval) {
|
|||||||
YAP_Term hd, yt;
|
YAP_Term hd, yt;
|
||||||
|
|
||||||
py_Context = NULL;
|
py_Context = NULL;
|
||||||
yt = YAP_GetFromSlot(l);
|
|
||||||
// Yap_DebugPlWriteln(yt);
|
// Yap_DebugPlWriteln(yt);
|
||||||
while (YAP_IsPairTerm(yt)) {
|
if (l == 0)
|
||||||
|
return Py_None;
|
||||||
|
while (YAP_IsPairTerm((yt = YAP_GetFromSlot(l)))) {
|
||||||
hd = YAP_HeadOfTerm(yt);
|
hd = YAP_HeadOfTerm(yt);
|
||||||
yt = YAP_TailOfTerm(yt);
|
Yap_PutInHandle(l, YAP_TailOfTerm(yt));
|
||||||
YAP_PutInSlot(l, yt);
|
|
||||||
ob = yap_to_python(hd, true, ob, false);
|
ob = yap_to_python(hd, true, ob, false);
|
||||||
if (!ob) {
|
if (!ob) {
|
||||||
return Py_None;
|
return Py_None;
|
||||||
|
@ -20,6 +20,7 @@ void pyErrorHandler__(int line, const char *file, const char *code) {
|
|||||||
static foreign_t python_len(term_t tobj, term_t tf) {
|
static foreign_t python_len(term_t tobj, term_t tf) {
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
o = term_to_python(tobj, true, NULL, true);
|
o = term_to_python(tobj, true, NULL, true);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
@ -32,13 +33,14 @@ static foreign_t python_len(term_t tobj, term_t tf) {
|
|||||||
static foreign_t python_represent( term_t name, term_t tobj) {
|
static foreign_t python_represent( term_t name, term_t tobj) {
|
||||||
term_t stackp = python_acquire_GIL();
|
term_t stackp = python_acquire_GIL();
|
||||||
PyObject *e;
|
PyObject *e;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
e = term_to_python(tobj, false, NULL, false);
|
e = term_to_python(tobj, false, NULL, false);
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
python_release_GIL(stackp);
|
python_release_GIL(stackp);
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
}
|
}
|
||||||
bool b = python_assign(name, e, NULL);
|
foreign_t b = python_assign(name, e, NULL);
|
||||||
python_release_GIL(stackp);
|
python_release_GIL(stackp);
|
||||||
pyErrorAndReturn(b);
|
pyErrorAndReturn(b);
|
||||||
}
|
}
|
||||||
@ -53,6 +55,7 @@ static foreign_t python_clear_errors(void) {
|
|||||||
static foreign_t python_dir(term_t tobj, term_t tf) {
|
static foreign_t python_dir(term_t tobj, term_t tf) {
|
||||||
PyObject *dir;
|
PyObject *dir;
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
o = term_to_python(tobj, true, NULL, true);
|
o = term_to_python(tobj, true, NULL, true);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
@ -70,6 +73,7 @@ static foreign_t python_index(term_t tobj, term_t tindex, term_t val) {
|
|||||||
PyObject *i;
|
PyObject *i;
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
PyObject *f;
|
PyObject *f;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
o = term_to_python(tobj, true, NULL, true);
|
o = term_to_python(tobj, true, NULL, true);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
@ -96,6 +100,7 @@ static foreign_t python_index(term_t tobj, term_t tindex, term_t val) {
|
|||||||
|
|
||||||
static foreign_t python_is(term_t tobj, term_t tf) {
|
static foreign_t python_is(term_t tobj, term_t tf) {
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
term_t lim = python_acquire_GIL();
|
term_t lim = python_acquire_GIL();
|
||||||
|
|
||||||
@ -112,13 +117,13 @@ static foreign_t python_is(term_t tobj, term_t tf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t python_proc(term_t tobj) {
|
static foreign_t python_proc(term_t tobj) {
|
||||||
|
PyStart();
|
||||||
PyObject *o;
|
PyObject *o;
|
||||||
|
|
||||||
term_t lim = python_acquire_GIL();
|
term_t lim = python_acquire_GIL();
|
||||||
|
|
||||||
o = term_to_python(tobj, true, NULL, true);
|
o = term_to_python(tobj, true, NULL, true);
|
||||||
python_release_GIL(lim);
|
python_release_GIL(lim);
|
||||||
bool rc = o != NULL;
|
foreign_t rc = o != NULL;
|
||||||
pyErrorAndReturn(rc);
|
pyErrorAndReturn(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +139,7 @@ static foreign_t python_slice(term_t parent, term_t indx, term_t tobj) {
|
|||||||
p = term_to_python(parent, true, NULL, true);
|
p = term_to_python(parent, true, NULL, true);
|
||||||
// Exp
|
// Exp
|
||||||
if (!pI || !p) {
|
if (!pI || !p) {
|
||||||
{
|
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
}
|
|
||||||
} else if ((pF = PySequence_GetSlice(p, 0, 0)) == NULL) {
|
} else if ((pF = PySequence_GetSlice(p, 0, 0)) == NULL) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
{ pyErrorAndReturn(false); }
|
{ pyErrorAndReturn(false); }
|
||||||
@ -153,6 +156,7 @@ static foreign_t python_slice(term_t parent, term_t indx, term_t tobj) {
|
|||||||
|
|
||||||
static foreign_t python_apply(term_t tin, term_t targs, term_t keywds,
|
static foreign_t python_apply(term_t tin, term_t targs, term_t keywds,
|
||||||
term_t tf) {
|
term_t tf) {
|
||||||
|
PyStart();
|
||||||
PyObject *pF;
|
PyObject *pF;
|
||||||
PyObject *pArgs, *pKeywords;
|
PyObject *pArgs, *pKeywords;
|
||||||
PyObject *pValue;
|
PyObject *pValue;
|
||||||
@ -162,7 +166,6 @@ static foreign_t python_apply(term_t tin, term_t targs, term_t keywds,
|
|||||||
term_t targ = PL_new_term_ref();
|
term_t targ = PL_new_term_ref();
|
||||||
|
|
||||||
pF = term_to_python(tin, true, NULL, true);
|
pF = term_to_python(tin, true, NULL, true);
|
||||||
PyErr_Clear();
|
|
||||||
if (pF == NULL) {
|
if (pF == NULL) {
|
||||||
{
|
{
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
@ -237,6 +240,7 @@ static foreign_t python_apply(term_t tin, term_t targs, term_t keywds,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t assign_python(term_t exp, term_t name) {
|
static foreign_t assign_python(term_t exp, term_t name) {
|
||||||
|
PyStart();
|
||||||
term_t stackp = python_acquire_GIL();
|
term_t stackp = python_acquire_GIL();
|
||||||
PyObject *e = term_to_python(exp, true, NULL, true);
|
PyObject *e = term_to_python(exp, true, NULL, true);
|
||||||
|
|
||||||
@ -244,7 +248,7 @@ static foreign_t assign_python(term_t exp, term_t name) {
|
|||||||
python_release_GIL(stackp);
|
python_release_GIL(stackp);
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
}
|
}
|
||||||
bool b = python_assign(name, e, NULL);
|
foreign_t b = python_assign(name, e, NULL);
|
||||||
python_release_GIL(stackp);
|
python_release_GIL(stackp);
|
||||||
pyErrorAndReturn(b);
|
pyErrorAndReturn(b);
|
||||||
}
|
}
|
||||||
@ -269,7 +273,7 @@ static foreign_t python_string_to(term_t f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
PyObject *pI, *pArgs, *pOut;
|
PyObject *pI, *pArgs, *pOut;
|
||||||
PyObject *env;
|
PyObject *env;
|
||||||
atom_t name;
|
atom_t name;
|
||||||
@ -331,7 +335,7 @@ static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t python_access(term_t obj, term_t f, term_t out) {
|
static foreign_t python_access(term_t obj, term_t f, term_t out) {
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
PyObject *o = term_to_python(obj, true, NULL, true), *pValue, *pArgs, *pF;
|
PyObject *o = term_to_python(obj, true, NULL, true), *pValue, *pArgs, *pF;
|
||||||
atom_t name;
|
atom_t name;
|
||||||
char *s = NULL;
|
char *s = NULL;
|
||||||
@ -400,7 +404,7 @@ static foreign_t python_field(term_t parent, term_t att, term_t tobj) {
|
|||||||
atom_t name;
|
atom_t name;
|
||||||
char *s;
|
char *s;
|
||||||
int arity;
|
int arity;
|
||||||
|
PyStart();
|
||||||
if (!PL_get_name_arity(att, &name, &arity)) {
|
if (!PL_get_name_arity(att, &name, &arity)) {
|
||||||
{
|
{
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
@ -448,14 +452,14 @@ static foreign_t python_field(term_t parent, term_t att, term_t tobj) {
|
|||||||
static foreign_t python_main_module(term_t mod) {
|
static foreign_t python_main_module(term_t mod) {
|
||||||
{
|
{
|
||||||
foreign_t rc;
|
foreign_t rc;
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
rc = address_to_term(py_Main, mod);
|
rc = address_to_term(py_Main, mod);
|
||||||
pyErrorAndReturn(rc);
|
pyErrorAndReturn(rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static foreign_t python_function(term_t tobj) {
|
static foreign_t python_function(term_t tobj) {
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
PyObject *obj = term_to_python(tobj, true, NULL, true);
|
PyObject *obj = term_to_python(tobj, true, NULL, true);
|
||||||
foreign_t rc = PyFunction_Check(obj);
|
foreign_t rc = PyFunction_Check(obj);
|
||||||
|
|
||||||
@ -465,7 +469,7 @@ static foreign_t python_function(term_t tobj) {
|
|||||||
foreign_t python_builtin(term_t out) {
|
foreign_t python_builtin(term_t out) {
|
||||||
{
|
{
|
||||||
foreign_t rc;
|
foreign_t rc;
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
rc = address_to_term(py_Builtin, out);
|
rc = address_to_term(py_Builtin, out);
|
||||||
pyErrorAndReturn(rc);
|
pyErrorAndReturn(rc);
|
||||||
}
|
}
|
||||||
@ -476,7 +480,7 @@ static foreign_t python_run_file(term_t file) {
|
|||||||
size_t len;
|
size_t len;
|
||||||
char si[256];
|
char si[256];
|
||||||
s = si;
|
s = si;
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
if (PL_get_nchars(file, &len, &s, CVT_ALL | CVT_EXCEPTION)) {
|
if (PL_get_nchars(file, &len, &s, CVT_ALL | CVT_EXCEPTION)) {
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
PyObject *PyFileObject = PyFile_FromString(si, "r");
|
PyObject *PyFileObject = PyFile_FromString(si, "r");
|
||||||
@ -499,11 +503,11 @@ extern PyThreadState *YAP_save;
|
|||||||
|
|
||||||
static foreign_t python_run_command(term_t cmd) {
|
static foreign_t python_run_command(term_t cmd) {
|
||||||
char *s;
|
char *s;
|
||||||
bool rc = false;
|
foreign_t rc = false;
|
||||||
size_t len;
|
size_t len;
|
||||||
char si[256];
|
char si[256];
|
||||||
|
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
s = si;
|
s = si;
|
||||||
if (PL_get_nchars(cmd, &len, &s, CVT_ALL | CVT_EXCEPTION)) {
|
if (PL_get_nchars(cmd, &len, &s, CVT_ALL | CVT_EXCEPTION)) {
|
||||||
PyRun_SimpleString(s);
|
PyRun_SimpleString(s);
|
||||||
@ -519,7 +523,7 @@ static foreign_t python_run_script(term_t cmd, term_t fun) {
|
|||||||
PyObject *pArgs = NULL, *pValue;
|
PyObject *pArgs = NULL, *pValue;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
s = si;
|
s = si;
|
||||||
if (PL_get_nchars(cmd, &len, &s, CVT_ALL | CVT_EXCEPTION) &&
|
if (PL_get_nchars(cmd, &len, &s, CVT_ALL | CVT_EXCEPTION) &&
|
||||||
(s = sf) != NULL &&
|
(s = sf) != NULL &&
|
||||||
@ -571,7 +575,7 @@ static foreign_t python_run_script(term_t cmd, term_t fun) {
|
|||||||
|
|
||||||
static foreign_t python_export(term_t t, term_t pl) {
|
static foreign_t python_export(term_t t, term_t pl) {
|
||||||
foreign_t rc = false;
|
foreign_t rc = false;
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
if (PL_is_functor(t, FUNCTOR_pointer1)) {
|
if (PL_is_functor(t, FUNCTOR_pointer1)) {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
term_t targ = PL_new_term_ref();
|
term_t targ = PL_new_term_ref();
|
||||||
@ -600,7 +604,8 @@ static foreign_t python_export(term_t t, term_t pl) {
|
|||||||
*/
|
*/
|
||||||
static int python_import(term_t mname, term_t mod) {
|
static int python_import(term_t mname, term_t mod) {
|
||||||
PyObject *pName;
|
PyObject *pName;
|
||||||
bool do_as = false;
|
foreign_t do_as = false;
|
||||||
|
PyStart();
|
||||||
|
|
||||||
char s0[MAXPATHLEN], *s = s0;
|
char s0[MAXPATHLEN], *s = s0;
|
||||||
s[0] = '\0';
|
s[0] = '\0';
|
||||||
@ -673,7 +678,7 @@ static int python_import(term_t mname, term_t mod) {
|
|||||||
|
|
||||||
static foreign_t python_to_rhs(term_t inp, term_t t) {
|
static foreign_t python_to_rhs(term_t inp, term_t t) {
|
||||||
PyObject *pVal;
|
PyObject *pVal;
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
pVal = term_to_python(inp, true, NULL, true);
|
pVal = term_to_python(inp, true, NULL, true);
|
||||||
if (pVal == NULL)
|
if (pVal == NULL)
|
||||||
pyErrorAndReturn(false);
|
pyErrorAndReturn(false);
|
||||||
@ -681,7 +686,7 @@ static foreign_t python_to_rhs(term_t inp, term_t t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// static PyThreadState *_saveP = NULL;
|
// static PyThreadState *_saveP = NULL;
|
||||||
static bool _threaded = true;
|
static foreign_t _threaded = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static YAP_Int
|
static YAP_Int
|
||||||
@ -707,7 +712,7 @@ PyThreadState *tstate;
|
|||||||
|
|
||||||
static YAP_Int p_python_threaded(void) {
|
static YAP_Int p_python_threaded(void) {
|
||||||
|
|
||||||
PyErr_Clear();
|
PyStart();
|
||||||
// PyEval_ReleaseThread(tstate);
|
// PyEval_ReleaseThread(tstate);
|
||||||
// _threaded = true;
|
// _threaded = true;
|
||||||
// _locked = 0;
|
// _locked = 0;
|
||||||
@ -730,7 +735,6 @@ term_t python_acquire_GIL(void) {
|
|||||||
PL_put_integer(curSlot, gstatei++);
|
PL_put_integer(curSlot, gstatei++);
|
||||||
return curSlot;
|
return curSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool python_release_GIL(term_t curBlock) {
|
bool python_release_GIL(term_t curBlock) {
|
||||||
int gstateix;
|
int gstateix;
|
||||||
gstatei--;
|
gstatei--;
|
||||||
|
@ -334,7 +334,7 @@ prolog_file_name(File, PrologFileName) :-
|
|||||||
system:true_file_name(File, PrologFileName).
|
system:true_file_name(File, PrologFileName).
|
||||||
prolog_file_name(File, PrologFileName) :-
|
prolog_file_name(File, PrologFileName) :-
|
||||||
'$do_error'(type_error(atom,File), prolog_file_name(File, PrologFileName)).
|
'$do_error'(type_error(atom,File), prolog_file_name(File, PrologFileName)).
|
||||||
|
:- start_low_level_trace.
|
||||||
/**
|
/**
|
||||||
@pred path(-Directories:list) is det,deprecated
|
@pred path(-Directories:list) is det,deprecated
|
||||||
|
|
||||||
@ -344,6 +344,7 @@ prolog_file_name(File, PrologFileName) :-
|
|||||||
*/
|
*/
|
||||||
path(Path) :-
|
path(Path) :-
|
||||||
findall(X,'$in_path'(X),Path).
|
findall(X,'$in_path'(X),Path).
|
||||||
|
:- stop_low_level_trace.
|
||||||
|
|
||||||
'$in_path'(X) :-
|
'$in_path'(X) :-
|
||||||
recorded('$path',Path,_),
|
recorded('$path',Path,_),
|
||||||
|
@ -133,7 +133,7 @@ undefined_query(G0, M0, Cut) :-
|
|||||||
% we found an import, and call again
|
% we found an import, and call again
|
||||||
% we have user code in the unknown_predicate
|
% we have user code in the unknown_predicate
|
||||||
% we fail, output a message, and just generate an exception.
|
% we fail, output a message, and just generate an exception.
|
||||||
'$undefp'([M0|G0],ok) :-
|
'$undefp'([M0|G0],_) :-
|
||||||
'$search_undef'(M0:G0, M:G),
|
'$search_undef'(M0:G0, M:G),
|
||||||
'$trace'(M:G).
|
'$trace'(M:G).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user