From 8a6e0acedcb954a7a8e4f8d3504a7e7eb8f98f0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 12 Feb 2009 21:35:31 +0000 Subject: [PATCH] compiler support for udi including user_index instruction --- C/absmi.c | 12 ++++++++++++ C/amasm.c | 15 +++++++++++++++ C/cdmgr.c | 7 +++++++ C/computils.c | 1 + C/grow.c | 1 + C/index.c | 21 +++++++++++++++++++++ H/YapOpcodes.h | 1 + H/amidefs.h | 5 +++++ H/compile.h | 1 + H/rclause.h | 6 ++++++ H/walkclause.h | 4 ++++ Makefile.in | 1 + 12 files changed, 75 insertions(+) diff --git a/C/absmi.c b/C/absmi.c index 29f44fcb1..0de1ab529 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -8422,6 +8422,18 @@ Yap_absmi(int inp) * Indexing in ARG1 * \************************************************************************/ + BOp(user_switch, lp); + { + yamop *new = Yap_udi_search(PREG->u.lp.p); + if (!new) { + PREG = PREG->u.lp.l; + JMPNext(); + } + PREG = new; + JMPNext(); + } + ENDBOp(); + BOp(switch_on_type, llll); BEGD(d0); d0 = CACHED_A1(); diff --git a/C/amasm.c b/C/amasm.c index eccc236cd..246e55bc0 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -530,6 +530,18 @@ a_p0(op_numbers opcode, yamop *code_p, int pass_no, PredEntry *p0) return code_p; } +inline static yamop * +a_lp(op_numbers opcode, yamop *code_p, int pass_no, struct intermediates *cip) +{ + if (pass_no) { + code_p->opc = emit_op(opcode); + code_p->u.lp.p = (PredEntry *)cip->cpc->rnd1; + code_p->u.lp.l = (yamop *)cip->cpc->rnd2; + } + GONEXT(lp); + return code_p; +} + inline static yamop * a_ue(op_numbers opcode, op_numbers opcodew, yamop *code_p, int pass_no) { @@ -3718,6 +3730,9 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp case jump_nv_op: code_p = a_xigl(_jump_if_nonvar, code_p, pass_no, cip->cpc); break; + case user_switch_op: + code_p = a_lp(_user_switch, code_p, pass_no, cip); + break; case switch_on_type_op: code_p = a_4sw(_switch_on_type, code_p, pass_no, cip); break; diff --git a/C/cdmgr.c b/C/cdmgr.c index 2c6355a3a..16865c5dd 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1181,6 +1181,10 @@ cleanup_dangling_indices(yamop *ipc, yamop *beg, yamop *end, yamop *suspend_code ipc->u.xll.l1 = release_wcls(ipc->u.xll.l1, ecs); ipc = NEXTOP(ipc,xll); break; + /* instructions type p */ + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: ipc->u.llll.l1 = release_wcls(ipc->u.llll.l1, ecs); @@ -2136,6 +2140,9 @@ addclause(Term t, yamop *cp, int mode, Term mod, Term *t4ref) UNLOCK(p->PELock); return TermNil; } + if (pflags & UDIPredFlag) { + Yap_new_udi_clause(p, cp, t); + } if (!is_dynamic(p)) { if (pflags & LogUpdatePredFlag) { LogUpdClause *clp = ClauseCodeToLogUpdClause(cp); diff --git a/C/computils.c b/C/computils.c index f68d0fae4..7b8e98068 100644 --- a/C/computils.c +++ b/C/computils.c @@ -656,6 +656,7 @@ static char *opformat[] = "jump_if_nonvar\t\t%g", "cache_arg\t%r", "cache_sub_arg\t%d", + "user_index", "switch_on_type\t%h\t%h\t%h\t%h", "switch_on_constant\t%i\n%c", "if_constant\t%i\n%c", diff --git a/C/grow.c b/C/grow.c index 9bdf762ef..0a7c3ebe8 100644 --- a/C/grow.c +++ b/C/grow.c @@ -1059,6 +1059,7 @@ fix_compiler_instructions(PInstr *pcpc) case jump_nv_op: case cache_arg_op: case cache_sub_arg_op: + case user_switch_op: case switch_on_type_op: case switch_c_op: case if_c_op: diff --git a/C/index.c b/C/index.c index 5a7fed65b..adfaffb5e 100644 --- a/C/index.c +++ b/C/index.c @@ -1349,6 +1349,8 @@ has_cut(yamop *pc) pc = NEXTOP(pc,c); break; /* instructions type p */ + case _user_switch: + return FALSE; case _deallocate: case _procceed: pc = NEXTOP(pc,p); @@ -3286,6 +3288,10 @@ compile_index(struct intermediates *cint) /* throw away a label */ new_label(cint); init_log_upd_clauses(cls,ap); + } else if (ap->PredFlags & UDIPredFlag) { + UInt lbl = new_label(cint); + Yap_emit(user_switch_op, Unsigned(ap), Unsigned(&(ap->cs.p_code.ExpandCode)), cint); + return lbl; } else { /* prepare basic data structures */ init_clauses(cls,ap); @@ -4017,6 +4023,9 @@ expand_index(struct intermediates *cint) { s_reg = NULL; ipc = NEXTOP(ipc,e); break; + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: t = Deref(ARG1); @@ -5535,6 +5544,9 @@ add_to_index(struct intermediates *cint, int first, path_stack_entry *sp, Clause ipc = NEXTOP(ipc,l); } break; + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: sp = push_path(sp, &(ipc->u.llll.l4), cls, cint); @@ -6078,6 +6090,9 @@ remove_from_index(PredEntry *ap, path_stack_entry *sp, ClauseDef *cls, yamop *bg sp = cross_block(sp, &ipc->u.xll.l1, ap); ipc = ipc->u.xll.l1; break; + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: sp = push_path(sp, &(ipc->u.llll.l4), cls, cint); @@ -6812,6 +6827,9 @@ Yap_FollowIndexingCode(PredEntry *ap, yamop *ipc, Term Terms[3], yamop *ap_pc, y } } break; + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: t = Deref(ARG1); @@ -7212,6 +7230,9 @@ Yap_NthClause(PredEntry *ap, Int ncls) case _jump_if_nonvar: ipc = NEXTOP(ipc,xll); break; + case _user_switch: + ipc = NEXTOP(ipc,p); + break; /* instructions type e */ case _switch_on_type: jlbl = &(ipc->u.llll.l4); diff --git a/H/YapOpcodes.h b/H/YapOpcodes.h index 3a93a05b0..e974144fa 100644 --- a/H/YapOpcodes.h +++ b/H/YapOpcodes.h @@ -216,6 +216,7 @@ OPCODE(try_logical ,OtaLl), OPCODE(retry_logical ,OtaLl), OPCODE(trust_logical ,OtILl), + OPCODE(user_switch ,lp), OPCODE(switch_on_type ,llll), OPCODE(switch_list_nl ,ollll), OPCODE(switch_on_arg_type ,xllll), diff --git a/H/amidefs.h b/H/amidefs.h index 345656e3c..5d8640ae7 100644 --- a/H/amidefs.h +++ b/H/amidefs.h @@ -438,6 +438,11 @@ typedef struct yami { struct yami *l4; CELL next; } ollll; + struct { + struct yami *l; + struct pred_entry *p; + CELL next; + } lp; struct { OPCODE opcw; CELL next; diff --git a/H/compile.h b/H/compile.h index 7b6283856..bf6f8a1c4 100644 --- a/H/compile.h +++ b/H/compile.h @@ -97,6 +97,7 @@ typedef enum compiler_op { jump_nv_op, cache_arg_op, cache_sub_arg_op, + user_switch_op, switch_on_type_op, switch_c_op, if_c_op, diff --git a/H/rclause.h b/H/rclause.h index 49876c3b8..1b34cbd33 100644 --- a/H/rclause.h +++ b/H/rclause.h @@ -257,6 +257,12 @@ restore_opcodes(yamop *pc) pc->u.llll.l4 = PtoOpAdjust(pc->u.llll.l4); pc = NEXTOP(pc,llll); break; + /* instructions type lp */ + case _user_switch: + pc->u.lp.l = PtoOpAdjust(pc->u.lp.l); + pc->u.lp.p = PtoPredAdjust(pc->u.lp.p); + pc = NEXTOP(pc,lp); + break; /* instructions type o */ case _unify_l_list: case _unify_l_list_write: diff --git a/H/walkclause.h b/H/walkclause.h index 57652f4eb..1b38a5457 100644 --- a/H/walkclause.h +++ b/H/walkclause.h @@ -197,6 +197,10 @@ case _switch_on_type: pc = NEXTOP(pc,llll); break; + /* instructions type lp */ + case _user_switch: + pc = NEXTOP(pc,lp); + break; /* instructions type o */ case _unify_l_list: case _unify_l_list_write: diff --git a/Makefile.in b/Makefile.in index c0332786e..ef9ebedf9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -223,6 +223,7 @@ PL_SOURCES= \ $(srcdir)/pl/statistics.yap \ $(srcdir)/pl/strict_iso.yap \ $(srcdir)/pl/tabling.yap $(srcdir)/pl/threads.yap \ + $(srcdir)/pl/udi.yap \ $(srcdir)/pl/utils.yap \ $(srcdir)/pl/yapor.yap $(srcdir)/pl/yio.yap