more indexing fixes
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@871 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
0d441d069d
commit
f6170508cd
107
C/index.c
107
C/index.c
@ -2797,7 +2797,7 @@ do_consts(GroupDef *grp, Term t, PredEntry *ap, int compound_term, CELL *sreg, U
|
|||||||
n = count_consts(grp);
|
n = count_consts(grp);
|
||||||
lbl = new_label();
|
lbl = new_label();
|
||||||
Yap_emit(label_op, lbl, Zero);
|
Yap_emit(label_op, lbl, Zero);
|
||||||
cs = emit_cswitch(n, nxtlbl, ap);
|
cs = emit_cswitch(n, (UInt)FAILCODE, ap);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
AtomSwiEntry *ics;
|
AtomSwiEntry *ics;
|
||||||
ClauseDef *max = min;
|
ClauseDef *max = min;
|
||||||
@ -2866,7 +2866,7 @@ do_funcs(GroupDef *grp, Term t, PredEntry *ap, UInt argno, int first, int last_a
|
|||||||
lbl = new_label();
|
lbl = new_label();
|
||||||
Yap_emit(label_op, lbl, Zero);
|
Yap_emit(label_op, lbl, Zero);
|
||||||
/* generate a switch */
|
/* generate a switch */
|
||||||
fs = emit_fswitch(n, nxtlbl, ap);
|
fs = emit_fswitch(n, (UInt)FAILCODE, ap);
|
||||||
for (i = 0; i < n ; i++) {
|
for (i = 0; i < n ; i++) {
|
||||||
Functor f = (Functor)RepAppl(min->Tag);
|
Functor f = (Functor)RepAppl(min->Tag);
|
||||||
FuncSwiEntry *ifs;
|
FuncSwiEntry *ifs;
|
||||||
@ -3732,7 +3732,7 @@ expand_index(PredEntry *ap) {
|
|||||||
/* this is will be used as a new PC */
|
/* this is will be used as a new PC */
|
||||||
CELL *top = (CELL *) TR;
|
CELL *top = (CELL *) TR;
|
||||||
UInt arity = 0;
|
UInt arity = 0;
|
||||||
UInt lab, fail_l, clleft, arg0 = 0;
|
UInt lab, fail_l, clleft, i = 0;
|
||||||
|
|
||||||
sp = stack = (istack_entry *)top;
|
sp = stack = (istack_entry *)top;
|
||||||
labelno = 1;
|
labelno = 1;
|
||||||
@ -3842,9 +3842,9 @@ expand_index(PredEntry *ap) {
|
|||||||
case _switch_on_type:
|
case _switch_on_type:
|
||||||
t = Deref(ARG1);
|
t = Deref(ARG1);
|
||||||
argno = 1;
|
argno = 1;
|
||||||
|
i = 0;
|
||||||
sp = reset_stack(stack);
|
sp = reset_stack(stack);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
arg0 = 1;
|
|
||||||
labp = &(ipc->u.llll.l4);
|
labp = &(ipc->u.llll.l4);
|
||||||
ipc = ipc->u.llll.l4;
|
ipc = ipc->u.llll.l4;
|
||||||
} else if (IsPairTerm(t)) {
|
} else if (IsPairTerm(t)) {
|
||||||
@ -3856,7 +3856,6 @@ expand_index(PredEntry *ap) {
|
|||||||
sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
||||||
ipc = ipc->u.llll.l3;
|
ipc = ipc->u.llll.l3;
|
||||||
} else {
|
} else {
|
||||||
arg0 = 1;
|
|
||||||
ipc = ipc->u.llll.l2;
|
ipc = ipc->u.llll.l2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3864,8 +3863,8 @@ expand_index(PredEntry *ap) {
|
|||||||
t = Deref(ARG1);
|
t = Deref(ARG1);
|
||||||
sp = reset_stack(stack);
|
sp = reset_stack(stack);
|
||||||
argno = 1;
|
argno = 1;
|
||||||
|
i = 0;
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
arg0 = 1;
|
|
||||||
labp = &(ipc->u.ollll.l4);
|
labp = &(ipc->u.ollll.l4);
|
||||||
ipc = ipc->u.ollll.l4;
|
ipc = ipc->u.ollll.l4;
|
||||||
} else if (IsPairTerm(t)) {
|
} else if (IsPairTerm(t)) {
|
||||||
@ -3877,15 +3876,14 @@ expand_index(PredEntry *ap) {
|
|||||||
sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
sp = push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
||||||
ipc = ipc->u.ollll.l3;
|
ipc = ipc->u.ollll.l3;
|
||||||
} else {
|
} else {
|
||||||
arg0 = 1;
|
|
||||||
ipc = ipc->u.ollll.l2;
|
ipc = ipc->u.ollll.l2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _switch_on_arg_type:
|
case _switch_on_arg_type:
|
||||||
argno = arg_from_x(ipc->u.xllll.x);
|
argno = arg_from_x(ipc->u.xllll.x);
|
||||||
|
i = 0;
|
||||||
t = Deref(XREGS[argno]);
|
t = Deref(XREGS[argno]);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
arg0 = 1;
|
|
||||||
labp = &(ipc->u.xllll.l4);
|
labp = &(ipc->u.xllll.l4);
|
||||||
ipc = ipc->u.xllll.l4;
|
ipc = ipc->u.xllll.l4;
|
||||||
} else if (IsPairTerm(t)) {
|
} else if (IsPairTerm(t)) {
|
||||||
@ -3897,33 +3895,29 @@ expand_index(PredEntry *ap) {
|
|||||||
sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)));
|
sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)));
|
||||||
ipc = ipc->u.xllll.l3;
|
ipc = ipc->u.xllll.l3;
|
||||||
} else {
|
} else {
|
||||||
arg0 = argno;
|
|
||||||
ipc = ipc->u.xllll.l2;
|
ipc = ipc->u.xllll.l2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _switch_on_sub_arg_type:
|
case _switch_on_sub_arg_type:
|
||||||
{
|
i = ipc->u.sllll.s;
|
||||||
COUNT argno = ipc->u.sllll.s;
|
t = Deref(s_reg[i]);
|
||||||
|
if (i != arity-1) is_last_arg = FALSE;
|
||||||
t = Deref(s_reg[ipc->u.sllll.s]);
|
t = Deref(s_reg[i]);
|
||||||
if (argno != arity-1) is_last_arg = FALSE;
|
if (IsVarTerm(t)) {
|
||||||
t = Deref(s_reg[argno]);
|
labp = &(ipc->u.sllll.l4);
|
||||||
if (IsVarTerm(t)) {
|
ipc = ipc->u.sllll.l4;
|
||||||
arg0 = argno+1;
|
i++;
|
||||||
labp = &(ipc->u.sllll.l4);
|
} else if (IsPairTerm(t)) {
|
||||||
ipc = ipc->u.sllll.l4;
|
s_reg = RepPair(t);
|
||||||
} else if (IsPairTerm(t)) {
|
sp = push_stack(sp, -i-1, AbsPair(NULL));
|
||||||
s_reg = RepPair(t);
|
labp = &(ipc->u.sllll.l1);
|
||||||
sp = push_stack(sp, -argno-1, AbsPair(NULL));
|
ipc = ipc->u.sllll.l1;
|
||||||
labp = &(ipc->u.sllll.l1);
|
} else if (IsApplTerm(t)) {
|
||||||
ipc = ipc->u.sllll.l1;
|
sp = push_stack(sp, -i-1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
||||||
} else if (IsApplTerm(t)) {
|
ipc = ipc->u.sllll.l3;
|
||||||
sp = push_stack(sp, -argno-1, AbsAppl((CELL *)FunctorOfTerm(t)));
|
} else {
|
||||||
ipc = ipc->u.sllll.l3;
|
ipc = ipc->u.sllll.l2;
|
||||||
} else {
|
i++;
|
||||||
arg0 = argno+1;
|
|
||||||
ipc = ipc->u.sllll.l2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _if_not_then:
|
case _if_not_then:
|
||||||
@ -3987,17 +3981,12 @@ expand_index(PredEntry *ap) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case _expand_index:
|
case _expand_index:
|
||||||
if (alt != NULL) {
|
if (alt != NULL && ap->PredFlags & LogUpdatePredFlag) {
|
||||||
if (ap->PredFlags & LogUpdatePredFlag) {
|
op_numbers fop = Yap_op_from_opcode(alt->opc);
|
||||||
op_numbers fop = Yap_op_from_opcode(alt->opc);
|
if (fop == _enter_lu_pred)
|
||||||
if (fop == _enter_lu_pred)
|
alt = alt->u.Ill.l1;
|
||||||
alt = alt->u.Ill.l1;
|
if (fop == _trust_logical_pred)
|
||||||
if (fop == _trust_logical_pred)
|
alt = NEXTOP(alt,l);
|
||||||
alt = NEXTOP(alt,l);
|
|
||||||
first = alt->u.ld.d;
|
|
||||||
} else {
|
|
||||||
first = PREVOP(alt->u.ld.d,ld);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ipc = NULL;
|
ipc = NULL;
|
||||||
break;
|
break;
|
||||||
@ -4045,6 +4034,8 @@ expand_index(PredEntry *ap) {
|
|||||||
} else {
|
} else {
|
||||||
max = install_clauses(cls, ap, stack, first, last);
|
max = install_clauses(cls, ap, stack, first, last);
|
||||||
}
|
}
|
||||||
|
/* don't count last clause if you don't have to */
|
||||||
|
if (alt && max->Code == last) max--;
|
||||||
if (max < cls && labp != NULL) {
|
if (max < cls && labp != NULL) {
|
||||||
*labp = FAILCODE;
|
*labp = FAILCODE;
|
||||||
return labp;
|
return labp;
|
||||||
@ -4055,7 +4046,7 @@ expand_index(PredEntry *ap) {
|
|||||||
!IsVarTerm(sp[-1].val) &&
|
!IsVarTerm(sp[-1].val) &&
|
||||||
IsAtomOrIntTerm(sp[-1].val)) {
|
IsAtomOrIntTerm(sp[-1].val)) {
|
||||||
/* if an atom or int continue from where we stopped */
|
/* if an atom or int continue from where we stopped */
|
||||||
arg0 = -sp[-1].pos;
|
i = -sp[-1].pos;
|
||||||
sp[-1].pos = 0;
|
sp[-1].pos = 0;
|
||||||
sp--;
|
sp--;
|
||||||
/* we have to put the right masks now */
|
/* we have to put the right masks now */
|
||||||
@ -4069,7 +4060,7 @@ expand_index(PredEntry *ap) {
|
|||||||
CodeStart = cpc = NULL;
|
CodeStart = cpc = NULL;
|
||||||
|
|
||||||
if (!IsVarTerm(sp[-1].val) && IsPairTerm(sp[-1].val) && sp > stack) {
|
if (!IsVarTerm(sp[-1].val) && IsPairTerm(sp[-1].val) && sp > stack) {
|
||||||
lab = do_compound_index(cls, max, s_reg, ap, arg0, 2, argno+1, fail_l, isfirstcl, is_last_arg, clleft, top);
|
lab = do_compound_index(cls, max, s_reg, ap, i, 2, argno+1, fail_l, isfirstcl, is_last_arg, clleft, top);
|
||||||
} else if (!IsVarTerm(sp[-1].val) && IsApplTerm(sp[-1].val) && sp > stack) {
|
} else if (!IsVarTerm(sp[-1].val) && IsApplTerm(sp[-1].val) && sp > stack) {
|
||||||
/* we are continuing within a compound term */
|
/* we are continuing within a compound term */
|
||||||
Functor f = (Functor)RepAppl(sp[-1].val);
|
Functor f = (Functor)RepAppl(sp[-1].val);
|
||||||
@ -4079,7 +4070,7 @@ expand_index(PredEntry *ap) {
|
|||||||
else
|
else
|
||||||
lab = do_blob_index(cls, max, t, ap, argno, fail_l, isfirstcl, clleft, top);
|
lab = do_blob_index(cls, max, t, ap, argno, fail_l, isfirstcl, clleft, top);
|
||||||
} else {
|
} else {
|
||||||
lab = do_compound_index(cls, max, s_reg, ap, arg0, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top);
|
lab = do_compound_index(cls, max, s_reg, ap, i, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (argno == ap->ArityOfPE) {
|
if (argno == ap->ArityOfPE) {
|
||||||
@ -4161,6 +4152,8 @@ ExpandIndex(PredEntry *ap) {
|
|||||||
#endif
|
#endif
|
||||||
if ((labp = expand_index(ap)) == NULL)
|
if ((labp = expand_index(ap)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (*labp == FAILCODE)
|
||||||
|
return FAILCODE;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (Yap_Option['i' - 'a' + 1]) {
|
if (Yap_Option['i' - 'a' + 1]) {
|
||||||
Yap_ShowCode();
|
Yap_ShowCode();
|
||||||
@ -5979,6 +5972,8 @@ lu_clause(yamop *ipc)
|
|||||||
LogUpdClause *c;
|
LogUpdClause *c;
|
||||||
CELL *p = (CELL *)ipc;
|
CELL *p = (CELL *)ipc;
|
||||||
|
|
||||||
|
if (ipc == FAILCODE)
|
||||||
|
return NULL;
|
||||||
while ((c = ClauseCodeToLogUpdClause(p))->Id != FunctorDBRef ||
|
while ((c = ClauseCodeToLogUpdClause(p))->Id != FunctorDBRef ||
|
||||||
!(c->ClFlags & LogUpdMask) ||
|
!(c->ClFlags & LogUpdMask) ||
|
||||||
(c->ClFlags & (IndexMask|DynamicMask|SwitchTableMask|SwitchRootMask))) {
|
(c->ClFlags & (IndexMask|DynamicMask|SwitchTableMask|SwitchRootMask))) {
|
||||||
@ -6047,14 +6042,14 @@ Yap_follow_lu_indexing_code(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr
|
|||||||
|
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case _try_in:
|
case _try_in:
|
||||||
|
update_clause_choice_point(NEXTOP(ipc,l), ap_pc);
|
||||||
ipc = ipc->u.l.l;
|
ipc = ipc->u.l.l;
|
||||||
B->cp_ap = NEXTOP(ipc,ld);
|
|
||||||
break;
|
break;
|
||||||
case _try_clause:
|
case _try_clause:
|
||||||
if (b0 == NULL)
|
if (b0 == NULL)
|
||||||
store_clause_choice_point(t1, tb, tr, NEXTOP(ipc,ld), ap, ap_pc, cp_pc);
|
store_clause_choice_point(t1, tb, tr, NEXTOP(ipc,ld), ap, ap_pc, cp_pc);
|
||||||
else
|
else
|
||||||
B->cp_ap = NEXTOP(ipc,ld);
|
update_clause_choice_point(NEXTOP(ipc,ld), ap_pc);
|
||||||
return lu_clause(ipc->u.ld.d);
|
return lu_clause(ipc->u.ld.d);
|
||||||
case _try_me:
|
case _try_me:
|
||||||
case _try_me1:
|
case _try_me1:
|
||||||
@ -6064,7 +6059,7 @@ Yap_follow_lu_indexing_code(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr
|
|||||||
if (b0 == NULL)
|
if (b0 == NULL)
|
||||||
store_clause_choice_point(t1, tb, tr, ipc->u.ld.d, ap, ap_pc, cp_pc);
|
store_clause_choice_point(t1, tb, tr, ipc->u.ld.d, ap, ap_pc, cp_pc);
|
||||||
else
|
else
|
||||||
B->cp_ap = ipc->u.ld.d;
|
update_clause_choice_point(ipc->u.ld.d, ap_pc);
|
||||||
ipc = NEXTOP(ipc,ld);
|
ipc = NEXTOP(ipc,ld);
|
||||||
break;
|
break;
|
||||||
case _retry:
|
case _retry:
|
||||||
@ -6281,8 +6276,12 @@ Yap_follow_lu_indexing_code(PredEntry *ap, yamop *ipc, Term t1, Term tb, Term tr
|
|||||||
case _expand_index:
|
case _expand_index:
|
||||||
ipc = ExpandIndex(ap);
|
ipc = ExpandIndex(ap);
|
||||||
break;
|
break;
|
||||||
case _undef_p:
|
|
||||||
case _op_fail:
|
case _op_fail:
|
||||||
|
/*
|
||||||
|
ipc = (yamop *)IntegerOfTerm(B->cp_args[1]);
|
||||||
|
break;
|
||||||
|
*/
|
||||||
|
case _undef_p:
|
||||||
return NULL;
|
return NULL;
|
||||||
case _index_pred:
|
case _index_pred:
|
||||||
case _spy_pred:
|
case _spy_pred:
|
||||||
@ -6533,6 +6532,15 @@ find_caller(PredEntry *ap, yamop *code) {
|
|||||||
break;
|
break;
|
||||||
case _expand_index:
|
case _expand_index:
|
||||||
ipc = alt;
|
ipc = alt;
|
||||||
|
alt = NULL;
|
||||||
|
break;
|
||||||
|
case _op_fail:
|
||||||
|
if (alt == NULL) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
ipc = alt;
|
||||||
|
alt = NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (alt == NULL) {
|
if (alt == NULL) {
|
||||||
@ -6562,6 +6570,7 @@ Yap_CleanUpIndex(LogUpdIndex *blk)
|
|||||||
/* I have to kill this block */
|
/* I have to kill this block */
|
||||||
yamop **caller, *new;
|
yamop **caller, *new;
|
||||||
caller = find_caller(ap, blk->ClCode);
|
caller = find_caller(ap, blk->ClCode);
|
||||||
|
if (caller == NULL) return NULL;
|
||||||
*caller = new = replace_lu_block(blk, REFRESH, ap, NULL, FALSE);
|
*caller = new = replace_lu_block(blk, REFRESH, ap, NULL, FALSE);
|
||||||
return new;
|
return new;
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,6 +113,10 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
|||||||
/* extern int gc_calls; */
|
/* extern int gc_calls; */
|
||||||
|
|
||||||
vsc_count++;
|
vsc_count++;
|
||||||
|
if (vsc_count < 5264300LL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (vsc_count == 5264343LL) vsc_xstop = TRUE;
|
||||||
#ifdef COMMENTED
|
#ifdef COMMENTED
|
||||||
if (vsc_count < 123536430LL) {
|
if (vsc_count < 123536430LL) {
|
||||||
if (vsc_count == 123536441LL) vsc_xstop = 1;
|
if (vsc_count == 123536441LL) vsc_xstop = 1;
|
||||||
|
Reference in New Issue
Block a user