cleanups and a bug fix (it is lp now, not just p as before).

This commit is contained in:
Vítor Santos Costa 2009-02-12 21:45:41 +00:00
parent 78bd156a20
commit f7046286a0
3 changed files with 29 additions and 6 deletions

View File

@ -1183,7 +1183,7 @@ cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code
break;
/* instructions type p */
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = NEXTOP(ipc,lp);
break;
/* instructions type e */
case _switch_on_type:

View File

@ -4024,7 +4024,7 @@ expand_index(struct intermediates *cint) {
ipc = NEXTOP(ipc,e);
break;
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = ipc->u.lp.l;
break;
/* instructions type e */
case _switch_on_type:
@ -5545,7 +5545,7 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause
}
break;
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = ipc->u.lp.l;
break;
/* instructions type e */
case _switch_on_type:
@ -6091,7 +6091,7 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg
ipc = ipc->u.xll.l1;
break;
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = ipc->u.lp.l;
break;
/* instructions type e */
case _switch_on_type:
@ -6828,7 +6828,7 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y
}
break;
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = ipc->u.lp.l;
break;
/* instructions type e */
case _switch_on_type:
@ -7231,7 +7231,7 @@ Yap_NthClause(PredEntry *ap, Int ncls)
ipc = NEXTOP(ipc,xll);
break;
case _user_switch:
ipc = NEXTOP(ipc,p);
ipc = ipc->u.lp.l;
break;
/* instructions type e */
case _switch_on_type:

23
C/udi.c
View File

@ -6,6 +6,13 @@
/* we can have this stactic because it is written once */
static struct udi_control_block RtreeCmd;
/******
All the info we need to enter user indexed code:
predicate
the user control block
functions used, in case we have different schema (maybe should part of previous)
right now, this is just a linked list....
******/
typedef struct udi_info
{
PredEntry *p;
@ -14,6 +21,10 @@ typedef struct udi_info
struct udi_info *next;
} *UdiInfo;
/******
we now have one extra user indexed predicate. We assume these
are few, so we can do with a linked list.
******/
static int
add_udi_block(void *info, PredEntry *p, UdiControlBlock cmd)
{
@ -28,6 +39,11 @@ add_udi_block(void *info, PredEntry *p, UdiControlBlock cmd)
return TRUE;
}
/******
new user indexed predicate;
the type right now is just rtrees, but in the future we'll have more.
the second argument is the term.
******/
static Int
p_new_udi(void)
{
@ -37,6 +53,7 @@ p_new_udi(void)
Atom udi_t;
void *info;
/* get the predicate from the spec, copied from cdmgr.c */
if (IsVarTerm(spec)) {
Yap_Error(INSTANTIATION_ERROR,spec,"new user index/1");
return FALSE;
@ -62,6 +79,7 @@ p_new_udi(void)
}
p = RepPredProp(Yap_GetPredPropByFunc(fun, tmod));
}
/* boring, boring, boring! */
if ((p->PredFlags & (DynamicPredFlag|LogUpdatePredFlag|UserCPredFlag|CArgsPredFlag|NumberDBPredFlag|AtomDBPredFlag|TestPredFlag|AsmPredFlag|CPredFlag|BinaryPredFlag)) ||
(p->ModuleOfPred == PROLOG_MODULE)) {
Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, spec, "udi/2");
@ -71,6 +89,7 @@ p_new_udi(void)
Yap_Error(PERMISSION_ERROR_ACCESS_PRIVATE_PROCEDURE, spec, "udi/2");
return FALSE;
}
/* just make sure we're looking at the right user type! */
if (IsVarTerm(udi_type)) {
Yap_Error(INSTANTIATION_ERROR,spec,"new user index/1");
return FALSE;
@ -85,9 +104,11 @@ p_new_udi(void)
Yap_Error(TYPE_ERROR_ATOM,spec,"new user index/1");
return FALSE;
}
/* this is the real work */
info = cmd->init(spec, (void *)p, p->ArityOfPE);
if (!info)
return FALSE;
/* add to table */
if (!add_udi_block(info, p, cmd)) {
Yap_Error(OUT_OF_HEAP_ERROR, spec, "new user index/1");
return FALSE;
@ -96,6 +117,7 @@ p_new_udi(void)
return TRUE;
}
/* just pass info to user, called from cdmgr.c */
int
Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
{
@ -108,6 +130,7 @@ Yap_new_udi_clause(PredEntry *p, yamop *cl, Term t)
return TRUE;
}
/* index, called from absmi.c */
yamop *
Yap_udi_search(PredEntry *p)
{