Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Jun 6, 2024
1 parent ab53f30 commit c5ee972
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
12 changes: 1 addition & 11 deletions src/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,7 @@ cell *prepare_call(query *q, bool prefix, cell *p1, pl_idx p1_ctx, unsigned extr

if (prefix) {
// Needed for follow() to work
tmp->tag = TAG_INTERNED;
tmp->arity = 0;
tmp->nbr_cells = 1;
tmp->flags = FLAG_BUILTIN;
tmp->val_off = g_true_s;
static builtins *s_fn_ptr = NULL;

if (!s_fn_ptr)
s_fn_ptr = get_fn_ptr(bif_iso_true_0);

tmp->bif_ptr = s_fn_ptr;
make_struct(tmp, g_true_s, bif_iso_true_0, 0, 0);
}

q->in_call++;
Expand Down
16 changes: 2 additions & 14 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,11 @@ void make_ptr(cell *tmp, void *v)
tmp->val_uint = (size_t)v;
}

void make_struct(cell *tmp, pl_idx offset, void *fn, unsigned arity, pl_idx extra_cells)
void make_struct_(cell *tmp, pl_idx offset, unsigned arity, pl_idx extra_cells)
{
*tmp = (cell){0};
tmp->tag = TAG_INTERNED;
tmp->nbr_cells = 1 + extra_cells;

if (fn) {
tmp->flags |= FLAG_BUILTIN;
tmp->bif_ptr = get_fn_ptr(fn);
}

tmp->arity = arity;
tmp->val_off = offset;
}
Expand Down Expand Up @@ -2066,13 +2060,7 @@ static cell *insert_call_here(parser *p, cell *c, cell *p1)
*dst-- = *last--;

p1 = p->cl->cells + p1_idx;
p1->tag = TAG_INTERNED;
p1->flags = FLAG_BUILTIN;
p1->bif_ptr = get_fn_ptr(bif_iso_call_1);
p1->val_off = g_call_s;
p1->nbr_cells = 2;
p1->arity = 1;

make_struct(p1, g_call_s, bif_iso_call_1, 1, 1);
p->cl->cidx++;
return p->cl->cells + c_idx;
}
Expand Down
16 changes: 15 additions & 1 deletion src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void make_uint(cell *tmp, pl_uint v);
void make_int(cell *tmp, pl_int v);
void make_float(cell *tmp, pl_flt v);
void make_ptr(cell *tmp, void *v);
void make_struct(cell *tmp, pl_idx offset, void *fn, unsigned arity, pl_idx extra_cells);
void make_struct_(cell *tmp, pl_idx offset, unsigned arity, pl_idx extra_cells);
void make_var(cell *tmp, pl_idx off, unsigned var_nbr);
void make_ref(cell *tmp, unsigned var_nbr, pl_idx ctx);
void make_end(cell *tmp);
Expand All @@ -45,4 +45,18 @@ bool do_register_struct(module *m, query *q, void *handle, const char *symbol, c
int do_dlclose(void *handle);
#endif

#define make_struct(tmp, offset, fn, arity, extra_cells) { \
cell *tmp_make = tmp; \
make_struct_(tmp_make, offset, arity, extra_cells); \
\
if (fn != NULL) { \
static builtins *s_fn_ptr_##fn = NULL; \
if (!s_fn_ptr_##fn) \
s_fn_ptr_##fn = get_fn_ptr(fn); \
\
tmp_make->bif_ptr = s_fn_ptr_##fn; \
tmp_make->flags = FLAG_BUILTIN; \
} \
}

extern const char *g_solo;
12 changes: 1 addition & 11 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,17 +1334,7 @@ bool match_rule(query *q, cell *p1, pl_idx p1_ctx, enum clause_type is_retract)
p1_body = deref(q, p1_body, p1_ctx);
pl_idx p1_body_ctx = q->latest_ctx;
cell tmp;
tmp.tag = TAG_INTERNED;
tmp.arity = 0;
tmp.nbr_cells = 1;
tmp.flags = FLAG_BUILTIN;
tmp.val_off = g_true_s;
static builtins *s_fn_ptr = NULL;

if (!s_fn_ptr)
s_fn_ptr = get_fn_ptr(bif_iso_true_0);

tmp.bif_ptr = s_fn_ptr;
make_struct(&tmp, g_true_s, bif_iso_true_0, 0, 0);
ok = unify(q, p1_body, p1_body_ctx, &tmp, q->st.curr_frame);
} else
ok = true;
Expand Down

0 comments on commit c5ee972

Please sign in to comment.