From f7046286a0f564ffe9edb0bd7d686e458eeb4387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 12 Feb 2009 21:45:41 +0000 Subject: [PATCH] cleanups and a bug fix (it is lp now, not just p as before). --- C/cdmgr.c | 2 +- C/index.c | 10 +++++----- C/udi.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/C/cdmgr.c b/C/cdmgr.c index 16865c5dd..bdeec39d8 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -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: diff --git a/C/index.c b/C/index.c index adfaffb5e..fd9d7f26f 100644 --- a/C/index.c +++ b/C/index.c @@ -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: diff --git a/C/udi.c b/C/udi.c index 438205ffa..9576ee747 100644 --- a/C/udi.c +++ b/C/udi.c @@ -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) {