Skip to content

Commit

Permalink
Work on sys_list_attributed/1, re issue #443
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Jan 11, 2024
1 parent b535828 commit bb3b47d
Showing 1 changed file with 29 additions and 38 deletions.
67 changes: 29 additions & 38 deletions src/bif_atts.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,39 @@ bool bif_get_atts_2(query *q)
return is_minus ? true : false;
}

bool any_attributed(query *q)
static bool check_occurs(unsigned var_nbr, pl_idx var_ctx, cell *c, pl_idx c_ctx)
{
const parser *p = q->p;
const frame *f = GET_FIRST_FRAME();
bool any = false;

for (unsigned i = 0; i < p->nbr_vars; i++) {
slot *e = GET_SLOT(f, i);
cell *v = deref(q, &e->c, e->c.var_ctx);
pl_idx v_ctx = q->latest_ctx;
for (unsigned nbr_cells = c->nbr_cells; nbr_cells--; c++) {
if (!is_var(c))
continue;

if (is_compound(v)) {
collect_vars(q, v, v_ctx);
pl_idx ctx = c_ctx;

for (unsigned i = 0, done = 0; i < q->tab_idx; i++) {
const frame *f = GET_FRAME(q->pl->tabs[i].ctx);
slot *e = GET_SLOT(f, q->pl->tabs[i].var_nbr);
cell *v = deref(q, &e->c, e->c.var_ctx);
if (is_ref(c))
ctx = c->var_ctx;

if (!is_empty(v) || !v->attrs || is_nil(v->attrs))
continue;
if (var_nbr != c->var_nbr)
continue;

return true;
}
}
if (var_ctx != ctx)
continue;

any = true;
}

return !any;
}

bool any_attributed(query *q)
{
for (unsigned i = 0; i < q->st.tp; i++) {
const trail *tr = q->trails + i;
const frame *f = GET_FRAME(tr->var_ctx);
slot *e = GET_SLOT(f, tr->var_nbr);
cell *v = deref(q, &e->c, e->c.var_ctx);
pl_idx v_ctx = q->latest_ctx;

if (!is_empty(v) || !v->attrs || is_nil(v->attrs))
continue;
Expand All @@ -231,7 +240,6 @@ bool any_attributed(query *q)
bool bif_sys_list_attributed_1(query *q)
{
GET_FIRST_ARG(p1,var);
parser *p = q->p;
check_heap_error(init_tmp_heap(q));

for (unsigned i = 0; i < q->st.tp; i++) {
Expand All @@ -241,23 +249,6 @@ bool bif_sys_list_attributed_1(query *q)
cell *c = deref(q, &e->c, e->c.var_ctx);
pl_idx c_ctx = q->latest_ctx;

if (is_compound(c)) {
collect_vars(q, c, c_ctx);

for (unsigned i = 0, done = 0; i < q->tab_idx; i++) {
const frame *f = GET_FRAME(q->pl->tabs[i].ctx);
slot *e = GET_SLOT(f, q->pl->tabs[i].var_nbr);
cell *v = deref(q, &e->c, e->c.var_ctx);

if (!is_empty(v) || !v->attrs || is_nil(v->attrs))
continue;

cell tmp;
make_ref(&tmp, q->pl->tabs[i].var_nbr, q->pl->tabs[i].ctx);
append_list(q, &tmp);
}
}

if (!is_empty(c) || !c->attrs || is_nil(c->attrs))
continue;

Expand Down Expand Up @@ -319,7 +310,7 @@ typedef struct {
slot e[];
} bind_state;

static void check_occurs(unsigned var_nbr, pl_idx var_ctx, cell *c, pl_idx c_ctx)
static void set_occurs(unsigned var_nbr, pl_idx var_ctx, cell *c, pl_idx c_ctx)
{
for (unsigned nbr_cells = c->nbr_cells; nbr_cells--; c++) {
if (!is_var(c))
Expand Down Expand Up @@ -366,7 +357,7 @@ bool bif_sys_undo_trail_2(query *q)
save->e[j] = *e;
cell *c = &e->c;
pl_idx c_ctx = e->c.var_ctx;
check_occurs(tr->var_nbr, tr->var_ctx, c, c_ctx);
set_occurs(tr->var_nbr, tr->var_ctx, c, c_ctx);
//printf("*** unbind [%u:%u] hi_tp=%u, tag=%u, tr->var_ctx=%u, tr->var_nbr=%u\n", j, i, q->undo_hi_tp, e->c.tag, tr->var_ctx, tr->var_nbr);
cell lhs, rhs;
make_ref(&lhs, tr->var_nbr, tr->var_ctx);
Expand Down

0 comments on commit bb3b47d

Please sign in to comment.