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; break;
/* instructions type p */ /* instructions type p */
case _user_switch: case _user_switch:
ipc = NEXTOP(ipc,p); ipc = NEXTOP(ipc,lp);
break; break;
/* instructions type e */ /* instructions type e */
case _switch_on_type: case _switch_on_type:

View File

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

23
C/udi.c
View File

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