466static char SccsId[] =
"%W% %G%";
637#include "YapCompile.h"
645#define NULL (void *)0
652#if defined(YAPOR) || defined(THREADS)
653#define SET_JLBL(X) jlbl = &(ipc->y_u.X)
659 UInt,
int,
int, CELL *);
662 int,
int,
int, CELL *,
int);
670static UInt cleanup_sw_on_clauses(CELL larg, UInt sz, OPCODE ecls) {
675 if (xp->opc == ecls) {
676 if (xp->y_u.sssllp.s3 == 1) {
677 UInt nsz = sz + (UInt)(NEXTOP((
yamop *)NULL, sssllp)) +
678 xp->y_u.sssllp.s1 *
sizeof(
yamop *);
679 LOCK(ExpandClausesListLock);
680 if (ExpandClausesFirst == xp)
681 ExpandClausesFirst = xp->y_u.sssllp.snext;
682 if (ExpandClausesLast == xp) {
683 ExpandClausesLast = xp->y_u.sssllp.sprev;
685 if (xp->y_u.sssllp.sprev) {
686 xp->y_u.sssllp.sprev->y_u.sssllp.snext = xp->y_u.sssllp.snext;
688 if (xp->y_u.sssllp.snext) {
689 xp->y_u.sssllp.snext->y_u.sssllp.sprev = xp->y_u.sssllp.sprev;
691 UNLOCK(ExpandClausesListLock);
694 Yap_expand_clauses_sz -= (UInt)(NEXTOP((
yamop *)NULL, sssllp)) +
695 xp->y_u.sssllp.s1 *
sizeof(
yamop *);
697 if (xp->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) {
698 Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((
yamop *)NULL, sssllp) +
699 xp->y_u.sssllp.s1 *
sizeof(
yamop *);
701 Yap_IndexSpace_EXT -= (UInt)(NEXTOP((
yamop *)NULL, sssllp)) +
702 xp->y_u.sssllp.s1 *
sizeof(
yamop *);
703 Yap_FreeCodeSpace((
char *)xp);
715static UInt recover_from_failed_susp_on_cls(
struct intermediates *cint,
719 struct PSEUDO *cpc = cint->CodeStart;
720 OPCODE ecls = Yap_opcode(_expand_clauses);
721 pred_flags_t log_upd_pred = cint->CurrentPred->PredFlags & LogUpdatePredFlag;
728 yamop *first = code_p->y_u.Illss.l1;
729 yamop *last = code_p->y_u.Illss.l2;
731 yamop *next = first->y_u.OtaLl.n;
734 Yap_FreeCodeSpace((
char *)first);
744 sz = cleanup_sw_on_clauses(cpc->rnd1, sz, ecls);
746 case switch_on_type_op: {
748 sz = cleanup_sw_on_clauses(type_sw->PairEntry, sz, ecls);
749 sz = cleanup_sw_on_clauses(type_sw->ConstEntry, sz, ecls);
750 sz = cleanup_sw_on_clauses(type_sw->FuncEntry, sz, ecls);
751 sz = cleanup_sw_on_clauses(type_sw->VarEntry, sz, ecls);
756 int cases = cpc->rnd1, i;
758 for (i = 0; i < cases; i++) {
759 sz = cleanup_sw_on_clauses(target[i].u_a.Label, sz, ecls);
762 LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2);
764 Yap_LUIndexSpace_SW -=
766 Yap_FreeCodeSpace((
char *)lcl);
768 StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2);
771 Yap_FreeCodeSpace((
char *)scl);
777 int cases = cpc->rnd1, i;
779 for (i = 0; i < cases; i++) {
780 sz = cleanup_sw_on_clauses(target[i].u_f.Label, sz, ecls);
783 LogUpdIndex *lcl = ClauseCodeToLogUpdIndex(cpc->rnd2);
785 Yap_LUIndexSpace_SW -=
787 Yap_FreeCodeSpace((
char *)lcl);
789 StaticIndex *scl = ClauseCodeToStaticIndex(cpc->rnd2);
792 Yap_FreeCodeSpace((
char *)scl);
800 Yap_ReleaseCMem(cint);
801 if (cint->code_addr) {
802 Yap_FreeCodeSpace((
char *)cint->code_addr);
803 cint->code_addr = NULL;
808static inline int smaller(Term t1, Term t2) {
809 CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2);
816static inline int smaller_or_eq(Term t1, Term t2) {
817 CELL tg1 = LowTagOf(t1), tg2 = LowTagOf(t2);
825 memcpy((
void *)d, (
void *)s,
sizeof(
ClauseDef));
828static void insort(
ClauseDef base[], CELL *p, CELL *q,
int my_p) {
833 for (j = p; j < q; j += 2) {
842 while (i > p + 1 && smaller(key, base[i[-2]].Tag)) {
849 for (j = p + 2; j < q; j += 2) {
858 while (i > p && smaller(key, base[i[-2]].Tag)) {
868static void msort(
ClauseDef *base, CELL *pt, Int size,
int my_p) {
871 Int half_size = size / 2;
872 CELL *pt_left, *pt_right, *end_pt, *end_pt_left;
876 insort(base, pt, pt + 2 * size, my_p);
879 pt_right = pt + half_size * 2;
882 msort(base, pt, half_size, left_p);
883 msort(base, pt_right, size - half_size, right_p);
887 end_pt = pt + 2 * size;
889 end_pt_left = pt + half_size * 2;
891 pt_left = pt + left_p;
897 while (pt_left < end_pt_left && pt_right < end_pt) {
899 if (smaller_or_eq(base[pt_left[0]].Tag, base[pt_right[0]].Tag)) {
913 while (pt_left < end_pt_left) {
920 if (my_p != right_p) {
921 while (pt_right < end_pt) {
928 if (size > 1 && smaller(base[pt[2]].Tag, base[pt[0]].Tag)) {
930 pt[2 + my_p] = pt[0];
940static void copy_back(
ClauseDef *dest, CELL *pt,
int max) {
944 for (i = 0; i < max; i++) {
952 clcpy(&cl, dest + i);
960 clcpy(dest + j, &cl);
963 clcpy(dest + j, dest + k);
976 int max = (grp->LastClause - grp->FirstClause) + 1, i;
980 if (!(base = (CELL *)Yap_AllocCodeSpace(2 * max *
sizeof(CELL)))) {
983 LOCAL_Error_Size = 2 * max *
sizeof(CELL);
984 siglongjmp(cint->CompilerBotch, 2);
988 while (top + 2 * max > (CELL *)LOCAL_TrailTop) {
989 if (!Yap_growtrail(2 * max * CellSize, TRUE)) {
990 LOCAL_Error_Size = 2 * max * CellSize;
992 siglongjmp(cint->CompilerBotch, 4);
999 for (i = 0; i < max; i++) {
1004 msort(grp->FirstClause, base, max, M_EVEN);
1005 copy_back(grp->FirstClause, base, max);
1006#if USE_SYSTEM_MALLOC
1007 Yap_FreeCodeSpace((ADDR)base);
1012static int init_regcopy(wamreg regs[MAX_REG_COPIES], wamreg copy) {
1018static int is_regcopy(wamreg regs[MAX_REG_COPIES],
int regs_count,
1021 while (i < regs_count) {
1022 if (regs[i] == copy) {
1032static int delete_regcopy(wamreg regs[MAX_REG_COPIES],
int regs_count,
1035 while (i < regs_count) {
1036 if (regs[i] == copy) {
1038 regs[i] = regs[regs_count - 1];
1039 return regs_count - 1;
1048static int add_regcopy(wamreg regs[MAX_REG_COPIES],
int regs_count, Int
source,
1051 while (i < regs_count) {
1054 if (regs_count == MAX_REG_COPIES) {
1057 regs[regs_count] = copy;
1058 return regs_count + 1;
1063 return delete_regcopy(regs, regs_count, copy);
1067inline static int link_regcopies(wamreg regs[MAX_REG_COPIES],
int regs_count,
1070 for (i = 0; i < regs_count; i++) {
1071 if (regs[i] == c1) {
1072 return add_regcopy(regs, regs_count, c1, c2);
1074 if (regs[i] == c2) {
1075 return add_regcopy(regs, regs_count, c2, c1);
1079 regs_count = delete_regcopy(regs, regs_count, c1);
1080 return delete_regcopy(regs, regs_count, c2);
1083static void add_info(
ClauseDef *clause, UInt regno) {
1084 wamreg myregs[MAX_REG_COPIES];
1088 nofregs = init_regcopy(myregs, Yap_regnotoreg(regno));
1089 cl = clause->CurrentCode;
1090#include "findclause.h"
1093static void add_head_info(
ClauseDef *clause, UInt regno) {
1094 wamreg iarg = Yap_regnotoreg(regno);
1096 yamop *cl = clause->CurrentCode;
1097#include "headclause.h"
1100static void move_next(
ClauseDef *clause, UInt regno) {
1101 yamop *cl = clause->CurrentCode;
1102 wamreg wreg = Yap_regnotoreg(regno);
1103 op_numbers op = Yap_op_from_opcode(cl->opc);
1112 clause->CurrentCode = NEXTOP(cl, e);
1117 if (wreg == cl->y_u.xl.x) {
1118 clause->CurrentCode = NEXTOP(cl, xl);
1122 if (wreg == cl->y_u.x.x) {
1123 clause->CurrentCode = NEXTOP(cl, x);
1134 if (wreg == cl->y_u.xc.x) {
1135 clause->CurrentCode = NEXTOP(cl, xc);
1155 if (wreg == cl->y_u.xfa.x) {
1156 clause->CurrentCode = NEXTOP(cl, xfa);
1159 clause->CurrentCode = clause->Code;
1166 if (ap->ModuleOfPred == IDB_MODULE) {
1169 cl = clause->ucd.WorkPC;
1172 op_numbers op = Yap_op_from_opcode(cl->opc);
1176 clause->Tag = (CELL)NULL;
1180 cl = NEXTOP(cl, xx);
1186 clause->Tag = (CELL)NULL;
1190 clause->Tag = (CELL)NULL;
1194 cl = NEXTOP(cl, yx);
1196 case _unify_l_x_var:
1197 case _unify_l_x_val:
1198 case _unify_l_x_loc:
1203 clause->Tag = (CELL)NULL;
1207 case _unify_l_x_var_write:
1208 case _unify_l_x_val_write:
1209 case _unify_l_x_loc_write:
1210 case _unify_x_var_write:
1211 case _unify_x_val_write:
1212 case _unify_x_loc_write:
1213 cl = NEXTOP(cl, ox);
1215 case _save_pair_x_write:
1217 case _save_appl_x_write:
1219 cl = NEXTOP(cl, ox);
1221 case _unify_l_x_var2:
1223 if (argno == 1 || argno == 2) {
1224 clause->Tag = (CELL)NULL;
1228 case _unify_l_x_var2_write:
1229 case _unify_x_var2_write:
1230 cl = NEXTOP(cl, oxx);
1235 case _unify_l_y_var:
1236 case _unify_l_y_val:
1237 case _unify_l_y_loc:
1242 clause->Tag = (CELL)NULL;
1246 case _unify_y_var_write:
1247 case _unify_y_val_write:
1248 case _unify_y_loc_write:
1249 case _unify_l_y_var_write:
1250 case _unify_l_y_val_write:
1251 case _unify_l_y_loc_write:
1252 cl = NEXTOP(cl, oy);
1254 case _save_pair_y_write:
1256 case _save_appl_y_write:
1258 cl = NEXTOP(cl, oy);
1263 clause->Tag = (CELL)NULL;
1267 case _unify_l_void_write:
1268 case _unify_void_write:
1274 clause->Tag = AbsPair(NULL);
1275 clause->ucd.WorkPC = NEXTOP(cl, o);
1279 case _unify_list_write:
1280 case _unify_l_list_write:
1283 case _unify_n_voids:
1284 case _unify_l_n_voids:
1285 if (argno <= cl->y_u.os.s) {
1286 clause->Tag = (CELL)NULL;
1289 argno -= cl->y_u.os.s;
1290 case _unify_n_voids_write:
1291 case _unify_l_n_voids_write:
1292 cl = NEXTOP(cl, os);
1297 clause->Tag = cl->y_u.oc.c;
1301 case _unify_atom_write:
1302 case _unify_l_atom_write:
1303 cl = NEXTOP(cl, oc);
1305 case _unify_float_write:
1306 case _unify_l_float_write:
1307 cl = NEXTOP(cl, od);
1310 case _unify_l_float:
1312 clause->Tag = AbsAppl((CELL *)FunctorDouble);
1313 clause->ucd.t_ptr = AbsAppl(cl->y_u.od.d);
1316 cl = NEXTOP(cl, od);
1319 case _unify_longint:
1320 case _unify_l_longint:
1322 clause->Tag = AbsAppl((CELL *)FunctorLongInt);
1323 clause->ucd.t_ptr = AbsAppl(cl->y_u.oi.i);
1327 cl = NEXTOP(cl, oi);
1330 case _unify_l_bigint:
1332 clause->Tag = AbsAppl((CELL *)FunctorBigInt);
1333 clause->ucd.t_ptr = cl->y_u.oc.c;
1336 cl = NEXTOP(cl, oc);
1340 case _unify_l_string:
1342 clause->Tag = AbsAppl((CELL *)FunctorString);
1343 clause->ucd.t_ptr = cl->y_u.ou.ut;
1346 cl = NEXTOP(cl, ou);
1349 case _unify_n_atoms:
1350 if (argno <= cl->y_u.osc.s) {
1351 clause->Tag = cl->y_u.osc.c;
1354 argno -= cl->y_u.osc.s;
1355 case _unify_n_atoms_write:
1356 cl = NEXTOP(cl, osc);
1359 case _unify_l_struc:
1361 clause->Tag = AbsAppl((CELL *)cl->y_u.ofa.f);
1362 clause->ucd.WorkPC = NEXTOP(cl, ofa);
1366 argno += cl->y_u.ofa.a - 1;
1367 case _unify_l_struc_write:
1368 case _unify_struct_write:
1369 cl = NEXTOP(cl, ofa);
1379 cl = NEXTOP(cl, os);
1388 cl = NEXTOP(cl, xc);
1391 case _unify_l_dbterm:
1392 cl = NEXTOP(cl, oc);
1394 case _unify_idb_term:
1395 case _copy_idb_term: {
1396 Term t = clause->ucd.c_sreg[argno];
1399 clause->Tag = (CELL)NULL;
1400 }
else if (IsApplTerm(t)) {
1401 CELL *pt = RepAppl(t);
1403 clause->Tag = AbsAppl((CELL *)pt[0]);
1404 if (IsExtensionFunctor(FunctorOfTerm(t))) {
1405 clause->ucd.t_ptr = t;
1407 clause->ucd.c_sreg = pt;
1409 }
else if (IsPairTerm(t)) {
1410 CELL *pt = RepPair(t);
1412 clause->Tag = AbsPair(NULL);
1413 clause->ucd.c_sreg = pt - 1;
1429 if (ap->ModuleOfPred == IDB_MODULE) {
1432 cl = clause->CurrentCode;
1436 clause->CurrentCode = clause->Code;
1441 op_numbers op = Yap_op_from_opcode(cl->opc);
1445 clause->CurrentCode = clause->Code;
1450 clause->CurrentCode = clause->Code;
1455 case _unify_void_write:
1471 case _unify_l_struc:
1472 if (cl == clause->ucd.WorkPC) {
1473 clause->CurrentCode = cl;
1475 clause->CurrentCode = clause->Code;
1478 case _unify_list_write:
1479 case _unify_l_list_write:
1482 case _unify_n_voids:
1483 case _unify_l_n_voids:
1484 if (argno <= cl->y_u.os.s) {
1485 clause->CurrentCode = clause->Code;
1488 argno -= cl->y_u.os.s;
1490 case _unify_n_voids_write:
1491 case _unify_l_n_voids_write:
1492 cl = NEXTOP(cl, os);
1494 case _unify_atom_write:
1495 case _unify_l_atom_write:
1496 cl = NEXTOP(cl, oc);
1498 case _unify_float_write:
1499 case _unify_l_float_write:
1500 cl = NEXTOP(cl, od);
1502 case _unify_l_struc_write:
1503 case _unify_struct_write:
1504 cl = NEXTOP(cl, ofa);
1516 clause->CurrentCode = clause->Code;
1527 while (min <= max) {
1528 grp->FirstClause = min;
1529 grp->AtomClauses = 0;
1530 grp->PairClauses = 0;
1531 grp->StructClauses = 0;
1532 grp->TestClauses = 0;
1533 if (min->Tag == (_var + 1) *
sizeof(CELL)) {
1538 if (IsVarTerm(min->Tag)) {
1541 grp->VarClauses = 1;
1543 if (clp > max || !IsVarTerm(clp->Tag)) {
1544 grp->LastClause = (min = clp) - 1;
1547 if (clp->Tag != (_var + 1) *
sizeof(CELL))
1552 grp->VarClauses = 0;
1555 if (IsAtomTerm(min->Tag) || IsIntTerm(min->Tag)) {
1557 }
else if (IsPairTerm(min->Tag)) {
1559 }
else if (IsApplTerm(min->Tag)) {
1560 grp->StructClauses++;
1565 }
while (min <= max && (!IsVarTerm(min->Tag)));
1566 if (min <= max && min->Tag == (_var + 1) *
sizeof(CELL)) {
1571 grp->LastClause = min - 1;
1575 while (grp + 16 > (
GroupDef *)LOCAL_TrailTop) {
1576 UInt sz = (groups + 16) *
sizeof(
GroupDef);
1577#if USE_SYSTEM_MALLOC
1578 LOCAL_Error_Size = sz;
1580 save_machine_regs();
1581 siglongjmp(cint->CompilerBotch, 4);
1583 if (!Yap_growtrail(sz, TRUE)) {
1584 LOCAL_Error_Size = sz;
1585 save_machine_regs();
1586 siglongjmp(cint->CompilerBotch, 4);
1596 UInt lbl = cint->i_labelno;
1597 cint->i_labelno += 2;
1602 if (ap->PredFlags & LogUpdatePredFlag) {
1604 return ((lcl->ClFlags & HasCutMask) != 0);
1605 }
else if (ap->PredFlags & MegaClausePredFlag) {
1611 scl = ClauseCodeToStaticClause(pc);
1612 return ((scl->ClFlags & HasCutMask) != 0);
1619 yamop *clcode = cl->Code;
1621 if (ap->PredFlags & TabledPredFlag)
1622 clcode = NEXTOP(clcode, Otapl);
1623 if (!(ap->PredFlags & LogUpdatePredFlag)) {
1625 if (ap->PredFlags & ProfiledPredFlag) {
1626 Yap_emit(retry_profiled_op, Unsigned(ap), Zero, cint);
1628 if (ap->PredFlags & CountPredFlag) {
1629 Yap_emit(count_retry_op, Unsigned(ap), Zero, cint);
1633 Yap_emit(trust_op, (CELL)clcode, has_cut(cl->Code, ap), cint);
1635 Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap),
1637 Yap_emit(jumpi_op, nxtlbl, Zero, cint);
1643 yamop *clcode = cl->Code;
1645 if (ap->PredFlags & TabledPredFlag)
1646 clcode = NEXTOP(clcode, Otapl);
1647 if (!(ap->PredFlags & LogUpdatePredFlag)) {
1649 if (ap->PredFlags & ProfiledPredFlag) {
1650 Yap_emit(retry_profiled_op, Unsigned(ap), Zero, cint);
1652 if (ap->PredFlags & CountPredFlag) {
1653 Yap_emit(count_retry_op, Unsigned(ap), Zero, cint);
1656 Yap_emit(retry_op, (CELL)clcode, (clauses << 1) | has_cut(cl->Code, ap),
1660static compiler_vm_op emit_optry(
int var_group,
int first,
int clauses,
1663 if (var_group || clauses == 0) {
1666 }
else if (clleft + clauses) {
1671 }
else if (clleft == 0) {
1673 if (ap->PredFlags & TabledPredFlag && !first) {
1689 int first,
int clauses,
int clleft, UInt nxtlbl) {
1692 compiler_vm_op comp_op;
1694 if (ap->PredFlags & LogUpdatePredFlag) {
1696 }
else if (ap->PredFlags & TabledPredFlag) {
1697 clcode = NEXTOP(cl->Code, Otapl);
1699 clcode = cl->CurrentCode;
1702 comp_op = emit_optry(var_group, first, clauses, clleft, cint->CurrentPred);
1703 Yap_emit(comp_op, (CELL)clcode,
1704 ((clauses + clleft) << 1) | has_cut(cl->Code, ap), cint);
1707static TypeSwitch *emit_type_switch(compiler_vm_op op,
1712static yamop *emit_switch_space(UInt n, UInt item_size,
1717 if (ap->PredFlags & LogUpdatePredFlag) {
1721 LOCAL_Error_Size = sz;
1723 save_machine_regs();
1724 siglongjmp(cint->CompilerBotch, 2);
1726 Yap_LUIndexSpace_SW += sz;
1727 cl->ClFlags = SwitchTableMask | LogUpdMask | func_mask;
1729 cl->ClPred = cint->CurrentPred;
1731 Yap_inform_profiler_of_clause(cl, (CODEADDR)cl + sz, ap,
1732 GPROF_NEW_LU_SWITCH);
1738 LOCAL_Error_Size = sz;
1740 save_machine_regs();
1741 siglongjmp(cint->CompilerBotch, 2);
1743 Yap_IndexSpace_SW += sz;
1744 cl->ClFlags = SwitchTableMask;
1746 cl->ClPred = cint->CurrentPred;
1747 Yap_inform_profiler_of_clause(cl, (CODEADDR)cl + sz, ap,
1748 GPROF_NEW_STATIC_SWITCH);
1759 if (n > MIN_HASH_ENTRIES) {
1760 COUNT cases = MIN_HASH_ENTRIES, i;
1768 for (i = 0; i < n; i++) {
1769 target[i].Tag = Zero;
1770 target[i].u_a.labp = fail_l;
1772 Yap_emit(op, Unsigned(n), (CELL)target, cint);
1780 for (i = 0; i < n; i++) {
1781 target[i].u_a.labp = fail_l;
1783 target[n].Tag = Zero;
1784 target[n].u_a.labp = fail_l;
1785 Yap_emit(op, Unsigned(n), (CELL)target, cint);
1795 hash = (t >> HASH_SHIFT) & (entries - 1);
1796 centry = cebase + hash;
1797 d = (entries - 1) & (t | 1);
1798 while (centry->Tag != t) {
1799 if (centry->Tag == 0L)
1801 hash = (hash + d) & (entries - 1);
1802 centry = cebase + hash;
1808 if (n > MIN_HASH_ENTRIES) {
1809 int cases = MIN_HASH_ENTRIES;
1814 return lookup_c_hash(wt, (
yamop *)cebase, cases);
1825 if (n > MIN_HASH_ENTRIES) {
1826 int cases = MIN_HASH_ENTRIES, i;
1834 for (i = 0; i < n; i++) {
1835 target[i].Tag = NULL;
1836 target[i].u_f.labp = fail_l;
1838 Yap_emit(op, Unsigned(n), (CELL)target, cint);
1844 cint, FuncSwitchMask);
1845 for (i = 0; i < n; i++) {
1846 target[i].u_f.labp = fail_l;
1848 target[n].Tag = NULL;
1849 target[n].u_f.labp = fail_l;
1850 Yap_emit(op, Unsigned(n), (CELL)target, cint);
1861 hash = (wt >> HASH_SHIFT) & (entries - 1);
1862 fentry = febase + hash;
1863 d = (entries - 1) & (wt | 1);
1864 while (fentry->Tag != f) {
1865 if (fentry->Tag == NULL)
1867 hash = (hash + d) & (entries - 1);
1868 fentry = febase + hash;
1875 if (n > MIN_HASH_ENTRIES) {
1876 int cases = MIN_HASH_ENTRIES;
1881 return lookup_f_hash(ft, (
yamop *)febase, cases);
1890 UInt nxtlbl, UInt argno0) {
1892 UInt labl_dyn0 = 0, labl_dynf = 0;
1894 labl = new_label(cint);
1895 Yap_emit(label_op, labl, Zero, cint);
1900 if (first && cint->CurrentPred->PredFlags & LogUpdatePredFlag) {
1902 labl_dyn0 = new_label(cint);
1904 labl_dynf = labl_dyn0;
1906 labl_dynf = new_label(cint);
1908 ncls = (cf - c0) + 1;
1911 Yap_emit_4ops(enter_lu_op, labl_dyn0, labl_dynf, ncls, Zero, cint);
1912 Yap_emit(label_op, labl_dyn0, Zero, cint);
1915 emit_try(c0, cint, var_group, first, 0, clleft, nxtlbl);
1919 emit_try(c0, cint, var_group, first, cf - c0, clleft, nxtlbl);
1923 emit_retry(c0, cint, clleft + (cf - c0));
1927 emit_trust(c0, cint, nxtlbl, clleft);
1928 if (!clleft && cint->CurrentPred->PredFlags & LogUpdatePredFlag) {
1929 Yap_emit(label_op, labl_dynf, Zero, cint);
1937 int var_group,
int first,
int clleft, UInt nxtlbl,
1939 return do_var_clauses(grp->FirstClause, grp->LastClause, var_group, cint,
1940 first, clleft, nxtlbl, argno0);
1944static UInt count_consts(
GroupDef *grp) {
1945 Term current = MkAtomTerm(AtomFoundVar);
1949 while (IsAtomTerm(cl->Tag) || IsIntTerm(cl->Tag)) {
1950 if (current != cl->Tag) {
1954 if (cl == grp->LastClause) {
1962static UInt count_blobs(
GroupDef *grp) {
1965 Term current = grp->FirstClause->Tag;
1967 while (cl <= grp->LastClause) {
1968 if (current != cl->Tag) {
1978static UInt count_funcs(
GroupDef *grp) {
1979 Term current = MkAtomTerm(AtomFoundVar);
1983 while (IsApplTerm(cl->Tag)) {
1984 if (current != cl->Tag) {
1988 if (cl == grp->LastClause) {
1997 int first,
int clleft, UInt nxtlbl) {
1998 if (cint->CurrentPred->PredFlags & TabledPredFlag) {
2001 if (clleft || !first) {
2006 return (UInt)NEXTOP(min->Code, Otapl);
2008 return (UInt)min->Code;
2011 if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) {
2012 return (UInt)(min->Code);
2014 return (UInt)(min->CurrentCode);
2020 UInt tcls = ap->cs.p_code.NOfClauses;
2021 UInt cls = (max - min) + 1;
2023 if (cint->expand_block &&
2024 cint->expand_block != (
yamop *)(&(ap->cs.p_code.ExpandCode)) &&
2025 cint->expand_block->y_u.sssllp.s2 < 2 * (max - min)) {
2026 cint->expand_block->y_u.sssllp.s3++;
2027 return (UInt)(cint->expand_block);
2029 if (cls < tcls / 8) {
2035 if (ap->PredFlags & LogUpdatePredFlag) {
2041 sz = (UInt)NEXTOP((
yamop *)NULL, sssllp) + tels *
sizeof(
yamop *);
2042 if ((ncode = (
yamop *)Yap_AllocCodeSpace(sz)) == NULL) {
2043 save_machine_regs();
2044 siglongjmp(cint->CompilerBotch, 2);
2047 Yap_ExpandClauses++;
2048 Yap_expand_clauses_sz += sz;
2050 if (ap->PredFlags & LogUpdatePredFlag) {
2051 Yap_LUIndexSpace_EXT += sz;
2053 Yap_IndexSpace_EXT += sz;
2055 Yap_inform_profiler_of_clause(ncode, (CODEADDR)ncode + sz, ap,
2056 GPROF_NEW_EXPAND_BLOCK);
2058 ncode->opc = Yap_opcode(_expand_clauses);
2059 ncode->y_u.sssllp.p = ap;
2060 ncode->y_u.sssllp.s1 = tels;
2061 ncode->y_u.sssllp.s2 = cls;
2062 ncode->y_u.sssllp.s3 = 1;
2063 st = (
yamop **)NEXTOP(ncode, sssllp);
2064 while (min <= max) {
2068 while (cls < tels) {
2072 LOCK(ExpandClausesListLock);
2073 ncode->y_u.sssllp.snext = ExpandClausesFirst;
2074 ncode->y_u.sssllp.sprev = NULL;
2075 if (ExpandClausesFirst)
2076 ExpandClausesFirst->y_u.sssllp.sprev = ncode;
2077 ExpandClausesFirst = ncode;
2078 if (ExpandClausesLast == NULL)
2079 ExpandClausesLast = ncode;
2080 UNLOCK(ExpandClausesListLock);
2083 return (UInt) & (ap->cs.p_code.ExpandCode);
2086static void recover_ecls_block(
yamop *ipc) {
2087 ipc->y_u.sssllp.s3--;
2088 if (!ipc->y_u.sssllp.s3) {
2089 LOCK(ExpandClausesListLock);
2090 if (ExpandClausesFirst == ipc)
2091 ExpandClausesFirst = ipc->y_u.sssllp.snext;
2092 if (ExpandClausesLast == ipc) {
2093 ExpandClausesLast = ipc->y_u.sssllp.sprev;
2095 if (ipc->y_u.sssllp.sprev) {
2096 ipc->y_u.sssllp.sprev->y_u.sssllp.snext = ipc->y_u.sssllp.snext;
2098 if (ipc->y_u.sssllp.snext) {
2099 ipc->y_u.sssllp.snext->y_u.sssllp.sprev = ipc->y_u.sssllp.sprev;
2101 UNLOCK(ExpandClausesListLock);
2103 Yap_ExpandClauses--;
2104 Yap_expand_clauses_sz -= (UInt)(NEXTOP((
yamop *)NULL, sssllp)) +
2105 ipc->y_u.sssllp.s1 *
sizeof(
yamop *);
2108 Yap_InformOfRemoval(ipc);
2109 if (ipc->y_u.sssllp.p->PredFlags & LogUpdatePredFlag) {
2110 Yap_LUIndexSpace_EXT -= (UInt)NEXTOP((
yamop *)NULL, sssllp) +
2111 ipc->y_u.sssllp.s1 *
sizeof(
yamop *);
2113 Yap_IndexSpace_EXT -= (UInt)NEXTOP((
yamop *)NULL, sssllp) +
2114 ipc->y_u.sssllp.s1 *
sizeof(
yamop *);
2115 Yap_FreeCodeSpace((
char *)ipc);
2120 UInt argno,
int first,
int clleft, UInt nxtlbl) {
2123 if (!IsVarTerm(t) || t != 0L) {
2124 return suspend_indexing(grp->FirstClause, grp->LastClause, ap, cint);
2126 return do_var_group(grp, cint, FALSE, first, clleft, nxtlbl,
2131 int compound_term, CELL *sreg, UInt arity,
int last_arg,
2132 UInt argno,
int first, UInt nxtlbl,
int clleft,
2142 if (!IsAtomTerm(min->Tag) && !IsIntTerm(min->Tag)) {
2146 n = count_consts(grp);
2147 lbl = new_label(cint);
2148 Yap_emit(label_op, lbl, Zero, cint);
2149 cs = emit_cswitch(n, FAILCODE, cint);
2150 for (i = 0; i < n; i++) {
2154 ics = fetch_centry(cs, min->Tag, i, n);
2155 ics->Tag = min->Tag;
2156 while (max != grp->LastClause && (max + 1)->Tag == min->Tag)
2160 if (ap->PredFlags & LogUpdatePredFlag && max > min) {
2161 ics->u_a.Label = suspend_indexing(min, max, ap, cint);
2163 ics->u_a.Label = do_compound_index(
2164 min, max, sreg, cint, compound_term, arity, argno, nxtlbl, first,
2165 last_arg, clleft, top, TRUE);
2167 }
else if (ap->PredFlags & LogUpdatePredFlag) {
2168 ics->u_a.Label = suspend_indexing(min, max, cint->CurrentPred, cint);
2171 do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top);
2175 do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top);
2177 grp->FirstClause = min = max + 1;
2183 UInt argno,
int first, UInt nxtlbl,
int clleft,
2192 n = count_blobs(grp);
2193 cs = emit_cswitch(n, (
yamop *)nxtlbl, cint);
2194 for (i = 0; i < n; i++) {
2198 ics = fetch_centry(cs, min->Tag, i, n);
2199 ics->Tag = min->Tag;
2200 while (max != grp->LastClause && (max + 1)->Tag == min->Tag)
2202 if (min != max && (ap->PredFlags & LogUpdatePredFlag)) {
2203 ics->u_a.Label = suspend_indexing(min, max, ap, cint);
2206 do_index(min, max, cint, argno + 1, nxtlbl, first, clleft, top);
2208 grp->FirstClause = min = max + 1;
2213 UInt argno,
int first,
int last_arg, UInt nxtlbl,
2214 int clleft, CELL *top) {
2215 COUNT n = count_funcs(grp);
2221 if (min > grp->LastClause || n == 0) {
2225 lbl = new_label(cint);
2226 Yap_emit(label_op, lbl, Zero, cint);
2228 fs = emit_fswitch(n, FAILCODE, cint);
2229 for (i = 0; i < n; i++) {
2234 ifs = fetch_fentry(fs, f, i, n);
2236 while (max != grp->LastClause && (max + 1)->Tag == min->Tag)
2245 if (IsExtensionFunctor(f)) {
2246 if (f == FunctorDBRef)
2247 ifs->u_f.Label = do_dbref_index(min, max, t, cint, argno, nxtlbl, first,
2249 else if (f == FunctorLongInt || f == FunctorBigInt)
2250 ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first,
2251 clleft, top, FALSE);
2253 ifs->u_f.Label = do_blob_index(min, max, t, cint, argno, nxtlbl, first,
2259 if (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == f) {
2260 sreg = RepAppl(t) + 1;
2265 do_compound_index(min, max, sreg, cint, 0, ArityOfFunctor(f), argno,
2266 nxtlbl, first, last_arg, clleft, top, TRUE);
2268 grp->FirstClause = min = max + 1;
2274 UInt argno,
int first,
int last_arg, UInt nxtlbl,
2275 int clleft, CELL *top) {
2279 while (IsPairTerm(max->Tag) && max != grp->LastClause) {
2282 if (!IsPairTerm(max->Tag)) {
2285 if (min > grp->LastClause) {
2289 grp->FirstClause = max + 1;
2292 if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) {
2293 return (UInt)(min->Code);
2295 return (UInt)(min->CurrentCode);
2298 if (min != max && !IsPairTerm(t)) {
2299 return suspend_indexing(min, max, cint->CurrentPred, cint);
2301 return do_compound_index(min, max, (IsPairTerm(t) ? RepPair(t) : NULL), cint,
2302 0, 2, argno, nxtlbl, first, last_arg, clleft, top,
2306static void group_prologue(
int compound_term, UInt argno,
int first,
2308 if (compound_term) {
2309 Yap_emit(cache_sub_arg_op, compound_term - 1, compound_term - 1, cint);
2311 if (!first || argno != 1) {
2312 Yap_emit(cache_arg_op, argno, argno, cint);
2318static void emit_protection_choicepoint(
int first,
int clleft, UInt nxtlbl,
2323 if (cint->CurrentPred->PredFlags & LogUpdatePredFlag) {
2324 UInt labl = new_label(cint);
2326 Yap_emit_4ops(enter_lu_op, labl, labl, 0, Zero, cint);
2327 Yap_emit(label_op, labl, Zero, cint);
2329 Yap_emit(tryme_op, nxtlbl, (clleft << 1), cint);
2334 Yap_emit(retryme_op, nxtlbl, (clleft << 1), cint);
2336 Yap_emit(trustme_op, 0, 0, cint);
2342 int compound_term, UInt argno,
int last_arg) {
2346 if (compound_term) {
2348 skip_to_arg(cl, ap, compound_term, last_arg);
2353 if (cl->Tag == (_var + 1) *
sizeof(CELL)) {
2356 clcpy(cli, cli + 1);
2361 move_next(cl, argno);
2369static void purge_pvar(
GroupDef *group) {
2374 if (cl->Tag == (_var + 1) *
sizeof(CELL)) {
2377 clcpy(cli, cli + 1);
2380 group->VarClauses--;
2385 group->LastClause = max;
2388static UInt *do_nonvar_group(
GroupDef *grp, Term t, UInt compound_term,
2389 CELL *sreg, UInt arity, UInt labl,
2391 int last_arg, UInt nxtlbl,
int clleft, CELL *top) {
2396 if (grp->AtomClauses + grp->PairClauses + grp->StructClauses > 1) {
2397 Yap_emit(label_op, labl, Zero, cint);
2398 if (argno == 1 && !compound_term) {
2399 emit_protection_choicepoint(first, clleft, nxtlbl, cint);
2401 group_prologue(compound_term, argno, first, cint);
2402 if (grp->LastClause < grp->FirstClause) {
2405 type_sw = emit_type_switch(switch_on_type_op, cint);
2407 type_sw->ConstEntry = type_sw->FuncEntry = type_sw->PairEntry =
2408 type_sw->VarEntry = nxtlbl;
2410 do_var_entries(grp, t, cint, argno, first, clleft, nxtlbl);
2411 grp->LastClause = cls_move(grp->FirstClause, ap, grp->LastClause,
2412 compound_term, argno, last_arg);
2413 sort_group(grp, top, cint);
2414 while (grp->FirstClause <= grp->LastClause) {
2415 if (IsAtomOrIntTerm(grp->FirstClause->Tag)) {
2416 type_sw->ConstEntry =
2417 do_consts(grp, t, cint, compound_term, sreg, arity, last_arg, argno,
2418 first, nxtlbl, clleft, top);
2419 }
else if (IsApplTerm(grp->FirstClause->Tag)) {
2420 type_sw->FuncEntry =
2421 do_funcs(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top);
2423 type_sw->PairEntry =
2424 do_pair(grp, t, cint, argno, first, last_arg, nxtlbl, clleft, top);
2427 return &(type_sw->VarEntry);
2429 Yap_emit(label_op, labl, Zero, cint);
2430 do_var_group(grp, cint, TRUE, first, clleft, nxtlbl, ap->ArityOfPE + 1);
2437 if (ngroups == 2 && group[0].FirstClause == group[0].LastClause &&
2438 group[0].AtomClauses == 1 && group[1].VarClauses == 1) {
2442 labl = new_label(cint);
2443 sp = Yap_emit_extra_size(if_not_op, Zero, 4 * CellSize, cint);
2444 sp[0] = (CELL)(group[0].FirstClause->Tag);
2445 sp[1] = (CELL)(group[1].FirstClause->Code);
2446 sp[2] = do_var_clauses(group[0].FirstClause, group[1].LastClause, FALSE,
2447 cint, TRUE, 0, (CELL)FAILCODE,
2448 cint->CurrentPred->ArityOfPE + 1);
2449 sp[3] = do_var_clauses(min, group[1].LastClause, FALSE, cint, TRUE, 0,
2450 (CELL)FAILCODE, cint->CurrentPred->ArityOfPE + 1);
2458 int found_pvar = FALSE;
2461 add_info(cl, argno);
2462 if (cl->Tag == (_var + 1) *
sizeof(CELL)) {
2478 cl->Tag = (CELL)NULL;
2483 LogUpdClause *lcl = ClauseCodeToLogUpdClause(cl->CurrentCode);
2484 Term t = lcl->lusl.ClSource->Entry;
2487 cl->Tag = (CELL)NULL;
2488 }
else if (IsApplTerm(t)) {
2489 CELL *pt = RepAppl(t);
2491 cl->Tag = AbsAppl((CELL *)pt[0]);
2492 if (IsExtensionFunctor(FunctorOfTerm(t))) {
2495 cl->ucd.c_sreg = pt;
2497 }
else if (IsPairTerm(t)) {
2498 CELL *pt = RepPair(t);
2500 cl->Tag = AbsPair(NULL);
2501 cl->ucd.c_sreg = pt - 1;
2510 add_info(cl, argno);
2519 UInt argno, UInt fail_l,
int first,
int clleft,
2522 UInt ngroups, found_pvar = FALSE;
2525 UInt labl, labl0, lablx;
2528 UInt argno0 = argno;
2530 yamop *eblk = cint->expand_block;
2534 return emit_single_switch_case(min, cint, first, clleft, fail_l);
2536 if ((argno > 1 && indexingMode() == TermSingle &&
2537 ap->PredFlags & LogUpdatePredFlag) ||
2538 indexingMode() == TermOff || ap->ArityOfPE < argno) {
2539 return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l,
2542 t = Deref(XREGS[argno]);
2543 if (ap->PredFlags & LogUpdatePredFlag) {
2545 cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE));
2547 found_pvar = cls_info(min, max, argno);
2549 ngroups = groups_in(min, max, group, cint);
2551 lablx = new_label(cint);
2552 Yap_emit(label_op, lablx, Zero, cint);
2553 while (IsVarTerm(t)) {
2554 if (ngroups > 1 || !group->VarClauses) {
2555 UInt susp_lab = suspend_indexing(min, max, ap, cint);
2556 if (!cint->expand_block) {
2557 cint->expand_block = (
yamop *)susp_lab;
2559 Yap_emit(jump_nv_op, susp_lab, argno, cint);
2561 if (argno == ap->ArityOfPE ||
2562 (indexingMode() == TermSingle && ap->PredFlags & LogUpdatePredFlag)) {
2563 do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l, argno0);
2564 cint->expand_block = eblk;
2568 t = Deref(XREGS[argno]);
2569 if (ap->PredFlags & LogUpdatePredFlag) {
2571 cls_head_info(min, max, argno, (ap->ModuleOfPred == IDB_MODULE));
2573 found_pvar = cls_info(min, max, argno);
2575 ngroups = groups_in(min, max, group, cint);
2577 labl0 = labl = new_label(cint);
2579 lablx = labl0 = labl = new_label(cint);
2581 cint->expand_block = eblk;
2582 top = (CELL *)(group + ngroups);
2585 if (ngroups > 1 || group->VarClauses != 0 || found_pvar) {
2586 if (ap->ArityOfPE == argno) {
2587 return do_var_clauses(min, max, FALSE, cint, first, clleft, fail_l,
2590 return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top);
2599 cl->CurrentCode = cl->Code;
2604 UInt special_options;
2606 if ((ap->PredFlags & LogUpdatePredFlag) && ngroups > 1) {
2608 group[0].VarClauses = ap->cs.p_code.NOfClauses;
2609 group[0].AtomClauses = group[0].PairClauses = group[0].StructClauses =
2610 group[0].TestClauses = 0;
2611 group[0].LastClause = group[ngroups - 1].LastClause;
2614 }
else if ((special_options =
2615 do_optims(group, ngroups, fail_l, min, cint)) != fail_l) {
2616 return special_options;
2618 if (ngroups == 1 && group->VarClauses && !found_pvar) {
2619 return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top);
2620 }
else if (found_pvar ||
2621 (ap->PredFlags & LogUpdatePredFlag && group[0].VarClauses)) {
2623 Yap_emit(label_op, labl0, Zero, cint);
2624 labl = new_label(cint);
2625 Yap_emit(jump_v_op, suspend_indexing(min, max, ap, cint), Zero, cint);
2628 for (i = 0; i < ngroups; i++) {
2630 int left_clauses = clleft + (max - group->LastClause);
2633 if (i < ngroups - 1) {
2634 nextlbl = new_label(cint);
2638 if (found_pvar && argno == 1) {
2641 if (group->FirstClause == group->LastClause && first && left_clauses == 0) {
2642 Yap_emit(jumpi_op, (CELL)(group->FirstClause->Code), Zero, cint);
2644 if (group->VarClauses) {
2645 Yap_emit(label_op, labl, Zero, cint);
2646 do_var_group(group, cint, argno == 1, first, left_clauses, nextlbl,
2649 do_nonvar_group(group, t, 0, NULL, 0, labl, cint, argno, first, TRUE,
2650 nextlbl, left_clauses, top);
2663 UInt sz = ((max0 + 1) - min0) *
sizeof(
ClauseDef);
2664 if ((
char *)top + sz >= LOCAL_TrailTop - 4096) {
2665 LOCAL_Error_Size = sz;
2667 save_machine_regs();
2668 siglongjmp(cint->CompilerBotch, 4);
2670 memcpy((
void *)top, (
void *)min0, sz);
2676 CELL tag = min->Tag;
2679 if (!IsAtomOrIntTerm(min->Tag) || min->Tag != tag)
2688 UInt argno, UInt fail_l,
int first,
int last_arg,
2689 int clleft, CELL *top,
int done_work) {
2690 UInt ret_lab = 0, *newlabp;
2694 int found_index = FALSE;
2695 pred_flags_t lu_pred = ap->PredFlags & LogUpdatePredFlag;
2696 UInt old_last_depth, old_last_depth_size;
2701 return emit_single_switch_case(min0, cint, first, clleft, fail_l);
2703 if ((indexingMode() == TermSingle && ap->PredFlags & LogUpdatePredFlag) ||
2705 cint->term_depth - cint->last_index_new_depth > indexingDepth())) {
2706 *newlabp = do_var_clauses(min0, max0, FALSE, cint, first, clleft, fail_l,
2711 return suspend_indexing(min0, max0, ap, cint);
2714 old_last_depth = cint->last_index_new_depth;
2715 old_last_depth_size = cint->last_depth_size;
2716 if (cint->last_depth_size != max0 - min0) {
2717 cint->last_index_new_depth = cint->term_depth;
2718 cint->last_depth_size = max0 - min0;
2720 while (i < arity && !found_index) {
2724 int isvt = IsVarTerm(Deref(sreg[i]));
2726 min = copy_clauses(max0, min0, top, cint);
2727 max = min + (max0 - min0);
2728 top = (CELL *)(max + 1);
2732 add_arg_info(cl, ap, i + 1);
2736 ngroups = groups_in(min, max, group, cint);
2737 if (ngroups == 1 && group->VarClauses == 0 &&
2738 (i < 8 || several_tags(min, max))) {
2743 ret_lab = new_label(cint);
2744 top = (CELL *)(group + 1);
2745 if (do_nonvar_group(group, (sreg == NULL ? 0L : Deref(sreg[i])), i + 1,
2746 (isvt ? NULL : sreg), arity, *newlabp, cint, argno,
2747 first, (last_arg && i + 1 == arity), fail_l, clleft,
2757 if (!lu_pred || !done_work)
2759 do_index(min0, max0, cint, argno + 1, fail_l, first, clleft, top);
2761 *newlabp = suspend_indexing(min0, max0, ap, cint);
2763 cint->last_index_new_depth = old_last_depth;
2764 cint->last_depth_size = old_last_depth_size;
2771 int first,
int clleft, CELL *top) {
2780 cl->Tag = cl->ucd.t_ptr;
2783 ngroups = groups_in(min, max, group, cint);
2784 if (ngroups > 1 || group->VarClauses) {
2785 return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top);
2787 int labl = new_label(cint);
2789 Yap_emit(label_op, labl, Zero, cint);
2790 Yap_emit(index_dbref_op, Zero, Zero, cint);
2791 sort_group(group, (CELL *)(group + 1), cint);
2792 do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group + 1));
2799 int first,
int clleft, CELL *top,
int blob) {
2808 if (cl->ucd.t_ptr == (CELL)NULL) {
2811 cl->Tag = Yap_Double_key(cl->ucd.t_ptr);
2813 cl->Tag = Yap_Int_key(cl->ucd.t_ptr);
2817 ngroups = groups_in(min, max, group, cint);
2818 if (ngroups > 1 || group->VarClauses) {
2819 return do_index(min, max, cint, argno + 1, fail_l, first, clleft, top);
2821 int labl = new_label(cint);
2823 Yap_emit(label_op, labl, Zero, cint);
2825 Yap_emit(index_blob_op, Zero, Zero, cint);
2827 Yap_emit(index_long_op, Zero, Zero, cint);
2828 sort_group(group, (CELL *)(group + 1), cint);
2829 do_blobs(group, t, cint, argno, first, fail_l, clleft, (CELL *)(group + 1));
2835 if (ap->PredFlags & MegaClausePredFlag) {
2836 MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
2837 UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses;
2838 yamop *end = (
yamop *)((
char *)mcl->ClCode + nclauses * mcl->ClItemSize);
2839 yamop *cd = mcl->ClCode;
2841 cl->Code = cl->CurrentCode = cd;
2842 cd = (
yamop *)((
char *)cd + mcl->ClItemSize);
2848 scl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
2850 cl->Code = cl->CurrentCode = scl->ClCode;
2852 if (scl->ClCode == ap->cs.p_code.LastClause)
2860 LogUpdClause *lcl = ClauseCodeToLogUpdClause(ap->cs.p_code.FirstClause);
2863 cl->Code = cl->CurrentCode = lcl->ClCode;
2866 }
while (lcl != NULL);
2872 int NClauses = ap->cs.p_code.NOfClauses;
2873 CELL *top = (CELL *)TR;
2877 cint->i_labelno = 1;
2879 LOCAL_Error_Size = 0;
2880#if USE_SYSTEM_MALLOC
2885 LOCAL_Error_Size += NClauses *
sizeof(
ClauseDef);
2887 save_machine_regs();
2888 siglongjmp(cint->CompilerBotch, 2);
2891 cint->freep = (
char *)HR;
2895 if (cint->cls + 2 * NClauses > (
ClauseDef *)(ASP - 4096)) {
2897 LOCAL_Error_Size += NClauses *
sizeof(
ClauseDef);
2899 save_machine_regs();
2900 siglongjmp(cint->CompilerBotch, 3);
2902 cint->freep = (
char *)(cint->cls + NClauses);
2904 if (ap->PredFlags & LogUpdatePredFlag) {
2907 init_log_upd_clauses(cint->cls, ap);
2908 }
else if (ap->PredFlags & UDIPredFlag) {
2909 UInt lbl = new_label(cint);
2910 Yap_emit(user_switch_op, Unsigned(ap),
2911 Unsigned(&(ap->cs.p_code.ExpandCode)), cint);
2915 init_clauses(cint->cls, ap);
2917 res = do_index(cint->cls, cint->cls + (NClauses - 1), cint, 1, (UInt)FAILCODE,
2923#if USE_SYSTEM_MALLOC
2925 Yap_FreeCodeSpace((ADDR)cint->cls);
2937 cint.CurrentPred = ap;
2938 cint.code_addr = NULL;
2941 LOCAL_Error_Size = 0;
2943 if ((setjres = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
2944 restore_machine_regs();
2945 recover_from_failed_susp_on_cls(&cint, 0);
2946 if (!Yap_dogc(PASS_REGS1)) {
2948 Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
2951 }
else if (setjres == 2) {
2952 restore_machine_regs();
2953 LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size);
2954 if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
2956 Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
2959 }
else if (setjres == 4) {
2960 restore_machine_regs();
2961 recover_from_failed_susp_on_cls(&cint, 0);
2962 if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) {
2964 Yap_Error(RESOURCE_ERROR_TRAIL, TermNil, LOCAL_ErrorMessage);
2967 }
else if (setjres != 0) {
2968 restore_machine_regs();
2969 recover_from_failed_susp_on_cls(&cint, 0);
2970 if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
2971 Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
2977 if (ap->cs.p_code.NOfClauses==0) {
2978if (ap->PredFlags & (LogUpdatePredFlag|MultiFileFlag)) {
2979 ap->OpcodeOfPred = FAIL_OPCODE;
2980 ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred =
2983 ap->OpcodeOfPred = UNDEF_OPCODE;
2984 ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred =
2985 (
yamop *)(&(ap->OpcodeOfPred));
2986 ap->PredFlags |= UndefPredFlag;
2988 ap->PredFlags &= ~IndexedPredFlag;
2989return ap->CodeOfPred;
2992 if (ap->cs.p_code.NOfClauses==1) {
2993 ap->OpcodeOfPred = ap->CodeOfPred->opc;
2994 ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred =
2995 ap->cs.p_code.FirstClause;
2996 ap->PredFlags &= ~ IndexedPredFlag;
2997return ap->CodeOfPred;
3000 Yap_BuildMegaClause(ap);
3001 cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL;
3002 cint.expand_block = NULL;
3003 cint.label_offset = NULL;
3004 cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L;
3005 if (compile_index(&cint) == (UInt)FAILCODE) {
3006 Yap_ReleaseCMem(&cint);
3011 if (GLOBAL_Option[
'i' -
'a' + 1]) {
3012 Yap_ShowCode(&cint);
3016 LOCAL_IPredArity = ap->ArityOfPE;
3017 if (cint.CodeStart) {
3018 if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint,
3019 cint.i_labelno + 1)) == NULL) {
3020 if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
3021 Yap_ReleaseCMem(&cint);
3023 Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
3029 Yap_ReleaseCMem(&cint);
3033 Yap_ReleaseCMem(&cint);
3035 if (ap->PredFlags & LogUpdatePredFlag) {
3036 LogUpdIndex *cl = ClauseCodeToLogUpdIndex(indx_out);
3037 cl->ClFlags |= SwitchRootMask;
3039 ap->PredFlags |= IndexedPredFlag;
3048 save_machine_regs();
3049 siglongjmp(cint->CompilerBotch, 4);
3063 if ((Int)(sp->pos) > 0) {
3064 add_info(cls, sp->pos);
3065 }
else if (sp->pos) {
3066 UInt argno = -sp->pos;
3067 add_arg_info(cls, ap, argno);
3070 if (cls->Tag != sp->val) {
3071 if (sp->val == 0L) {
3076 if (IsApplTerm(cls->Tag)) {
3078 if (IsExtensionFunctor(f)) {
3079 if (f == FunctorDBRef) {
3080 if (cls->ucd.t_ptr != sp->extra)
3082 }
else if (f == FunctorDouble) {
3083 if (cls->ucd.t_ptr &&
3084 Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr))
3086 }
else if (f == FunctorString) {
3087 if (cls->ucd.t_ptr &&
3088 Yap_String_key(sp->extra) != Yap_String_key(cls->ucd.t_ptr))
3091 if (cls->ucd.t_ptr &&
3092 Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr))
3097 if ((Int)(sp->pos) > 0) {
3098 move_next(cls, sp->pos);
3099 }
else if (sp->pos) {
3100 UInt argno = -sp->pos;
3101 skip_to_arg(cls, ap, argno, FALSE);
3112 if (ap->PredFlags & MegaClausePredFlag) {
3113 MegaClause *mcl = ClauseCodeToMegaClause(beg);
3114 UInt nclauses = mcl->ClPred->cs.p_code.NOfClauses;
3115 yamop *end = (
yamop *)((
char *)mcl->ClCode + nclauses * mcl->ClItemSize);
3116 yamop *cd = mcl->ClCode;
3118 if (stack[0].pos == 0) {
3120 cls->Code = cls->CurrentCode = cd;
3123 cd = (
yamop *)((
char *)cd + mcl->ClItemSize);
3130 cls->Code = cls->CurrentCode = cd;
3131 sp = install_clause(cls, ap, stack);
3133 if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) {
3136 cd = (
yamop *)((
char *)cd + mcl->ClItemSize);
3144 if (stack[0].pos == 0) {
3146 cls->Code = cls->CurrentCode = cl->ClCode;
3149 if (cl->ClCode == end) {
3156 cls->Code = cls->CurrentCode = cl->ClCode;
3157 sp = install_clause(cls, ap, stack);
3159 if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) {
3162 if (cl->ClCode == end) {
3175 if (stack[0].pos == 0) {
3178 cls->Code = cls->CurrentCode = *beg;
3190 cls->Code = cls->CurrentCode = *beg;
3191 sp = install_clause(cls, ap, stack);
3193 if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) {
3207 cls->CurrentCode = cls->Code;
3208 install_clause(cls, ap, stack);
3209 }
while (cls++ != end);
3216 if ((Int)(sp->pos) > 0) {
3217 add_head_info(cls, sp->pos);
3218 }
else if (sp->pos) {
3219 UInt argno = -sp->pos;
3220 add_arg_info(cls, ap, argno);
3223 if (cls->Tag != sp->val) {
3224 if (sp->val == 0L) {
3229 if (IsApplTerm(cls->Tag)) {
3231 if (IsExtensionFunctor(f)) {
3232 if (f == FunctorDBRef) {
3233 if (cls->ucd.t_ptr != sp->extra)
3235 }
else if (f == FunctorDouble) {
3236 if (cls->ucd.t_ptr &&
3237 Yap_Double_key(sp->extra) != Yap_Double_key(cls->ucd.t_ptr))
3240 if (cls->ucd.t_ptr &&
3241 Yap_Int_key(sp->extra) != Yap_Int_key(cls->ucd.t_ptr))
3246 if ((Int)(sp->pos) > 0) {
3247 move_next(cls, sp->pos);
3248 }
else if (sp->pos) {
3249 UInt argno = -sp->pos;
3251 skip_to_arg(cls, ap, argno, FALSE);
3264 if (stack[0].pos == 0) {
3266 cls->Code = cls->CurrentCode = beg;
3269 if (beg == end || beg == NULL) {
3272 beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode;
3276 cls->Code = cls->CurrentCode = beg;
3277 sp = install_log_upd_clause(cls, ap, stack);
3279 if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) {
3282 if (beg == end || beg == NULL) {
3285 beg = ClauseCodeToLogUpdClause(beg)->ClNext->ClCode;
3294 if (stack[0].pos == 0) {
3297 cls->Code = cls->CurrentCode = *beg;
3309 cls->Code = cls->CurrentCode = *beg;
3310 sp = install_log_upd_clause(cls, ap, stack);
3312 if (!sp->pos && (sp[-1].val == 0L || cls->Tag == sp[-1].val)) {
3326 cls->CurrentCode = cls->Code;
3327 install_log_upd_clause(cls, ap, stack);
3328 }
while (cls++ != end);
3331#if PRECOMPUTE_REGADDRESS
3333#define arg_from_x(I) (((CELL *)(I)) - XREGS)
3337#define arg_from_x(I) (I)
3344 while (cebase->Tag != t) {
3356 while (febase->Tag != f) {
3366 if (ap->PredFlags & LogUpdatePredFlag) {
3375 }
else if (ap->PredFlags & MegaClausePredFlag) {
3376 MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
3377 UInt ncls = mcl->ClPred->cs.p_code.NOfClauses;
3379 return (ncls - 1) - ((
char *)cl - (
char *)mcl->ClCode) / mcl->ClItemSize;
3381 yamop *last = ap->cs.p_code.LastClause;
3385 c = ClauseCodeToStaticClause(cl);
3386 while (c->ClCode != last) {
3400 if (cur.lui == NULL || ipc == FAILCODE || ipc == e_code ||
3401 ipc->opc == Yap_opcode(_expand_clauses))
3406 if (ipc >= lcur->ClCode && ipc < (
yamop *)((CODEADDR)lcur + lcur->ClSize))
3410 if (lcur->ParentIndex) {
3412 if (ipc >= pcur->ClCode &&
3413 ipc < (
yamop *)((CODEADDR)pcur + pcur->ClSize)) {
3419 ncur = ClauseCodeToLogUpdIndex(ipc);
3420 if (ncur->ParentIndex != lcur) {
3422 fprintf(stderr,
"OOPS, bad parent in lu index\n");
3434 if (ipc >= scur->ClCode && ipc < (
yamop *)((CODEADDR)scur + scur->ClSize))
3436 ncur = ClauseCodeToStaticIndex(ipc);
3437 if (ncur->ClPred == scur->ClPred) {
3460 ret.lui = ClauseCodeToLogUpdIndex(ipc);
3462 ret.si = ClauseCodeToStaticIndex(ipc);
3471 if (ipc->opc == Yap_opcode(_switch_on_sub_arg_type) &&
3472 (ncode = ipc->y_u.sllll.l4)->opc == Yap_opcode(_expand_clauses)) {
3473 if (ncode->y_u.sssllp.s2 != cint->last_depth_size) {
3474 cint->last_index_new_depth = cint->term_depth;
3475 cint->last_depth_size = ncode->y_u.sssllp.s2;
3481 cint->term_depth = cint->last_index_new_depth;
3482 cint->last_depth_size = ap->cs.p_code.NOfClauses;
3489 yamop *first, *last = NULL, *alt = NULL;
3496 yamop **labp = NULL;
3498 Term t = TermNil, *s_reg = NULL;
3499 int is_last_arg = TRUE;
3501 int isfirstcl = TRUE;
3503 CELL *top = (CELL *)TR;
3505 UInt lab, fail_l, clleft, i = 0;
3506 int is_lu = ap->PredFlags & LogUpdatePredFlag;
3507 yamop *e_code = (
yamop *)&(ap->cs.p_code.ExpandCode);
3509 ipc = ap->cs.p_code.TrueCodeOfPred;
3510 first = ap->cs.p_code.FirstClause;
3511 NClauses = ap->cs.p_code.NOfClauses;
3513 cint->i_labelno = 1;
3516 cint->term_depth = cint->last_index_new_depth = cint->last_depth_size = 0L;
3518 parentcl = code_to_indexcl(ipc, is_lu);
3519 while (ipc != NULL) {
3522 op = Yap_op_from_opcode(ipc->opc);
3527 if (ap->PredFlags & LogUpdatePredFlag) {
3528 first = ClauseCodeToLogUpdClause(ipc->y_u.Otapl.d)->ClNext->ClCode;
3529 }
else if (ap->PredFlags & MegaClausePredFlag) {
3530 MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
3531 first = (
yamop *)((
char *)ipc->y_u.Otapl.d) + mcl->ClItemSize;
3533 first = ClauseCodeToStaticClause(ipc->y_u.Otapl.d)->ClNext->ClCode;
3536 ipc = NEXTOP(ipc, Otapl);
3542 first = ClauseCodeToStaticClause(PREVOP(ipc->y_u.Otapl.d, Otapl))
3545 ipc = NEXTOP(ipc, Otapl);
3555 if (ap->PredFlags & LogUpdatePredFlag) {
3556 first = ClauseCodeToLogUpdClause(ipc->y_u.l.l)->ClNext->ClCode;
3557 }
else if (ap->PredFlags & MegaClausePredFlag) {
3558 MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
3559 first = (
yamop *)((
char *)ipc->y_u.Otapl.d) + mcl->ClItemSize;
3561 first = ClauseCodeToStaticClause(ipc->y_u.l.l)->ClNext->ClCode;
3564 ipc = NEXTOP(ipc, l);
3568 case _table_retry_me:
3578 alt = ipc->y_u.Otapl.d;
3579 ipc = NEXTOP(ipc, Otapl);
3584 case _profiled_trust_me:
3586 case _count_trust_me:
3588 case _table_trust_me:
3591 ipc = NEXTOP(ipc, Otapl);
3599 Yap_Error(SYSTEM_ERROR_COMPILER, TermNil,
"found trust in expand_index");
3605 case _retry_logical:
3606 case _count_retry_logical:
3607 case _profiled_retry_logical:
3608 ipc = ipc->y_u.OtaLl.n;
3610 case _trust_logical:
3611 case _count_trust_logical:
3612 case _profiled_trust_logical:
3613 ipc = ipc->y_u.OtILl.n;
3615 case _enter_lu_pred:
3617 ipc = ipc->y_u.Illss.l1;
3619 case _retry_profiled:
3622 ipc = NEXTOP(ipc, l);
3632 ipc = NEXTOP(ipc, p);
3635 ipc = NEXTOP(ipc, e);
3638 if (IsVarTerm(Deref(ARG1))) {
3639 labp = &(ipc->y_u.l.l);
3641 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3643 ipc = NEXTOP(ipc, l);
3646 case _jump_if_nonvar:
3647 argno = arg_from_x(ipc->y_u.xll.x);
3648 t = Deref(XREGS[argno]);
3651 if (!IsVarTerm(t)) {
3653 labp = &(ipc->y_u.xll.l1);
3654 ipc = ipc->y_u.xll.l1;
3655 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3658 ipc = NEXTOP(ipc, xll);
3664 if (s_reg[-1] != (CELL)FunctorDBREF) {
3669 t = AbsAppl(s_reg - 1);
3672 ipc = NEXTOP(ipc, e);
3675 if (s_reg[-1] != (CELL)FunctorDouble) {
3680 t = Yap_DoubleP_key(s_reg);
3681 sp[-1].extra = AbsAppl(s_reg - 1);
3683 ipc = NEXTOP(ipc, e);
3686 if (s_reg[-1] != (CELL)FunctorLongInt) {
3691 t = Yap_IntP_key(s_reg);
3692 sp[-1].extra = AbsAppl(s_reg - 1);
3694 ipc = NEXTOP(ipc, e);
3697 labp = &(ipc->y_u.lp.l);
3698 ipc = ipc->y_u.lp.l;
3701 case _switch_on_type:
3702 zero_expand_depth(ap, cint);
3707 labp = &(ipc->y_u.llll.l4);
3708 ipc = ipc->y_u.llll.l4;
3709 }
else if (IsPairTerm(t)) {
3710 sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint);
3712 labp = &(ipc->y_u.llll.l1);
3713 ipc = ipc->y_u.llll.l1;
3714 increase_expand_depth(ipc, cint);
3715 }
else if (IsApplTerm(t)) {
3717 push_stack(sp, 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil, cint);
3718 ipc = ipc->y_u.llll.l3;
3719 increase_expand_depth(ipc, cint);
3721 sp = push_stack(sp, argno, t, TermNil, cint);
3722 ipc = ipc->y_u.llll.l2;
3724 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3726 case _switch_list_nl:
3727 zero_expand_depth(ap, cint);
3732 labp = &(ipc->y_u.ollll.l4);
3733 ipc = ipc->y_u.ollll.l4;
3734 }
else if (IsPairTerm(t)) {
3736 labp = &(ipc->y_u.ollll.l1);
3737 sp = push_stack(sp, 1, AbsPair(NULL), TermNil, cint);
3738 ipc = ipc->y_u.ollll.l1;
3739 increase_expand_depth(ipc, cint);
3740 }
else if (t == TermNil) {
3741 sp = push_stack(sp, 1, t, TermNil, cint);
3742 ipc = ipc->y_u.ollll.l2;
3743 increase_expand_depth(ipc, cint);
3747 if (IsApplTerm(t)) {
3748 tn = AbsAppl((CELL *)FunctorOfTerm(t));
3752 sp = push_stack(sp, argno, tn, TermNil, cint);
3753 ipc = ipc->y_u.ollll.l3;
3755 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3757 case _switch_on_arg_type:
3758 zero_expand_depth(ap, cint);
3759 argno = arg_from_x(ipc->y_u.xllll.x);
3761 t = Deref(XREGS[argno]);
3763 labp = &(ipc->y_u.xllll.l4);
3764 ipc = ipc->y_u.xllll.l4;
3765 }
else if (IsPairTerm(t)) {
3767 sp = push_stack(sp, argno, AbsPair(NULL), TermNil, cint);
3768 labp = &(ipc->y_u.xllll.l1);
3769 ipc = ipc->y_u.xllll.l1;
3770 increase_expand_depth(ipc, cint);
3771 }
else if (IsApplTerm(t)) {
3772 sp = push_stack(sp, argno, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil,
3774 ipc = ipc->y_u.xllll.l3;
3775 increase_expand_depth(ipc, cint);
3777 sp = push_stack(sp, argno, t, TermNil, cint);
3778 ipc = ipc->y_u.xllll.l2;
3780 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3782 case _switch_on_sub_arg_type:
3783 i = ipc->y_u.sllll.s;
3784 t = Deref(s_reg[i]);
3786 is_last_arg = FALSE;
3787 t = Deref(s_reg[i]);
3789 labp = &(ipc->y_u.sllll.l4);
3790 ipc = ipc->y_u.sllll.l4;
3792 }
else if (IsPairTerm(t)) {
3794 sp = push_stack(sp, -i - 1, AbsPair(NULL), TermNil, cint);
3795 labp = &(ipc->y_u.sllll.l1);
3796 ipc = ipc->y_u.sllll.l1;
3798 increase_expand_depth(ipc, cint);
3799 }
else if (IsApplTerm(t)) {
3800 sp = push_stack(sp, -i - 1, AbsAppl((CELL *)FunctorOfTerm(t)), TermNil,
3802 ipc = ipc->y_u.sllll.l3;
3804 increase_expand_depth(ipc, cint);
3809 sp = push_stack(sp, -i - 1, t, TermNil, cint);
3810 ipc = ipc->y_u.sllll.l2;
3813 parentcl = index_jmp(parentcl, parentcl, ipc, is_lu, e_code);
3820 case _switch_on_func:
3829 if (op == _switch_on_func) {
3830 fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
3832 fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
3834 newpc = fe->u_f.labp;
3836 labp = &(fe->u_f.labp);
3837 if (newpc == e_code) {
3839 parentcl = code_to_indexcl(ipc->y_u.sssl.l, is_lu);
3842 ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l, is_lu);
3844 parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code);
3847 case _switch_on_cons:
3852 if (op == _switch_on_cons) {
3853 ae = lookup_c_hash(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
3855 ae = lookup_c(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
3858 labp = &(ae->u_a.labp);
3859 if (ae->u_a.labp == e_code) {
3861 parentcl = code_to_indexcl(ipc->y_u.sssl.l, is_lu);
3864 ClausePointer npar = code_to_indexcl(ipc->y_u.sssl.l, is_lu);
3866 parentcl = index_jmp(npar, parentcl, ipc, is_lu, e_code);
3870 case _expand_clauses:
3871 if (alt != NULL && ap->PredFlags & LogUpdatePredFlag) {
3872 op_numbers fop = Yap_op_from_opcode(alt->opc);
3873 if (fop == _enter_lu_pred)
3874 alt = alt->y_u.Illss.l1;
3884 Yap_Error(SYSTEM_ERROR_COMPILER, t,
3885 "unexpected instruction %d at expand_index ", op);
3890 first = alt->y_u.Otapl.d;
3900 cint->current_cl.lui = parentcl.lui;
3902 cint->current_cl.si = parentcl.si;
3909 if (alt == TRUSTFAILCODE)
3914 fail_l = (UInt)FAILCODE;
3916 last = ap->cs.p_code.LastClause;
3918 if (ap->PredFlags & LogUpdatePredFlag) {
3919 op_numbers op = Yap_op_from_opcode(alt->opc);
3921 if (op >= _retry2 && op <= _retry4) {
3922 last = alt->y_u.l.l;
3924 last = alt->y_u.Otapl.d;
3927 op_numbers op = Yap_op_from_opcode(alt->opc);
3928 if (op == _retry || op == _trust) {
3929 last = alt->y_u.Otapl.d;
3931 }
else if (op == _table_retry || op == _table_trust) {
3932 last = PREVOP(alt->y_u.Otapl.d, Otapl);
3934 }
else if (op >= _retry2 && op <= _retry4) {
3935 last = alt->y_u.l.l;
3939 clleft = count_clauses_left(last, ap);
3942 if (Yap_op_from_opcode((*labp)->opc) == _expand_clauses) {
3946 COUNT nclauses = ipc->y_u.sssllp.s1;
3949 cint->expand_block = ipc;
3950#if USE_SYSTEM_MALLOC
3955 LOCAL_Error_Size += NClauses *
sizeof(
ClauseDef);
3957 save_machine_regs();
3958 siglongjmp(cint->CompilerBotch, 2);
3963 if (cint->cls + 2 * nclauses > (
ClauseDef *)(ASP - 4096)) {
3965 LOCAL_Error_Size += 2 * NClauses *
sizeof(
ClauseDef);
3967 save_machine_regs();
3968 siglongjmp(cint->CompilerBotch, 3);
3971 if (ap->PredFlags & LogUpdatePredFlag) {
3973 install_log_upd_clauseseq(cint->cls, ap, stack, clp, clp + nclauses);
3975 max = install_clauseseq(cint->cls, ap, stack, clp, clp + nclauses);
3978 cint->expand_block = NULL;
3979#if USE_SYSTEM_MALLOC
3984 LOCAL_Error_Size += NClauses *
sizeof(
ClauseDef);
3986 save_machine_regs();
3987 siglongjmp(cint->CompilerBotch, 2);
3992 if (cint->cls + 2 * NClauses > (
ClauseDef *)(ASP - 4096)) {
3994 LOCAL_Error_Size += 2 * NClauses *
sizeof(
ClauseDef);
3995 save_machine_regs();
3996 siglongjmp(cint->CompilerBotch, 3);
3999 if (ap->PredFlags & LogUpdatePredFlag) {
4000 max = install_log_upd_clauses(cint->cls, ap, stack, first, last);
4002 max = install_clauses(cint->cls, ap, stack, first, last);
4005 if (ap->PredFlags & LogUpdatePredFlag) {
4006 fprintf(stderr,
"vsc +");
4008 fprintf(stderr,
"vsc ");
4010 fprintf(stderr,
" : expanding %d out of %d\n", (max - cls) + 1, NClauses);
4014 if (alt && max->Code == last)
4016 if (max < cint->cls && labp != NULL) {
4020#if USE_SYSTEM_MALLOC
4021 cint->freep = (
char *)HR;
4023 cint->freep = (
char *)(max + 1);
4025 cint->CodeStart = cint->BlobsStart = cint->cpc = cint->icpc = NULL;
4027 if (!IsVarTerm(sp[-1].val) && sp > stack) {
4028 if (IsAtomOrIntTerm(sp[-1].val)) {
4029 if (s_reg == NULL) {
4030 lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl,
4035 if (ap->PredFlags & LogUpdatePredFlag) {
4036 reinstall_log_upd_clauses(cint->cls, max, ap, stack);
4038 reinstall_clauses(cint->cls, max, ap, stack);
4041 while (sp > stack) {
4042 Term t = sp[-1].val;
4043 if (IsApplTerm(t)) {
4045 if (!IsExtensionFunctor(f)) {
4046 arity = ArityOfFunctor(f);
4051 }
else if (IsPairTerm(t)) {
4058 lab = do_compound_index(cint->cls, max, s_reg, cint, i, arity, argno,
4059 fail_l, isfirstcl, is_last_arg, clleft, top,
4062 }
else if (IsPairTerm(sp[-1].val) && sp > stack) {
4063 lab = do_compound_index(cint->cls, max, s_reg, cint, i, 2, argno, fail_l,
4064 isfirstcl, is_last_arg, clleft, top, FALSE);
4068 if (IsExtensionFunctor(f)) {
4069 lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl,
4072 lab = do_compound_index(cint->cls, max, s_reg, cint, i,
4073 ArityOfFunctor(f), argno, fail_l, isfirstcl,
4074 is_last_arg, clleft, top, FALSE);
4078 if (argno == ap->ArityOfPE) {
4079 lab = do_var_clauses(cint->cls, max, FALSE, cint, isfirstcl, clleft,
4080 fail_l, ap->ArityOfPE + 1);
4082 lab = do_index(cint->cls, max, cint, argno + 1, fail_l, isfirstcl, clleft,
4086 if (labp && !(lab & 1)) {
4087 *labp = (
yamop *)lab;
4093 yamop *nextop USES_REGS) {
4094 yamop *indx_out, *expand_clauses;
4101 cint.code_addr = NULL;
4102 cint.label_offset = NULL;
4103 if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
4105 restore_machine_regs();
4107 recover_from_failed_susp_on_cls(&cint, 0);
4108 Yap_dogc(PASS_REGS1);
4109 }
else if (cb == 2) {
4110 restore_machine_regs();
4111 LOCAL_Error_Size = recover_from_failed_susp_on_cls(&cint, LOCAL_Error_Size);
4112 if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
4113 save_machine_regs();
4114 if (ap->PredFlags & LogUpdatePredFlag) {
4115 Yap_kill_iblock((
ClauseUnion *)ClauseCodeToLogUpdIndex(
4116 ap->cs.p_code.TrueCodeOfPred),
4121 cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
4124#if defined(YAPOR) || defined(THREADS)
4125 if (ap->PredFlags & LogUpdatePredFlag &&
4126 !(ap->PredFlags & ThreadLocalPredFlag) &&
4127 ap->ModuleOfPred != IDB_MODULE) {
4128 ap->OpcodeOfPred = LOCKPRED_OPCODE;
4129 ap->cs.p_code.TrueCodeOfPred = ap->CodeOfPred =
4130 (
yamop *)(&(ap->OpcodeOfPred));
4133 ap->OpcodeOfPred = INDEX_OPCODE;
4134 ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred =
4135 (
yamop *)(&(ap->OpcodeOfPred));
4136#if defined(YAPOR) || defined(THREADS)
4139 Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
4143 }
else if (cb == 4) {
4144 restore_machine_regs();
4145 Yap_ReleaseCMem(&cint);
4146 if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) {
4147 save_machine_regs();
4148 if (ap->PredFlags & LogUpdatePredFlag) {
4149 Yap_kill_iblock((
ClauseUnion *)ClauseCodeToLogUpdIndex(
4150 ap->cs.p_code.TrueCodeOfPred),
4155 cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
4163 cint.CodeStart = cint.cpc = cint.BlobsStart = cint.icpc = NIL;
4164 cint.CurrentPred = ap;
4165 LOCAL_Error_TYPE = YAP_NO_ERROR;
4166 LOCAL_Error_Size = 0;
4167 if (P->opc == Yap_opcode(_expand_clauses)) {
4170 expand_clauses = NULL;
4173 if (GLOBAL_Option[
'i' -
'a' + 1]) {
4174 Yap_DebugWriteIndicator(ap);
4177 if ((labp = expand_index(&cint)) == NULL) {
4178 if (expand_clauses) {
4180 recover_ecls_block(expand_clauses);
4182 Yap_ReleaseCMem(&cint);
4186 if (*labp == FAILCODE) {
4187 if (expand_clauses) {
4189 recover_ecls_block(expand_clauses);
4191 Yap_ReleaseCMem(&cint);
4196 if (GLOBAL_Option[
'i' -
'a' + 1]) {
4197 Yap_ShowCode(&cint);
4201 LOCAL_IPredArity = ap->ArityOfPE;
4202 if (cint.CodeStart) {
4203 if ((indx_out = Yap_assemble(ASSEMBLING_EINDEX, TermNil, ap, FALSE, &cint,
4204 cint.i_labelno + 1)) == NULL) {
4205 if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
4206 Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
4207 Yap_ReleaseCMem(&cint);
4215 if (expand_clauses) {
4217 recover_ecls_block(expand_clauses);
4219 Yap_ReleaseCMem(&cint);
4223 if (indx_out == NULL) {
4224 if (expand_clauses) {
4226 recover_ecls_block(expand_clauses);
4228 Yap_ReleaseCMem(&cint);
4232 Yap_ReleaseCMem(&cint);
4235 if (ap->PredFlags & LogUpdatePredFlag) {
4238 *nic = ClauseCodeToLogUpdIndex(indx_out);
4242 nic->SiblingIndex = ic->ChildIndex;
4243 nic->PrevSiblingIndex = NULL;
4244 if (ic->ChildIndex) {
4245 ic->ChildIndex->PrevSiblingIndex = nic;
4247 nic->ParentIndex = ic;
4248 nic->ClFlags &= ~SwitchRootMask;
4249 ic->ChildIndex = nic;
4254 *nic = ClauseCodeToStaticIndex(indx_out);
4258 nic->SiblingIndex = ic->ChildIndex;
4259 ic->ChildIndex = nic;
4261 if (expand_clauses) {
4263 recover_ecls_block(expand_clauses);
4270 return ExpandIndex(ap, nargs, CP PASS_REGS);
4277 save_machine_regs();
4278 siglongjmp(cint->CompilerBotch, 4);
4280 sp->flag = pc_entry;
4281 sp->uip.pce.pi_pc = pipc;
4282 sp->uip.pce.code = clp->Code;
4283 sp->uip.pce.current_code = clp->CurrentCode;
4284 sp->uip.pce.work_pc = clp->ucd.WorkPC;
4285 sp->uip.pce.tag = clp->Tag;
4294 save_machine_regs();
4295 siglongjmp(cint->CompilerBotch, 4);
4298 sp->flag = block_entry;
4299 sp->uip.cle.entry_code = pipc;
4300 if (ap->PredFlags & LogUpdatePredFlag) {
4301 sp->uip.cle.block = (
ClauseUnion *)ClauseCodeToLogUpdIndex(*pipc);
4303 sp->uip.cle.block = (
ClauseUnion *)ClauseCodeToStaticIndex(*pipc);
4312 sp->flag = block_entry;
4313 sp->uip.cle.entry_code = NULL;
4314 if (ap->PredFlags & LogUpdatePredFlag) {
4315 sp->uip.cle.block = (
ClauseUnion *)ClauseCodeToLogUpdIndex(ipc);
4317 sp->uip.cle.block = (
ClauseUnion *)ClauseCodeToStaticIndex(ipc);
4331 while ((--tsp)->flag != block_entry)
4333 block = tsp->uip.cle.block;
4334 if (block->lui.ClFlags & LogUpdMask)
4335 bsize = block->lui.ClSize;
4337 bsize = block->si.ClSize;
4338 if (ipc > (
yamop *)block && ipc < (
yamop *)((CODEADDR)block + bsize)) {
4340 for (; tsp < sp; tsp++) {
4341 if (tsp->flag == pc_entry) {
4343 nsp->flag = pc_entry;
4344 nsp->uip.pce.pi_pc = tsp->uip.pce.pi_pc;
4345 nsp->uip.pce.code = tsp->uip.pce.code;
4346 nsp->uip.pce.current_code = tsp->uip.pce.current_code;
4347 nsp->uip.pce.work_pc = tsp->uip.pce.work_pc;
4348 nsp->uip.pce.tag = tsp->uip.pce.tag;
4355 }
while (tsp->uip.cle.entry_code != NULL);
4357 return fetch_new_block(sp, pipc, ap, cint);
4365 while ((--sp)->flag != pc_entry)
4368 clp->Code = sp->uip.pce.code;
4369 clp->CurrentCode = sp->uip.pce.current_code;
4370 clp->ucd.WorkPC = sp->uip.pce.work_pc;
4371 clp->Tag = sp->uip.pce.tag;
4372 if (sp->uip.pce.pi_pc == NULL) {
4376 nipc = *(sp->uip.pce.pi_pc);
4377 *spp = cross_block(sp, sp->uip.pce.pi_pc, ap, cint);
4382 if (pc->y_u.sssl.s <= MIN_HASH_ENTRIES) {
4387 for (i = 0; i < pc->y_u.sssl.s; i++, csw++) {
4393 COUNT free = pc->y_u.sssl.s - pc->y_u.sssl.e;
4394 return (!free || pc->y_u.sssl.s / free > 4);
4398static int table_ae_overflow(
yamop *pc, Term at) {
4399 if (pc->y_u.sssl.s <= MIN_HASH_ENTRIES) {
4404 for (i = 0; i < pc->y_u.sssl.s; i++, csw++) {
4410 COUNT free = pc->y_u.sssl.s - pc->y_u.sssl.e;
4411 return (!free || pc->y_u.sssl.s / free > 4);
4417 if (ap->PredFlags & LogUpdatePredFlag) {
4419 *ncl = ClauseCodeToLogUpdIndex(ncod),
4420 *c = parent_block->lui.ChildIndex;
4421 ncl->SiblingIndex = cl->SiblingIndex;
4422 ncl->PrevSiblingIndex = cl->PrevSiblingIndex;
4423 ncl->ClRefCount = cl->ClRefCount;
4424 ncl->ChildIndex = cl->ChildIndex;
4425 ncl->ParentIndex = cl->ParentIndex;
4426 ncl->ClPred = cl->ClPred;
4429 parent_block->lui.ChildIndex = ncl;
4431 if (cl->PrevSiblingIndex)
4432 cl->PrevSiblingIndex->SiblingIndex = ncl;
4434 if (cl->SiblingIndex) {
4435 cl->SiblingIndex->PrevSiblingIndex = ncl;
4439 c->ParentIndex = ncl;
4440 c = c->SiblingIndex;
4442 Yap_InformOfRemoval(cl);
4443 Yap_LUIndexSpace_SW -= cl->ClSize;
4444 Yap_FreeCodeSpace((
char *)cl);
4447 *ncl = ClauseCodeToStaticIndex(ncod),
4448 *c = parent_block->si.ChildIndex;
4449 ncl->SiblingIndex = cl->SiblingIndex;
4450 ncl->ClPred = cl->ClPred;
4452 parent_block->si.ChildIndex = ncl;
4454 while (c->SiblingIndex != cl) {
4455 c = c->SiblingIndex;
4457 c->SiblingIndex = ncl;
4459 Yap_InformOfRemoval(cl);
4460 Yap_IndexSpace_SW -= cl->ClSize;
4461 Yap_FreeCodeSpace((
char *)cl);
4468 int n = pc->y_u.sssl.s, i, i0 = n;
4472 if (n > MIN_HASH_ENTRIES) {
4477 for (i = 0; i < pc->y_u.sssl.s; i++, tmp++) {
4478 if (tmp->Tag != Zero)
4481 fail_l = tmp->u_a.Label;
4484 fail_l = old_ae[n].u_a.Label;
4487 if (n > MIN_HASH_ENTRIES) {
4488 int cases = MIN_HASH_ENTRIES, i, n0;
4492 if (cases == pc->y_u.sssl.s) {
4493 return fetch_centry(old_ae, at, n - 1, n);
4498 pc->opc = Yap_opcode(_switch_on_cons);
4499 pc->y_u.sssl.s = cases;
4500 for (i = 0; i < cases; i++) {
4501 target[i].Tag = Zero;
4502 target[i].u_a.Label = fail_l;
4505 pc->opc = Yap_opcode(_if_cons);
4509 target[n].Tag = Zero;
4510 target[n].u_a.Label = fail_l;
4512 for (i = 0; i < i0; i++, old_ae++) {
4513 Term tag = old_ae->Tag;
4518 ics->u_a.Label = old_ae->u_a.Label;
4523 replace_index_block(blk, pc->y_u.sssl.l, (
yamop *)target, ap);
4524 pc->y_u.sssl.l = (
yamop *)target;
4525 return fetch_centry(target, at, n - 1, n);
4531 int n = pc->y_u.sssl.s, i, i0 = n;
4535 if (n > MIN_HASH_ENTRIES) {
4540 for (i = 0; i < pc->y_u.sssl.s; i++, tmp++) {
4541 if (tmp->Tag != Zero)
4544 fail_l = tmp->u_f.Label;
4547 fail_l = old_fe[n].u_f.Label;
4550 if (n > MIN_HASH_ENTRIES) {
4551 int cases = MIN_HASH_ENTRIES, i, n0;
4556 if (cases == pc->y_u.sssl.s) {
4557 return fetch_fentry(old_fe, f, n - 1, n);
4559 pc->opc = Yap_opcode(_switch_on_func);
4560 pc->y_u.sssl.s = cases;
4565 cint, FuncSwitchMask);
4566 for (i = 0; i < cases; i++) {
4567 target[i].Tag = NULL;
4568 target[i].u_f.Label = fail_l;
4571 pc->opc = Yap_opcode(_if_func);
4576 cint, FuncSwitchMask);
4577 target[n].Tag = Zero;
4578 target[n].u_f.Label = fail_l;
4580 for (i = 0; i < i0; i++, old_fe++) {
4585 ifs->Tag = old_fe->Tag;
4586 ifs->u_f.Label = old_fe->u_f.Label;
4589 replace_index_block(blk, pc->y_u.sssl.l, (
yamop *)target, ap);
4590 pc->y_u.sssl.l = (
yamop *)target;
4591 return fetch_fentry(target, f, n - 1, n);
4596 if ((tgl->ClFlags & ErasedMask) && !(tgl->ClRefCount) &&
4597 !(tgl->ClFlags & InUseMask)) {
4599 Yap_ErLogUpdCl(tgl);
4604 while ((--sp)->flag != block_entry)
4606 return sp->uip.cle.block;
4610 while ((--sp)->flag != block_entry)
4612 if (sp->uip.cle.entry_code == NULL) {
4613 Yap_kill_iblock(sp->uip.cle.block, NULL, ap);
4617 while ((--nsp)->flag != block_entry)
4619 Yap_kill_iblock(sp->uip.cle.block, nsp->uip.cle.block, ap);
4620 *sp->uip.cle.entry_code = (
yamop *)&(ap->cs.p_code.ExpandCode);
4626 while (start->y_u.OtaLl.d->ClFlags & ErasedMask)
4627 start = start->y_u.OtaLl.n;
4629 return start->y_u.OtaLl.d;
4633 yamop **prevp = &(header->y_u.Illss.l1);
4634 yamop *curp = header->y_u.Illss.l1;
4636 if (curp->y_u.OtaLl.d == cl) {
4637 yamop *newp = curp->y_u.OtaLl.n;
4638 newp->opc = curp->opc;
4641 yamop *ocurp = NULL, *ocurp0 = curp;
4643 while (curp->y_u.OtaLl.d != cl) {
4645 curp = curp->y_u.OtaLl.n;
4648 if (curp == header->y_u.Illss.l2)
4649 header->y_u.Illss.l2 = ocurp;
4650 if (ocurp != ocurp0)
4651 ocurp->opc = curp->opc;
4652 ocurp->y_u.OtILl.n = curp->y_u.OtaLl.n;
4653 ocurp->y_u.OtILl.block = curp->y_u.OtILl.block;
4655 header->y_u.Illss.e--;
4660 clean_ref_to_clause(cl);
4661 Yap_LUIndexSpace_CP -= (UInt)NEXTOP((
yamop *)NULL, OtILl);
4662 Yap_FreeCodeSpace((ADDR)curp);
4665static void remove_dirty_clauses_from_index(
yamop *header) {
4667 yamop *previouscurp;
4668 OPCODE endop = Yap_opcode(_trust_logical);
4669 yamop **prevp = &(header->y_u.Illss.l1), *curp = header->y_u.Illss.l1;
4670 OPCODE startopc = curp->opc;
4671 PredEntry *ap = curp->y_u.OtaLl.d->ClPred;
4673 if (ap->PredFlags & CountPredFlag)
4674 endop = Yap_opcode(_count_trust_logical);
4675 else if (ap->PredFlags & ProfiledPredFlag)
4676 endop = Yap_opcode(_profiled_trust_logical);
4677 while ((cl = curp->y_u.OtaLl.d) && (cl->ClFlags & ErasedMask)) {
4678 yamop *ocurp = curp;
4680 header->y_u.Illss.e--;
4690 clean_ref_to_clause(cl);
4691 curp = curp->y_u.OtaLl.n;
4692 Yap_LUIndexSpace_CP -= (UInt)NEXTOP((
yamop *)NULL, OtaLl);
4693 Yap_FreeCodeSpace((ADDR)ocurp);
4694 if (ocurp == header->y_u.Illss.l2) {
4697 if (clau->ClFlags & ErasedMask) {
4698 Yap_ErLogUpdIndex(clau);
4701 header->y_u.Illss.l1 = header->y_u.Illss.l2 = NULL;
4702 header->y_u.Illss.s = header->y_u.Illss.e = 0;
4707 curp->opc = startopc;
4708 if (curp->opc == endop)
4711 if (header->y_u.Illss.e <= 1)
4713 previouscurp = curp;
4714 curp = curp->y_u.OtaLl.n;
4716 if ((cl = curp->y_u.OtaLl.d)->ClFlags & ErasedMask) {
4717 yamop *ocurp = curp;
4719 header->y_u.Illss.e--;
4724 clean_ref_to_clause(cl);
4725 if (curp->opc == endop) {
4726 previouscurp->opc = endop;
4727 previouscurp->y_u.OtILl.block = curp->y_u.OtILl.block;
4728 previouscurp->y_u.OtILl.n = NULL;
4729 header->y_u.Illss.l2 = previouscurp;
4730 Yap_LUIndexSpace_CP -= (UInt)NEXTOP((
yamop *)NULL, OtILl);
4731 Yap_FreeCodeSpace((ADDR)curp);
4734 previouscurp->y_u.OtaLl.n = curp->y_u.OtaLl.n;
4735 curp = curp->y_u.OtaLl.n;
4736 Yap_LUIndexSpace_CP -= (UInt)NEXTOP((
yamop *)NULL, OtaLl);
4737 Yap_FreeCodeSpace((ADDR)ocurp);
4738 if (!header->y_u.Illss.e)
4741 previouscurp = curp;
4742 if (curp->opc == endop) {
4743 curp->y_u.OtILl.n = NULL;
4746 curp = curp->y_u.OtaLl.n;
4758 while ((--sp)->flag != block_entry)
4761 start = blk->ClCode;
4762 op0 = Yap_op_from_opcode(start->opc);
4763 while (op0 == _lock_lu) {
4764 start = NEXTOP(start, p);
4765 op0 = Yap_op_from_opcode(start->opc);
4767 while (op0 == _jump_if_nonvar) {
4768 start = NEXTOP(start, xll);
4769 op0 = Yap_op_from_opcode(start->opc);
4771 if (op0 != _enter_lu_pred) {
4773 return kill_block(sp + 1, ap);
4776 if (!start->y_u.Illss.s) {
4778 Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"Illss.s == 0 %p", ipc);
4781 if (start->y_u.Illss.s == 1) {
4784 find_last_clause(start->y_u.Illss.l1);
4787 while ((--nsp)->flag != block_entry)
4790 *sp->uip.cle.entry_code = FAILCODE;
4791 Yap_kill_iblock(sp->uip.cle.block, nsp->uip.cle.block, ap);
4796 blk->ClRefCount == 0
4798 !(blk->ClFlags & InUseMask)
4801 remove_clause_from_index(start, ClauseCodeToLogUpdClause(bg));
4803 blk->ClFlags |= DirtyMask;
4812 while ((--sp)->flag != block_entry)
4814 Yap_kill_iblock(sp->uip.cle.block, NULL, ap);
4821 while ((--sp)->flag != block_entry)
4823 Yap_kill_iblock(sp->uip.cle.block, NULL, ap);
4828 if (ipc == FAILCODE)
4830 if (ipc == (
yamop *)(&(ap->OpcodeOfPred)))
4832 return ClauseCodeToLogUpdClause(ipc);
4836 StaticClause *cl = ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
4837 while (ipc < cl->ClCode || ipc > (
yamop *)((
char *)cl + cl->ClSize)) {
4848 if (ipc == FAILCODE)
4850 if (ipc == (
yamop *)(&(ap->OpcodeOfPred)))
4852 if (ap->PredFlags & MegaClausePredFlag)
4854 if (ap->PredFlags & TabledPredFlag)
4855 ipc = PREVOP(ipc, Otapl);
4858 return ClauseCodeToStaticClause(p);
4860 op_numbers op = Yap_op_from_opcode(ipc->opc);
4867 j = Yap_regnotoreg(ipc->y_u.xl.x);
4870 j = Yap_regnotoreg(ipc->y_u.x.x);
4873 j = Yap_regnotoreg(ipc->y_u.xc.x);
4876 j = Yap_regnotoreg(ipc->y_u.xd.x);
4879 j = Yap_regnotoreg(ipc->y_u.xd.x);
4886 return ClauseCodeToStaticClause(p);
4888 return find_static_clause(ap, ipc);
4891 return ClauseCodeToStaticClause(p);
4892 return find_static_clause(ap, ipc);
4898 if (ipc == (
yamop *)(&(ap->OpcodeOfPred)))
4900 if (ipc == FAILCODE)
4902 return ClauseCodeToStaticClause(ipc);
4910 while ((--sp)->flag != block_entry)
4912 if (sp->uip.cle.entry_code == NULL) {
4914 Yap_RemoveIndexation(ap);
4917 ipc = *sp->uip.cle.entry_code;
4918 if (Yap_op_from_opcode(ipc->opc) == op) {
4923 *sp->uip.cle.entry_code = FAILCODE;
4926 if (ap->PredFlags & LogUpdatePredFlag) {
4931 cld[0].Code = cls[0].Code;
4932 cld[1].Code = lc->ClCode;
4934 cld[0].Code = lc->ClCode;
4935 cld[1].Code = cls[0].Code;
4937 intrs.expand_block = NULL;
4938 *sp->uip.cle.entry_code =
4939 (
yamop *)suspend_indexing(cld, cld + 1, ap, &intrs);
4942 *sp->uip.cle.entry_code = (
yamop *)&(ap->cs.p_code.ExpandCode);
4948 return kill_block(sp + 1, ap);
4951static int compacta_expand_clauses(
yamop *ipc) {
4954 yamop **start = (
yamop **)(NEXTOP(ipc, sssllp));
4957 ptr = end = start + ipc->y_u.sssllp.s1;
4959 while (ptr > start) {
4960 yamop *next = *--ptr;
4965 while (end > start) {
4973static int compactz_expand_clauses(
yamop *ipc) {
4976 yamop **start = (
yamop **)(NEXTOP(ipc, sssllp));
4979 end = start + ipc->y_u.sssllp.s1;
4983 yamop *next = *ptr++;
4989 while (start < end) {
5007 clar = (
yamop **)NEXTOP(ipc, sssllp);
5009 if (*clar == NULL || clar[0] == cls->Code) {
5010 while (*clar == NULL)
5012 if (clar[0] != cls->Code) {
5013 clar[-1] = cls->Code;
5014 ipc->y_u.sssllp.s2++;
5016 return pop_path(spp, cls, ap, cint);
5018 }
while (compacta_expand_clauses(ipc));
5021 clar = (
yamop **)NEXTOP(ipc, sssllp) + ipc->y_u.sssllp.s1;
5022 if (clar[-1] == NULL || clar[-1] == cls->Code) {
5023 while (*--clar == NULL)
5025 if (clar[0] != cls->Code) {
5026 clar[1] = cls->Code;
5027 ipc->y_u.sssllp.s2++;
5029 return pop_path(spp, cls, ap, cint);
5031 }
while (compactz_expand_clauses(ipc));
5033 while ((--sp)->flag != block_entry)
5035 if (sp->uip.cle.entry_code) {
5036 *sp->uip.cle.entry_code = (
yamop *)&(ap->cs.p_code.ExpandCode);
5038 recover_ecls_block(ipc);
5039 return pop_path(spp, cls, ap, cint);
5046 yamop **max = st + ipc->y_u.sssllp.s1;
5050 if (*st && *st == cls->Code) {
5052 ipc->y_u.sssllp.s2--;
5058 if (ipc->y_u.sssllp.s2 == 1) {
5060 while ((--sp)->flag != block_entry)
5063 if (*st && *st != cls->Code) {
5064 *sp->uip.cle.entry_code = *st;
5065 recover_ecls_block(ipc);
5076 UInt size = (UInt)NEXTOP((
yamop *)NULL, OtaLl);
5077 LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code);
5079 if ((newcp = (
yamop *)Yap_AllocCodeSpace(size)) == NULL) {
5081 save_machine_regs();
5082 siglongjmp(cint->CompilerBotch, 2);
5084 Yap_LUIndexSpace_CP += size;
5089 newcp->opc = Yap_opcode(_try_logical);
5090 newcp->y_u.OtaLl.s = ap->ArityOfPE;
5091 newcp->y_u.OtaLl.n = next;
5092 newcp->y_u.OtaLl.d = lcl;
5100 UInt size = (UInt)NEXTOP((
yamop *)NULL, OtILl);
5101 LogUpdClause *lcl = ClauseCodeToLogUpdClause(cls->Code);
5104 if ((newcp = (
yamop *)Yap_AllocCodeSpace(size)) == NULL) {
5106 save_machine_regs();
5107 siglongjmp(cint->CompilerBotch, 2);
5109 Yap_LUIndexSpace_CP += size;
5114 if (ap->PredFlags & CountPredFlag)
5115 newcp->opc = Yap_opcode(_count_trust_logical);
5116 else if (ap->PredFlags & ProfiledPredFlag)
5117 newcp->opc = Yap_opcode(_profiled_trust_logical);
5119 newcp->opc = Yap_opcode(_trust_logical);
5120 newcp->y_u.OtILl.block = icl;
5121 newcp->y_u.OtILl.n = NULL;
5122 newcp->y_u.OtILl.d = lcl;
5127static void add_to_index(
struct intermediates *cint,
int first,
5131 yamop *ipc = ap->cs.p_code.TrueCodeOfPred;
5134 UInt current_arity = 0;
5137 sp = init_block_stack(sp, ipc, ap);
5139 while (ipc != NULL) {
5140 op_numbers op = Yap_op_from_opcode(ipc->opc);
5144 case _retry_logical:
5145 case _count_retry_logical:
5146 case _profiled_retry_logical:
5147 case _trust_logical:
5148 case _count_trust_logical:
5149 case _profiled_trust_logical:
5152 case _enter_lu_pred:
5154 icl = ipc->y_u.Illss.I;
5156 if (ap->PredFlags & CountPredFlag)
5157 ipc->y_u.Illss.l1->opc = Yap_opcode(_count_retry_logical);
5158 else if (ap->PredFlags & ProfiledPredFlag)
5159 ipc->y_u.Illss.l1->opc = Yap_opcode(_profiled_retry_logical);
5161 ipc->y_u.Illss.l1->opc = Yap_opcode(_retry_logical);
5162 ipc->y_u.Illss.l1 = add_try(ap, cls, ipc->y_u.Illss.l1, cint);
5165 yamop *end = add_trust(icl, cls, cint), *old = ipc->y_u.Illss.l2;
5168 if (ap->PredFlags & CountPredFlag)
5169 old->opc = Yap_opcode(_count_retry_logical);
5170 else if (ap->PredFlags & ProfiledPredFlag)
5171 old->opc = Yap_opcode(_profiled_retry_logical);
5173 old->opc = Yap_opcode(_retry_logical);
5174 old->y_u.OtaLl.n = end;
5175 old->y_u.OtaLl.s = ap->ArityOfPE;
5176 ipc->y_u.Illss.l2 = end;
5178 ipc = pop_path(&sp, cls, ap, cint);
5185 sp = expanda_block(sp, ap, cls, group1, alt, cint);
5186 ipc = pop_path(&sp, cls, ap, cint);
5189 ipc = NEXTOP(ipc, Otapl);
5199 sp = expanda_block(sp, ap, cls, group1, alt, cint);
5200 ipc = pop_path(&sp, cls, ap, cint);
5203 ipc = NEXTOP(ipc, l);
5208 ipc = NEXTOP(ipc, Otapl);
5214 ipc = NEXTOP(ipc, l);
5220 ipc = ipc->y_u.Otapl.d;
5224 ipc = NEXTOP(ipc, Otapl);
5225 alt = ipc->y_u.Otapl.d;
5227 ipc = ipc->y_u.Otapl.d;
5231 case _retry_profiled:
5233 ipc = NEXTOP(ipc, Otapl);
5235 case _profiled_trust_me:
5237 case _count_trust_me:
5239 ipc = NEXTOP(ipc, Otapl);
5242 sp = expandz_block(sp, ap, cls, group1, alt, cint);
5243 ipc = pop_path(&sp, cls, ap, cint);
5246 sp = cross_block(sp, &ipc->y_u.l.l, ap, cint);
5251 sp = push_path(sp, &(ipc->y_u.l.l), cls, cint);
5252 ipc = NEXTOP(ipc, l);
5254 case _jump_if_nonvar:
5255 sp = push_path(sp, &(ipc->y_u.xll.l2), cls, cint);
5256 sp = cross_block(sp, &ipc->y_u.xll.l1, ap, cint);
5257 ipc = ipc->y_u.xll.l1;
5263 sp = kill_block(sp, ap);
5264 ipc = pop_path(&sp, cls, ap, cint);
5266 ipc = NEXTOP(ipc, l);
5270 ipc = ipc->y_u.lp.l;
5273 case _switch_on_type:
5274 sp = push_path(sp, &(ipc->y_u.llll.l4), cls, cint);
5275 if (ap->PredFlags & LogUpdatePredFlag) {
5276 add_head_info(cls, 1);
5280 if (IsPairTerm(cls->Tag)) {
5281 yamop *nipc = ipc->y_u.llll.l1;
5285 if (nipc == FAILCODE) {
5287 if (ap->PredFlags & LogUpdatePredFlag) {
5288 ipc->y_u.llll.l1 = cls->Code;
5290 ipc->y_u.llll.l1 = cls->CurrentCode;
5292 ipc = pop_path(&sp, cls, ap, cint);
5295 sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint);
5298 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5299 yamop *nipc = ipc->y_u.llll.l2;
5301 if (nipc == FAILCODE) {
5303 sp = kill_block(sp, ap);
5304 ipc = pop_path(&sp, cls, ap, cint);
5309 }
else if (IsApplTerm(cls->Tag)) {
5310 yamop *nipc = ipc->y_u.llll.l3;
5311 if (nipc == FAILCODE) {
5313 sp = kill_block(sp, ap);
5314 ipc = pop_path(&sp, cls, ap, cint);
5323 sp = kill_block(sp, ap);
5324 ipc = pop_path(&sp, cls, ap, cint);
5327 case _switch_list_nl:
5328 sp = kill_block(sp, ap);
5329 ipc = pop_path(&sp, cls, ap, cint);
5331 case _switch_on_arg_type:
5332 sp = push_path(sp, &(ipc->y_u.xllll.l4), cls, cint);
5333 if (ap->PredFlags & LogUpdatePredFlag) {
5334 add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5336 add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5338 if (IsPairTerm(cls->Tag)) {
5339 yamop *nipc = ipc->y_u.xllll.l1;
5342 move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5343 if (nipc == FAILCODE) {
5345 if (ap->PredFlags & LogUpdatePredFlag) {
5346 ipc->y_u.xllll.l1 = cls->Code;
5348 ipc->y_u.xllll.l1 = cls->CurrentCode;
5350 ipc = pop_path(&sp, cls, ap, cint);
5353 sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint);
5356 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5357 yamop *nipc = ipc->y_u.xllll.l2;
5358 move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5359 if (nipc == FAILCODE) {
5361 sp = kill_block(sp, ap);
5362 ipc = pop_path(&sp, cls, ap, cint);
5367 }
else if (IsApplTerm(cls->Tag)) {
5368 yamop *nipc = ipc->y_u.xllll.l3;
5369 move_next(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5370 if (nipc == FAILCODE) {
5372 sp = kill_block(sp, ap);
5373 ipc = pop_path(&sp, cls, ap, cint);
5382 sp = kill_block(sp, ap);
5383 ipc = pop_path(&sp, cls, ap, cint);
5386 case _switch_on_sub_arg_type:
5387 sp = push_path(sp, &(ipc->y_u.sllll.l4), cls, cint);
5388 add_arg_info(cls, ap, ipc->y_u.sllll.s + 1);
5389 if (IsPairTerm(cls->Tag)) {
5390 yamop *nipc = ipc->y_u.sllll.l1;
5392 skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity);
5393 if (nipc == FAILCODE) {
5395 if (ap->PredFlags & LogUpdatePredFlag) {
5396 ipc->y_u.sllll.l1 = cls->Code;
5398 ipc->y_u.sllll.l1 = cls->CurrentCode;
5400 ipc = pop_path(&sp, cls, ap, cint);
5403 sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint);
5406 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5407 yamop *nipc = ipc->y_u.sllll.l2;
5408 skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity);
5409 if (nipc == FAILCODE) {
5411 sp = kill_block(sp, ap);
5412 ipc = pop_path(&sp, cls, ap, cint);
5417 }
else if (IsApplTerm(cls->Tag)) {
5418 yamop *nipc = ipc->y_u.sllll.l3;
5419 skip_to_arg(cls, ap, ipc->y_u.sllll.s, current_arity);
5420 if (nipc == FAILCODE) {
5422 sp = kill_block(sp, ap);
5423 ipc = pop_path(&sp, cls, ap, cint);
5432 sp = kill_block(sp, ap);
5433 ipc = pop_path(&sp, cls, ap, cint);
5437 ipc = pop_path(&sp, cls, ap, cint);
5440 case _switch_on_func:
5447 if (op == _switch_on_func) {
5448 fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5450 fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5452 if (!IsExtensionFunctor(f)) {
5453 current_arity = ArityOfFunctor(f);
5455 newpc = fe->u_f.labp;
5456 if (newpc == (
yamop *)&(ap->cs.p_code.ExpandCode)) {
5458 ipc = pop_path(&sp, cls, ap, cint);
5459 }
else if (newpc == FAILCODE) {
5462 if (IsExtensionFunctor(f)) {
5463 sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls);
5464 ipc = pop_path(&sp, cls, ap, cint);
5467 if (table_fe_overflow(ipc, f)) {
5468 fe = expand_ftable(ipc, current_block(sp), cint, f);
5473 if (ap->PredFlags & LogUpdatePredFlag) {
5474 fe->u_f.labp = cls->Code;
5476 fe->u_f.labp = cls->CurrentCode;
5478 ipc = pop_path(&sp, cls, ap, cint);
5480 yamop *newpc = fe->u_f.labp;
5481 sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint);
5482 sp = cross_block(sp, &(fe->u_f.labp), ap, cint);
5487 cls->Tag = cls->ucd.t_ptr;
5488 ipc = NEXTOP(ipc, e);
5491 cls->Tag = Yap_Double_key(cls->ucd.t_ptr);
5492 ipc = NEXTOP(ipc, e);
5495 cls->Tag = Yap_Int_key(cls->ucd.t_ptr);
5496 ipc = NEXTOP(ipc, e);
5498 case _switch_on_cons:
5505 if (op == _switch_on_cons) {
5506 ae = lookup_c_hash(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5508 ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5510 newpc = ae->u_a.labp;
5512 if (newpc == (
yamop *)&(ap->cs.p_code.ExpandCode)) {
5514 ipc = pop_path(&sp, cls, ap, cint);
5515 }
else if (newpc == FAILCODE) {
5517 if (ae->Tag != at) {
5518 if (table_ae_overflow(ipc, at)) {
5519 ae = expand_ctable(ipc, current_block(sp), cint, at);
5524 if (ap->PredFlags & LogUpdatePredFlag) {
5525 ae->u_a.labp = cls->Code;
5527 ae->u_a.labp = cls->CurrentCode;
5529 ipc = pop_path(&sp, cls, ap, cint);
5531 yamop *newpc = ae->u_a.labp;
5533 sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint);
5534 sp = cross_block(sp, &(ae->u_a.labp), ap, cint);
5538 case _expand_clauses:
5539 ipc = add_to_expand_clauses(&sp, ipc, cls, ap, first, cint);
5542 ipc = pop_path(&sp, cls, ap, cint);
5545 ipc = NEXTOP(ipc, p);
5548 while ((--sp)->flag != block_entry)
5550 *sp->uip.cle.entry_code = cls->Code;
5551 ipc = pop_path(&sp, cls, ap, cint);
5554 sp = kill_unsafe_block(sp, op, ap, first, FALSE, cls);
5555 ipc = pop_path(&sp, cls, ap, cint);
5568 if (!(ap->PredFlags & LogUpdatePredFlag)) {
5569 if (ap->PredFlags & IndexedPredFlag)
5570 Yap_RemoveIndexation(ap);
5573 cint.CurrentPred = ap;
5574 cint.expand_block = NULL;
5575 cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NIL;
5576 cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L;
5577 if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
5578 restore_machine_regs();
5579 Yap_dogc(PASS_REGS1);
5580 save_machine_regs();
5581 }
else if (cb == 2) {
5582 restore_machine_regs();
5583 Yap_growheap(FALSE, LOCAL_Error_Size, NULL);
5584 save_machine_regs();
5585 }
else if (cb == 4) {
5586 restore_machine_regs();
5587 Yap_growtrail(LOCAL_Error_Size, FALSE);
5588 save_machine_regs();
5591 Yap_RemoveIndexation(ap);
5594 LOCAL_Error_TYPE = YAP_NO_ERROR;
5596 if (GLOBAL_Option[
'i' -
'a' + 1]) {
5597 Yap_DebugPutc(stderr,
'+');
5598 Yap_DebugWriteIndicator(ap);
5602 cl.Code = cl.CurrentCode = beg;
5603 sp = push_path(stack, NULL, &cl, &cint);
5604 add_to_index(&cint, first, sp, &cl);
5609 int n = ipc->y_u.sssl.s;
5612 if (n > MIN_HASH_ENTRIES) {
5613 fep = lookup_f_hash(f, ipc->y_u.sssl.l, n);
5616 while (fep->Tag != f)
5619 fep->u_f.labp = FAILCODE;
5624 int n = ipc->y_u.sssl.s;
5627 if (n > MIN_HASH_ENTRIES) {
5628 cep = lookup_c_hash(at, ipc->y_u.sssl.l, n);
5631 while (cep->Tag != at)
5634 cep->u_a.labp = FAILCODE;
5641 yamop *ipc = ap->cs.p_code.TrueCodeOfPred;
5643 if (ap->cs.p_code.NOfClauses == 1) {
5644 if (ap->PredFlags & IndexedPredFlag) {
5645 Yap_RemoveIndexation(ap);
5648 ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause;
5649 if (ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
5650 ap->OpcodeOfPred = Yap_opcode(_spy_pred);
5651 ap->CodeOfPred = (
yamop *)(&(ap->OpcodeOfPred));
5652#if defined(YAPOR) || defined(THREADS)
5653 }
else if (ap->PredFlags & LogUpdatePredFlag &&
5654 !(ap->PredFlags & ThreadLocalPredFlag) &&
5655 ap->ModuleOfPred != IDB_MODULE) {
5656 ap->cs.p_code.TrueCodeOfPred = FAILCODE;
5657 ap->OpcodeOfPred = LOCKPRED_OPCODE;
5658 ap->CodeOfPred = (
yamop *)(&(ap->OpcodeOfPred));
5661 ap->OpcodeOfPred = ap->cs.p_code.FirstClause->opc;
5662 ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred;
5666 sp = init_block_stack(sp, ipc, ap);
5668 while (ipc != NULL) {
5669 op_numbers op = Yap_op_from_opcode(ipc->opc);
5672 case _retry_profiled:
5674 ipc = NEXTOP(ipc, p);
5680 if (IN_BETWEEN(bg, ipc->y_u.l.l, lt)) {
5681 sp = kill_clause(ipc, bg, lt, sp, ap);
5682 ipc = pop_path(&sp, cls, ap, cint);
5685 ipc = NEXTOP(ipc, l);
5693 if (IN_BETWEEN(bg, ipc->y_u.Otapl.d, lt)) {
5694 sp = kill_clause(ipc, bg, lt, sp, ap);
5695 ipc = pop_path(&sp, cls, ap, cint);
5698 ipc = NEXTOP(ipc, Otapl);
5710 if (IN_BETWEEN(bg, ipc->y_u.l.l, lt)) {
5711 sp = kill_clause(ipc, bg, lt, sp, ap);
5712 ipc = pop_path(&sp, cls, ap, cint);
5715 ipc = NEXTOP(ipc, l);
5719 if (IN_BETWEEN(bg, ipc->y_u.Otapl.d, lt)) {
5720 sp = kill_clause(ipc, bg, lt, sp, ap);
5722 ipc = pop_path(&sp, cls, ap, cint);
5724 case _enter_lu_pred:
5731 sp = kill_clause(ipc, bg, lt, sp, ap);
5732 ipc = pop_path(&sp, cls, ap, cint);
5737 sp = push_path(sp, &(ipc->y_u.Otapl.d), cls, cint);
5738 ipc = NEXTOP(ipc, Otapl);
5740 case _profiled_trust_me:
5742 case _count_trust_me:
5743 ipc = NEXTOP(ipc, Otapl);
5746 sp = cross_block(sp, &ipc->y_u.l.l, ap, cint);
5751 sp = push_path(sp, &(ipc->y_u.l.l), cls, cint);
5752 ipc = NEXTOP(ipc, l);
5754 case _jump_if_nonvar:
5755 sp = push_path(sp, &(ipc->y_u.xll.l2), cls, cint);
5756 sp = cross_block(sp, &ipc->y_u.xll.l1, ap, cint);
5757 ipc = ipc->y_u.xll.l1;
5760 ipc = ipc->y_u.lp.l;
5763 case _switch_on_type:
5764 sp = push_path(sp, &(ipc->y_u.llll.l4), cls, cint);
5765 if (ap->PredFlags & LogUpdatePredFlag) {
5766 add_head_info(cls, 1);
5770 if (IsPairTerm(cls->Tag)) {
5771 yamop *nipc = ipc->y_u.llll.l1;
5772 if (IN_BETWEEN(bg, nipc, lt)) {
5774 ipc->y_u.llll.l1 = FAILCODE;
5775 ipc = pop_path(&sp, cls, ap, cint);
5778 sp = cross_block(sp, &ipc->y_u.llll.l1, ap, cint);
5781 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5782 yamop *nipc = ipc->y_u.llll.l2;
5783 if (IN_BETWEEN(bg, nipc, lt)) {
5785 ipc->y_u.llll.l2 = FAILCODE;
5786 ipc = pop_path(&sp, cls, ap, cint);
5791 }
else if (IsApplTerm(cls->Tag)) {
5792 yamop *nipc = ipc->y_u.llll.l3;
5793 if (IN_BETWEEN(bg, nipc, lt)) {
5795 ipc->y_u.llll.l3 = FAILCODE;
5796 ipc = pop_path(&sp, cls, ap, cint);
5805 sp = kill_block(sp, ap);
5806 ipc = pop_path(&sp, cls, ap, cint);
5809 case _switch_list_nl:
5810 sp = kill_block(sp, ap);
5811 ipc = pop_path(&sp, cls, ap, cint);
5813 case _switch_on_arg_type:
5814 sp = push_path(sp, &(ipc->y_u.xllll.l4), cls, cint);
5815 if (ap->PredFlags & LogUpdatePredFlag) {
5816 add_head_info(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5818 add_info(cls, Yap_regtoregno(ipc->y_u.xllll.x));
5820 if (IsPairTerm(cls->Tag)) {
5821 yamop *nipc = ipc->y_u.xllll.l1;
5822 if (IN_BETWEEN(bg, nipc, lt)) {
5824 ipc->y_u.xllll.l1 = FAILCODE;
5825 ipc = pop_path(&sp, cls, ap, cint);
5828 sp = cross_block(sp, &ipc->y_u.xllll.l1, ap, cint);
5831 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5832 yamop *nipc = ipc->y_u.xllll.l2;
5833 if (IN_BETWEEN(bg, nipc, lt)) {
5835 ipc->y_u.xllll.l2 = FAILCODE;
5836 ipc = pop_path(&sp, cls, ap, cint);
5841 }
else if (IsApplTerm(cls->Tag)) {
5842 yamop *nipc = ipc->y_u.xllll.l3;
5843 if (IN_BETWEEN(bg, nipc, lt)) {
5845 ipc->y_u.xllll.l3 = FAILCODE;
5846 ipc = pop_path(&sp, cls, ap, cint);
5855 sp = kill_block(sp, ap);
5856 ipc = pop_path(&sp, cls, ap, cint);
5859 case _switch_on_sub_arg_type:
5860 sp = push_path(sp, &(ipc->y_u.sllll.l4), cls, cint);
5861 add_arg_info(cls, ap, ipc->y_u.sllll.s + 1);
5862 if (IsPairTerm(cls->Tag)) {
5863 yamop *nipc = ipc->y_u.sllll.l1;
5864 if (IN_BETWEEN(bg, nipc, lt)) {
5866 ipc->y_u.sllll.l1 = FAILCODE;
5867 ipc = pop_path(&sp, cls, ap, cint);
5870 sp = cross_block(sp, &ipc->y_u.sllll.l1, ap, cint);
5873 }
else if (IsAtomOrIntTerm(cls->Tag)) {
5874 yamop *nipc = ipc->y_u.sllll.l2;
5875 if (IN_BETWEEN(bg, nipc, lt)) {
5877 ipc->y_u.sllll.l2 = FAILCODE;
5878 ipc = pop_path(&sp, cls, ap, cint);
5883 }
else if (IsApplTerm(cls->Tag)) {
5884 yamop *nipc = ipc->y_u.sllll.l3;
5885 if (IN_BETWEEN(bg, nipc, lt)) {
5887 ipc->y_u.sllll.l3 = FAILCODE;
5888 ipc = pop_path(&sp, cls, ap, cint);
5897 sp = kill_block(sp, ap);
5898 ipc = pop_path(&sp, cls, ap, cint);
5902 ipc = pop_path(&sp, cls, ap, cint);
5905 case _switch_on_func:
5912 if (op == _switch_on_func) {
5913 fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5915 fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5917 newpc = fe->u_f.labp;
5919 if (newpc == (
yamop *)&(ap->cs.p_code.ExpandCode)) {
5921 ipc = pop_path(&sp, cls, ap, cint);
5922 }
else if (newpc == FAILCODE) {
5923 ipc = pop_path(&sp, cls, ap, cint);
5924 }
else if (IN_BETWEEN(bg, fe->u_f.Label, lt)) {
5926 contract_ftable(ipc, current_block(sp), ap, f);
5927 ipc = pop_path(&sp, cls, ap, cint);
5929 yamop *newpc = fe->u_f.labp;
5930 sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint);
5931 sp = cross_block(sp, &(fe->u_f.labp), ap, cint);
5936 cls->Tag = cls->ucd.t_ptr;
5937 ipc = NEXTOP(ipc, e);
5940 cls->Tag = Yap_Double_key(cls->ucd.t_ptr);
5941 ipc = NEXTOP(ipc, e);
5944 cls->Tag = Yap_Int_key(cls->ucd.t_ptr);
5945 ipc = NEXTOP(ipc, e);
5947 case _switch_on_cons:
5954 if (op == _switch_on_cons) {
5955 ae = lookup_c_hash(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5957 ae = lookup_c(at, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
5959 newpc = ae->u_a.labp;
5961 if (newpc == (
yamop *)&(ap->cs.p_code.ExpandCode)) {
5963 ipc = pop_path(&sp, cls, ap, cint);
5964 }
else if (newpc == FAILCODE) {
5965 ipc = pop_path(&sp, cls, ap, cint);
5966 }
else if (IN_BETWEEN(bg, ae->u_a.Label, lt)) {
5968 contract_ctable(ipc, current_block(sp), ap, at);
5969 ipc = pop_path(&sp, cls, ap, cint);
5971 yamop *newpc = ae->u_a.labp;
5973 sp = fetch_new_block(sp, &(ipc->y_u.sssl.l), ap, cint);
5974 sp = cross_block(sp, &(ae->u_a.labp), ap, cint);
5979 ipc = pop_path(&sp, cls, ap, cint);
5981 case _expand_clauses:
5982 nullify_expand_clause(ipc, sp, cls);
5983 ipc = pop_path(&sp, cls, ap, cint);
5986 ipc = NEXTOP(ipc, p);
5989 if (IN_BETWEEN(bg, ipc, lt)) {
5990 sp = kill_unsafe_block(sp, op, ap, TRUE, TRUE, cls);
5992 ipc = pop_path(&sp, cls, ap, cint);
6007 if (ap->PredFlags & MegaClausePredFlag) {
6010 cint.expand_block = NULL;
6011 cint.CodeStart = cint.BlobsStart = cint.cpc = cint.icpc = NULL;
6012 if ((cb = sigsetjmp(cint.CompilerBotch, 0)) == 3) {
6013 restore_machine_regs();
6014 Yap_dogc(PASS_REGS1);
6015 save_machine_regs();
6016 }
else if (cb == 2) {
6017 restore_machine_regs();
6018 Yap_growheap(FALSE, LOCAL_Error_Size, NULL);
6019 save_machine_regs();
6020 }
else if (cb == 4) {
6021 restore_machine_regs();
6022 Yap_growtrail(LOCAL_Error_Size, FALSE);
6023 save_machine_regs();
6025 LOCAL_Error_TYPE = YAP_NO_ERROR;
6026 cint.term_depth = cint.last_index_new_depth = cint.last_depth_size = 0L;
6027 if (cb || (ap->cs.p_code.NOfClauses == 2 &&
6028 ap->PredFlags & IndexedPredFlag)) {
6030 if (ap->PredFlags & LogUpdatePredFlag) {
6032 (
ClauseUnion *)ClauseCodeToLogUpdIndex(ap->cs.p_code.TrueCodeOfPred),
6036 ap->PredFlags &= ~LogUpdatePredFlag;
6037 cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred);
6040 ap->PredFlags &= ~IndexedPredFlag;
6044 if (GLOBAL_Option[
'i' -
'a' + 1]) {
6045 Term tmod = ap->ModuleOfPred;
6049 Yap_DebugPutc(stderr,
'-');
6050 Yap_DebugPutc(stderr,
'\t');
6051 Yap_DebugPlWrite(tmod);
6052 Yap_DebugPutc(stderr,
':');
6053 if (ap->ModuleOfPred != IDB_MODULE) {
6054 if (ap->ArityOfPE == 0) {
6056 Yap_DebugPlWrite(MkAtomTerm(At));
6058 Functor f = ap->FunctorOfPred;
6059 Atom At = NameOfFunctor(f);
6060 Yap_DebugPlWrite(MkAtomTerm(At));
6061 Yap_DebugPutc(stderr,
'/');
6062 Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f)));
6065 if (ap->PredFlags & NumberDBPredFlag) {
6066 Int
id = ap->src.IndxId;
6067 Yap_DebugPlWrite(MkIntegerTerm(
id));
6068 }
else if (ap->PredFlags & AtomDBPredFlag) {
6070 Yap_DebugPlWrite(MkAtomTerm(At));
6072 Functor f = ap->FunctorOfPred;
6073 Atom At = NameOfFunctor(f);
6074 Yap_DebugPlWrite(MkAtomTerm(At));
6075 Yap_DebugPutc(stderr,
'/');
6076 Yap_DebugPlWrite(MkIntegerTerm(ArityOfFunctor(f)));
6079 Yap_DebugPutc(stderr,
'\n');
6083 if (ap->PredFlags & LogUpdatePredFlag) {
6085 cl.Code = cl.CurrentCode = beg;
6086 last = (
yamop *)((CODEADDR)c + c->ClSize);
6089 cl.Code = cl.CurrentCode = beg;
6090 last = (
yamop *)((CODEADDR)c + c->ClSize);
6092 sp = push_path(stack, NULL, &cl, &cint);
6093 if (ap->cs.p_code.NOfClauses == 0) {
6095#if defined(YAPOR) || defined(THREADS)
6096 if (ap->PredFlags & LogUpdatePredFlag && ap->ModuleOfPred != IDB_MODULE) {
6097 ap->cs.p_code.TrueCodeOfPred = FAILCODE;
6098 ap->CodeOfPred = (
yamop *)(&(ap->OpcodeOfPred));
6101 ap->CodeOfPred = ap->cs.p_code.TrueCodeOfPred = FAILCODE;
6102#if defined(YAPOR) || defined(THREADS)
6105 ap->OpcodeOfPred = Yap_opcode(_op_fail);
6106 }
else if (ap->PredFlags & IndexedPredFlag) {
6107 remove_from_index(ap, sp, &cl, beg, last, &cint);
6108 }
else if (ap->cs.p_code.NOfClauses == 1) {
6109 ap->cs.p_code.TrueCodeOfPred = ap->cs.p_code.FirstClause;
6110 ap->CodeOfPred = (
yamop *)(&(ap->OpcodeOfPred));
6114static void store_clause_choice_point(Term t1, Term tb, Term tr,
yamop *ipc,
6116 yamop *cp_pc USES_REGS) {
6117 Term tpc = MkIntegerTerm((Int)ipc);
6118 Term tpe = MkIntegerTerm((Int)pe);
6119 CELL *tsp = ASP - 5;
6128 HB = bptr->cp_h = HR;
6130 bptr->cp_depth = DEPTH;
6133 bptr->cp_cp = cp_pc;
6134 bptr->cp_ap = ap_pc;
6138 ASP[E_CB] = (CELL)bptr;
6146static void update_clause_choice_point(
yamop *ipc,
yamop *ap_pc USES_REGS) {
6147 Term tpc = MkIntegerTerm((Int)ipc);
6148 B->cp_args[1] = tpc;
6154 if (ap->PredFlags & LogUpdatePredFlag)
6155 return lu_clause(ipc, ap);
6156 else if (ap->PredFlags & MegaClausePredFlag)
6167 int blob_term = FALSE;
6169#if defined(YAPOR) || defined(THREADS)
6170 yamop **jlbl = NULL;
6172 pred_flags_t lu_pred = ap->PredFlags & LogUpdatePredFlag;
6173 int unbounded = TRUE;
6175 if (ap->ModuleOfPred != IDB_MODULE) {
6176 if (ap->ArityOfPE) {
6177 CELL *tar = RepAppl(Deref(Yap_GetFromHandle(yht)));
6180 for (i = 1; i <= ap->ArityOfPE; i++) {
6186 while (ipc != NULL) {
6187 op_numbers op = Yap_op_from_opcode(ipc->opc);
6190 update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS);
6192 return lu_clause(ipc->y_u.l.l, ap);
6201 store_clause_choice_point(Yap_GetFromHandle(yht),
6202 Yap_GetFromHandle(yht+1),
6203 Yap_GetFromHandle(yht+2),
6204 NEXTOP(ipc, Otapl), ap, ap_pc,
6209 update_clause_choice_point(NEXTOP(ipc, Otapl), ap_pc PASS_REGS);
6212 return lu_clause(ipc->y_u.Otapl.d, ap);
6219 store_clause_choice_point(Yap_GetFromHandle(yht),
6220 Yap_GetFromHandle(yht+1),
6221 Yap_GetFromHandle(yht+2),
6223 ap, ap_pc, cp_pc PASS_REGS);
6227 update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS);
6230 return lu_clause(ipc->y_u.l.l, ap);
6238 store_clause_choice_point(Yap_GetFromHandle(yht),
6239 Yap_GetFromHandle(yht+1),
6240 Yap_GetFromHandle(yht+2),
6241 ipc->y_u.Otapl.d, ap, ap_pc, cp_pc PASS_REGS);
6245 update_clause_choice_point(ipc->y_u.Otapl.d, ap_pc PASS_REGS);
6247 ipc = NEXTOP(ipc, Otapl);
6249 case _retry_profiled:
6251 ipc = NEXTOP(ipc, p);
6257 update_clause_choice_point(NEXTOP(ipc, Otapl), ap_pc PASS_REGS);
6259 return lu_clause(ipc->y_u.Otapl.d, ap);
6265 update_clause_choice_point(NEXTOP(ipc, l), ap_pc PASS_REGS);
6267 return lu_clause(ipc->y_u.l.l, ap);
6271 update_clause_choice_point(ipc->y_u.Otapl.d, ap_pc PASS_REGS);
6272 ipc = NEXTOP(ipc, Otapl);
6279 while (POP_CHOICE_POINT(B->cp_b)) {
6287 CUT_prune_to(cut_pt);
6295 return lu_clause(ipc->y_u.Otapl.d, ap);
6298 case _profiled_trust_me:
6300 case _count_trust_me:
6302 case _table_trust_me:
6306 while (POP_CHOICE_POINT(B->cp_b)) {
6314 CUT_prune_to(cut_pt);
6320 ipc = NEXTOP(ipc, Otapl);
6322 case _enter_lu_pred: {
6328 if (ap->LastCallOfPred != LUCALL_EXEC) {
6333 if (ap->TimeStampOfPred >= TIMESTAMP_RESET)
6334 Yap_UpdateTimestamps(ap);
6335 ap->TimeStampOfPred++;
6338 ap->LastCallOfPred = LUCALL_EXEC;
6340 *--ASP = MkIntegerTerm(ap->TimeStampOfPred);
6344 INC_CLREF_COUNT(cl);
6347 if (!(cl->ClFlags & InUseMask)) {
6348 cl->ClFlags |= InUseMask;
6353 ipc = ipc->y_u.Illss.l1;
6357 store_clause_choice_point(Yap_GetFromHandle(yht),
6358 Yap_GetFromHandle(yht+1),
6359 Yap_GetFromHandle(yht+2),
6360 ipc->y_u.OtaLl.n, ap, ap_pc, cp_pc PASS_REGS);
6364 update_clause_choice_point(ipc->y_u.OtaLl.n, ap_pc PASS_REGS);
6367 UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]);
6369 if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) {
6371 ipc = ipc->y_u.OtaLl.n;
6375 return ipc->y_u.OtaLl.d;
6376 case _retry_logical:
6377 case _profiled_retry_logical:
6378 case _count_retry_logical: {
6379 UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]);
6380 if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtaLl.d)) {
6382 ipc = ipc->y_u.OtaLl.n;
6386 update_clause_choice_point(ipc->y_u.OtaLl.n, ap_pc PASS_REGS);
6387 return ipc->y_u.OtaLl.d;
6389 case _table_try_single:
6392 case _trust_logical:
6393 case _count_trust_logical:
6394 case _profiled_trust_logical: {
6395 UInt timestamp = IntegerOfTerm(((CELL *)(B + 1))[5]);
6399 if (!VALID_TIMESTAMP(timestamp, ipc->y_u.OtILl.d)) {
6403 newpc = ipc->y_u.OtILl.d;
6406 DEC_CLREF_COUNT(cl);
6410 if (cl->ClRefCount == 0 && cl->ClFlags & (ErasedMask | DirtyMask)) {
6417 if (lcl->ClRefCount == 1) {
6420 INC_CLREF_COUNT(lcl);
6425 if (cl->ClFlags & ErasedMask) {
6426 Yap_ErLogUpdIndex(cl);
6428 Yap_CleanUpIndex(cl);
6432 if (TrailTerm(B->cp_tr - 1) == CLREF_TO_TRENTRY(cl) &&
6433 B->cp_tr != B->cp_b->cp_tr) {
6437 cl->ClFlags &= ~InUseMask;
6439 if (cl->ClFlags & (ErasedMask | DirtyMask)) {
6445 if (newpc && !(lcl->ClFlags & (DirtyMask | InUseMask))) {
6446 lcl->ClFlags |= InUseMask;
6449 if (cl->ClFlags & ErasedMask) {
6450 Yap_ErLogUpdIndex(cl);
6452 Yap_CleanUpIndex(cl);
6458 while (POP_CHOICE_POINT(B->cp_b)) {
6466 CUT_prune_to(cut_pt);
6478 case _jump_if_var: {
6479 Term t = Deref(ARG1);
6484 ipc = NEXTOP(ipc, l);
6487 case _jump_if_nonvar: {
6488 Term t = Deref(XREGS[arg_from_x(ipc->y_u.xll.x)]);
6489 if (!IsVarTerm(t)) {
6491 ipc = ipc->y_u.xll.l1;
6493 ipc = NEXTOP(ipc, xll);
6497 ipc = ipc->y_u.lp.l;
6500 case _switch_on_type:
6505 ipc = ipc->y_u.llll.l4;
6506 }
else if (IsPairTerm(t)) {
6509 ipc = ipc->y_u.llll.l1;
6510 S = s_reg = RepPair(t);
6511 }
else if (IsAtomOrIntTerm(t)) {
6513 ipc = ipc->y_u.llll.l2;
6516 ipc = ipc->y_u.llll.l3;
6520 case _switch_list_nl:
6525 ipc = ipc->y_u.ollll.l4;
6526 }
else if (IsPairTerm(t)) {
6529 ipc = ipc->y_u.ollll.l1;
6530 S = s_reg = RepPair(t);
6531 }
else if (t == TermNil) {
6534 ipc = ipc->y_u.ollll.l2;
6537 ipc = ipc->y_u.ollll.l3;
6541 case _switch_on_arg_type:
6542 t = Deref(XREGS[arg_from_x(ipc->y_u.xllll.x)]);
6546 ipc = ipc->y_u.xllll.l4;
6547 }
else if (IsPairTerm(t)) {
6550 ipc = ipc->y_u.xllll.l1;
6551 S = s_reg = RepPair(t);
6552 }
else if (IsAtomOrIntTerm(t)) {
6554 ipc = ipc->y_u.xllll.l2;
6557 ipc = ipc->y_u.xllll.l3;
6561 case _switch_on_sub_arg_type:
6562 t = Deref(s_reg[ipc->y_u.sllll.s]);
6566 ipc = ipc->y_u.sllll.l4;
6567 }
else if (IsPairTerm(t)) {
6570 S = s_reg = RepPair(t);
6571 ipc = ipc->y_u.sllll.l1;
6572 }
else if (IsAtomOrIntTerm(t)) {
6574 ipc = ipc->y_u.sllll.l2;
6577 ipc = ipc->y_u.sllll.l3;
6586 ipc = ipc->y_u.clll.l3;
6587 }
else if (!IsVarTerm(t) && t != ipc->y_u.clll.c) {
6589 ipc = ipc->y_u.clll.l1;
6592 ipc = ipc->y_u.clll.l2;
6596 case _switch_on_func:
6607 if (op == _switch_on_func) {
6608 fe = lookup_f_hash(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
6610 fe = lookup_f(f, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
6612#if defined(YAPOR) || defined(THREADS)
6613 jlbl = &(fe->u_f.labp);
6618 if (s_reg[-1] != (CELL)FunctorDBREF) {
6622 t = AbsAppl(s_reg - 1);
6624 ipc = NEXTOP(ipc, e);
6627 if (s_reg[-1] != (CELL)FunctorDouble) {
6631 t = Yap_DoubleP_key(s_reg);
6633 ipc = NEXTOP(ipc, e);
6636 if (s_reg[-1] != (CELL)FunctorLongInt) {
6640 t = Yap_IntP_key(s_reg);
6642 ipc = NEXTOP(ipc, e);
6644 case _switch_on_cons:
6650 if (op == _switch_on_cons) {
6651 ae = lookup_c_hash(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
6653 ae = lookup_c(t, ipc->y_u.sssl.l, ipc->y_u.sssl.s);
6655#if defined(YAPOR) || defined(THREADS)
6656 jlbl = &(ae->u_a.labp);
6661 case _expand_clauses:
6665 h1 = Yap_InitHandle( (CELL)&XREGS[ap->ArityOfPE + 1] );
6666 h2 = Yap_InitHandle( TermNil );
6668 h1 = Yap_InitHandle( AbsPair(s_reg) );
6669 h2 = Yap_InitHandle( t );
6671#if defined(YAPOR) || defined(THREADS)
6672 if (!same_lu_block(jlbl, ipc)) {
6677 ipc = ExpandIndex(ap, 5, cp_pc PASS_REGS);
6679 t = Yap_PopHandle(h2);
6680 s_reg = (CELL *)RepPair(Yap_PopHandle(h1));
6691 ipc = NEXTOP(ipc, p);
6695 ap = Yap_GetThreadPred(ap PASS_REGS);
6696 ipc = ap->CodeOfPred;
6701 if ((ap->PredFlags & IndexedPredFlag) || ap->cs.p_code.NOfClauses <= 1) {
6702 ipc = ap->cs.p_code.TrueCodeOfPred;
6709 h1 = Yap_InitHandle( (CELL)&XREGS[ap->ArityOfPE + 1] );
6710 h2 = Yap_InitHandle( TermNil );
6712 h1 = Yap_InitHandle( (CELL)s_reg );
6713 h2 = Yap_InitHandle( t );
6715#if defined(YAPOR) || defined(THREADS)
6716 if (!same_lu_block(jlbl, ipc)) {
6721 Yap_IPred(ap, 5, cp_pc);
6722 ipc = ap->cs.p_code.TrueCodeOfPred;
6724 t = Yap_PopHandle(h2);
6725 s_reg = (CELL *)Yap_PopHandle(h1);
6734 if (ipc == FAILCODE)
6739 while (POP_CHOICE_POINT(B->cp_b)) {
6747 CUT_prune_to(cut_pt);
6758 return lu_clause(ipc, ap);
6766 while (POP_CHOICE_POINT(B->cp_b)) {
6774 CUT_prune_to(cut_pt);
6786 yamop *ipc = ap->cs.p_code.TrueCodeOfPred, *alt = NULL;
6787#if defined(YAPOR) || defined(THREADS)
6788 yamop **jlbl = NULL;
6792 if (ncls > ap->cs.p_code.NOfClauses)
6795 return to_clause(ap->cs.p_code.FirstClause, ap);
6796 else if (ap->PredFlags & MegaClausePredFlag) {
6797 MegaClause *mcl = ClauseCodeToMegaClause(ap->cs.p_code.FirstClause);
6799 return (
LogUpdClause *)((
char *)mcl->ClCode + (ncls - 1) * mcl->ClItemSize);
6800 }
else if (ncls == ap->cs.p_code.NOfClauses) {
6801 return to_clause(ap->cs.p_code.LastClause, ap);
6802 }
else if (ncls < 0)
6805 if (ap->ModuleOfPred != IDB_MODULE) {
6806 if (ap->ArityOfPE) {
6809 for (i = 1; i <= ap->ArityOfPE; i++) {
6810 XREGS[i] = MkVarTerm();
6817 op_numbers op = Yap_op_from_opcode(ipc->opc);
6822 return to_clause(ipc->y_u.l.l, ap);
6824 ipc = NEXTOP(ipc, l);
6826 case _retry_profiled:
6828 ipc = NEXTOP(ipc, p);
6832 return to_clause(ipc->y_u.Otapl.d, ap);
6833 else if (alt == NULL) {
6836 if (ap->PredFlags & ProfiledPredFlag) {
6837 if (ap->PredFlags & CountPredFlag) {
6838 ipc = (
yamop *)((
char *)ipc +
6839 ncls * (UInt)NEXTOP(
6840 NEXTOP(NEXTOP((
yamop *)NULL, Otapl), p),
6844 (
yamop *)((
char *)ipc +
6845 ncls * (UInt)NEXTOP(NEXTOP((
yamop *)NULL, Otapl), p));
6847 }
else if (ap->PredFlags & CountPredFlag) {
6848 ipc = (
yamop *)((
char *)ipc +
6849 ncls * (UInt)NEXTOP(NEXTOP((
yamop *)NULL, Otapl), p));
6851 ipc = (
yamop *)((
char *)ipc +
6852 ncls * (UInt)NEXTOP((
yamop *)NULL, Otapl));
6854 return to_clause(ipc->y_u.Otapl.d, ap);
6858 ipc = NEXTOP(ipc, Otapl);
6867 return to_clause(ipc->y_u.l.l, ap);
6868 else if (alt == NULL) {
6871 if (ap->PredFlags & ProfiledPredFlag) {
6872 if (ap->PredFlags & CountPredFlag) {
6873 ipc = (
yamop *)((
char *)ipc +
6874 ncls * (UInt)NEXTOP(
6875 NEXTOP(NEXTOP((
yamop *)NULL, l), p), p));
6877 ipc = (
yamop *)((
char *)ipc +
6878 ncls * (UInt)NEXTOP(NEXTOP((
yamop *)NULL, l), p));
6880 }
else if (ap->PredFlags & CountPredFlag) {
6881 ipc = (
yamop *)((
char *)ipc +
6882 ncls * (UInt)NEXTOP(NEXTOP((
yamop *)NULL, l), p));
6884 ipc = (
yamop *)((
char *)ipc + ncls * (UInt)NEXTOP((
yamop *)NULL, l));
6886 return to_clause(ipc->y_u.l.l, ap);
6890 ipc = NEXTOP(ipc, l);
6894 return to_clause(ipc->y_u.l.l, ap);
6900 alt = ipc->y_u.Otapl.d;
6901 ipc = NEXTOP(ipc, Otapl);
6903 case _profiled_trust_me:
6905 case _count_trust_me:
6907 ipc = NEXTOP(ipc, Otapl);
6910 case _retry_logical:
6911 case _count_retry_logical:
6912 case _profiled_retry_logical:
6913 if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->y_u.OtaLl.d)) {
6915 return ipc->y_u.OtaLl.d;
6918 ipc = ipc->y_u.OtaLl.n;
6920 case _trust_logical:
6921 case _count_trust_logical:
6922 case _profiled_trust_logical:
6923 if (VALID_TIMESTAMP(ap->TimeStampOfPred, ipc->y_u.OtILl.d)) {
6925 return ipc->y_u.OtILl.d;
6928 case _enter_lu_pred:
6930 ipc = ipc->y_u.Illss.l1;
6933 ipc = NEXTOP(ipc, p);
6943 case _jump_if_nonvar:
6944 ipc = NEXTOP(ipc, xll);
6948 ipc = ipc->y_u.lp.l;
6951 case _switch_on_type:
6953 ipc = ipc->y_u.llll.l4;
6955 case _switch_list_nl:
6957 ipc = ipc->y_u.ollll.l4;
6959 case _switch_on_arg_type:
6961 ipc = ipc->y_u.xllll.l4;
6963 case _switch_on_sub_arg_type:
6965 ipc = ipc->y_u.sllll.l4;
6969 ipc = ipc->y_u.clll.l3;
6972 case _expand_clauses:
6973#if defined(YAPOR) || defined(THREADS)
6974 if (*jlbl != (
yamop *)&(ap->cs.p_code.ExpandCode)) {
6979 ipc = ExpandIndex(ap, 0, CP PASS_REGS);
6988 Yap_IPred(ap, 0, CP);
6989 ipc = ap->cs.p_code.TrueCodeOfPred;
7000 yamop *start = blk->ClCode;
7001 op_numbers op = Yap_op_from_opcode(start->opc);
7003 blk->ClFlags &= ~DirtyMask;
7004 while (op == _lock_lu) {
7005 start = NEXTOP(start, p);
7006 op = Yap_op_from_opcode(start->opc);
7008 while (op == _jump_if_nonvar) {
7009 start = NEXTOP(start, xll);
7010 op = Yap_op_from_opcode(start->opc);
7012 remove_dirty_clauses_from_index(start);
@ source
If true maintain the source for all clauses.