Skip to content

Commit

Permalink
Bigints
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Nov 26, 2024
1 parent 450e8a1 commit 7d70bb8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/bif_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
} \
if (errno == ENOMEM) \
return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \
q->accum.val_bigint->refcnt = 0; \
}

Expand All @@ -39,7 +39,7 @@
} \
if (errno == ENOMEM) \
return throw_error(q, p1, q->st.curr_frame, "resource_error", "memory"); \
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \
q->accum.val_bigint->refcnt = 0; \
}

Expand All @@ -54,7 +54,7 @@
if (mp_rat_init_copy(&q->accum.val_bigint->irat, &q->tmp_irat) == MP_MEMORY) {\
return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \
} \
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \
q->accum.val_bigint->refcnt = 0; \
} else { \
q->accum.tag = TAG_INTEGER; \
Expand All @@ -64,7 +64,7 @@
if (mp_int_init_copy(&q->accum.val_bigint->ival, &q->tmp_irat.num) == MP_MEMORY) {\
return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory"); \
} \
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG); \
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED; \
q->accum.val_bigint->refcnt = 0; \
} \
if (errno == ENOMEM) \
Expand Down Expand Up @@ -512,7 +512,7 @@ static bool bif_numerator_1(query *q)
mp_int_init_copy(&q->accum.val_bigint->ival, &p1.val_bigint->irat.num);
if (errno == ENOMEM)
return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory");
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG);
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED;
q->accum.val_bigint->refcnt = 0;
return true;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ static bool bif_denominator_1(query *q)
mp_int_init_copy(&q->accum.val_bigint->ival, &p1.val_bigint->irat.den);
if (errno == ENOMEM)
return throw_error(q, &p1, q->st.curr_frame, "resource_error", "memory");
q->accum.flags = (FLAG_MANAGED | FLAG_INT_BIG);
q->accum.flags = FLAG_INT_BIG | FLAG_MANAGED;
q->accum.val_bigint->refcnt = 0;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bif_predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -4761,7 +4761,7 @@ static bool bif_hex_chars_2(query *q)
check_heap_error(tmp.val_bigint);
tmp.val_bigint->refcnt = 1;
mp_int_init_copy(&tmp.val_bigint->ival, &v2);
tmp.flags |= ((FLAG_MANAGED | FLAG_INT_BIG) | FLAG_INT_BIG);
tmp.flags |= FLAG_INT_BIG | FLAG_MANAGED | FLAG_INT_BIG;
} else {
make_uint(&tmp, (unsigned long long)val);
}
Expand Down Expand Up @@ -4816,7 +4816,7 @@ static bool bif_octal_chars_2(query *q)
check_heap_error(tmp.val_bigint);
tmp.val_bigint->refcnt = 1;
mp_int_init_copy(&tmp.val_bigint->ival, &v2);
tmp.flags |= (FLAG_MANAGED | FLAG_INT_BIG);
tmp.flags |= FLAG_INT_BIG | FLAG_MANAGED;
} else {
make_uint(&tmp, (unsigned long long)val);
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
p->v.val_bigint->refcnt = 1;
mp_int_init_copy(&p->v.val_bigint->ival, &v2);
if (neg) p->v.val_bigint->ival.sign = MP_NEG;
p->v.flags |= FLAG_INT_BIG;
p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED;
} else {
set_smallint(&p->v, val);
if (neg) p->v.val_int = -p->v.val_int;
Expand All @@ -2629,7 +2629,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
p->v.val_bigint->refcnt = 1;
mp_int_init_copy(&p->v.val_bigint->ival, &v2);
if (neg) p->v.val_bigint->ival.sign = MP_NEG;
p->v.flags |= FLAG_INT_BIG;
p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED;
} else {
set_smallint(&p->v, val);
if (neg) p->v.val_int = -p->v.val_int;
Expand All @@ -2652,7 +2652,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
p->v.val_bigint->refcnt = 1;
mp_int_init_copy(&p->v.val_bigint->ival, &v2);
if (neg) p->v.val_bigint->ival.sign = MP_NEG;
p->v.flags |= FLAG_INT_BIG;
p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED;
} else {
set_smallint(&p->v, val);
if (neg) p->v.val_int = -p->v.val_int;
Expand Down Expand Up @@ -2712,7 +2712,7 @@ static bool parse_number(parser *p, const char **srcptr, bool neg)
p->v.val_bigint->refcnt = 1;
mp_int_init_copy(&p->v.val_bigint->ival, &v2);
if (neg) p->v.val_bigint->ival.sign = MP_NEG;
p->v.flags |= FLAG_INT_BIG;
p->v.flags |= FLAG_INT_BIG | FLAG_MANAGED;
} else {
set_smallint(&p->v, val);
if (neg) p->v.val_int = -p->v.val_int;
Expand Down
10 changes: 10 additions & 0 deletions src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,16 @@ void query_destroy(query *q)
free(save);
}

while (q->st.tp > 0) {
const trail *tr = q->trails + --q->st.tp;
const frame *f = GET_FRAME(tr->var_ctx);
slot *e = GET_SLOT(f, tr->var_nbr);
cell *c = &e->c;
unshare_cell(c);
c->tag = TAG_EMPTY;
c->attrs = tr->attrs;
}

for (int i = 0; i < MAX_QUEUES; i++)
free(q->queue[i]);

Expand Down

0 comments on commit 7d70bb8

Please sign in to comment.