return objects.value();
}
+// Allocates memory
+void growable_array::reallot_array(cell count) {
+ array *a_old = elements.untagged();
+ array *a_new = elements.parent->reallot_array(a_old, count);
+ elements.set_untagged(a_new);
+}
+
// Allocates memory
void growable_array::add(cell elt_) {
factor_vm* parent = elements.parent;
data_root<object> elt(elt_, parent);
- if (count == array_capacity(elements.untagged()))
- elements = parent->reallot_array(elements.untagged(), count * 2);
-
+ if (count == array_capacity(elements.untagged())) {
+ reallot_array(2 * count);
+ }
parent->set_array_nth(elements.untagged(), count++, elt.value());
}
data_root<array> elts(elts_, parent);
cell capacity = array_capacity(elts.untagged());
if (count + capacity > array_capacity(elements.untagged())) {
- elements =
- parent->reallot_array(elements.untagged(), (count + capacity) * 2);
+ reallot_array(2 * (count + capacity));
}
for (cell index = 0; index < capacity; index++)
// Allocates memory
void growable_array::trim() {
- factor_vm* parent = elements.parent;
- elements = parent->reallot_array(elements.untagged(), count);
+ reallot_array(count);
}
}
: count(0),
elements(parent->allot_array(capacity, false_object), parent) {}
+ void reallot_array(cell count);
void add(cell elt);
void append(array* elts);
void trim();
bignum_destructive_unnormalization(u.untagged(), shift);
}
- q = bignum_trim(q.untagged());
+ q.set_untagged(bignum_trim(q.untagged()));
*quotient = q.untagged();
} else {
}
}
- u = bignum_trim(u.untagged());
+ u.set_untagged(bignum_trim(u.untagged()));
if (remainder != NULL)
*remainder = u.untagged();
}
(*scan) = qj;
}
- q = bignum_trim(q.untagged());
+ q.set_untagged(bignum_trim(q.untagged()));
if (remainder != ((bignum**)0)) {
if (shift != 0)
bignum_digit_type r = bignum_destructive_scale_down(q.untagged(), denominator);
- q = bignum_trim(q.untagged());
+ q.set_untagged(bignum_trim(q.untagged()));
if (remainder != ((bignum**)0))
(*remainder) = bignum_digit_to_bignum(r, r_negative_p);
}
data_root<bignum> e(bignum_trim(a.untagged()), this);
data_root<bignum> f(bignum_trim(b.untagged()), this);
- c = bignum_remainder(e.untagged(), f.untagged());
+ c.set_untagged(bignum_remainder(e.untagged(), f.untagged()));
if (c.untagged() == BIGNUM_OUT_OF_BAND) {
return c.untagged();
}
ctx->push(tag<byte_array>(reallot_array(array.untagged(), capacity)));
}
+// Allocates memory
+void growable_byte_array::reallot_array(cell count) {
+ byte_array *ba_old = elements.untagged();
+ byte_array *ba_new = elements.parent->reallot_array(ba_old, count);
+ elements.set_untagged(ba_new);
+}
+
// Allocates memory
void growable_byte_array::grow_bytes(cell len) {
count += len;
- if (count >= array_capacity(elements.untagged()))
- elements = elements.parent->reallot_array(elements.untagged(), count * 2);
+ if (count >= array_capacity(elements.untagged())) {
+ reallot_array(2 * count);
+ }
}
// Allocates memory
cell len = array_capacity(byte_array.untagged());
cell new_size = count + len;
- factor_vm* parent = elements.parent;
- if (new_size >= array_capacity(elements.untagged()))
- elements = parent->reallot_array(elements.untagged(), new_size * 2);
+ if (new_size >= array_capacity(elements.untagged())) {
+ reallot_array(2 * new_size);
+ }
memcpy(&elements->data<uint8_t>()[count], byte_array->data<uint8_t>(), len);
// Allocates memory
void growable_byte_array::trim() {
- factor_vm* parent = elements.parent;
- elements = parent->reallot_array(elements.untagged(), count);
+ reallot_array(count);
}
}
growable_byte_array(factor_vm* parent, cell capacity = 40)
: count(0), elements(parent->allot_byte_array(capacity), parent) {}
+ void reallot_array(cell count);
void grow_bytes(cell len);
void append_bytes(void* elts, cell len);
void append_byte_array(cell elts);
push();
}
- const data_root<Type>& operator=(const Type* x) {
- tagged<Type>::operator=(x);
- return *this;
- }
- const data_root<Type>& operator=(const cell& x) {
- tagged<Type>::operator=(x);
- return *this;
- }
-
~data_root() {
parent->data_roots.pop_back();
}
}
void quotation_jit::init_quotation(cell quot) {
- elements = untag<quotation>(quot)->array;
+ elements.set_value(untag<quotation>(quot)->array);
}
bool quotation_jit::fast_if_p(cell i, cell length) {
explicit tagged(cell tagged) : value_(tagged) {}
explicit tagged(Type* untagged) : value_(factor::tag(untagged)) {}
- Type* operator->() const { return untagged(); }
- cell* operator&() const { return &value_; }
-
- const tagged<Type>& operator=(const Type* x) {
- value_ = tag(x);
- return *this;
+ void set_value(const cell ptr) {
+ value_ = ptr;
}
- const tagged<Type>& operator=(const cell& x) {
- value_ = x;
- return *this;
+
+ void set_untagged(const Type *untagged) {
+ set_value(tag(untagged));
}
+ Type* operator->() const { return untagged(); }
+ cell* operator&() const { return &value_; }
+
bool operator==(const tagged<Type>& x) { return value_ == x.value_; }
bool operator!=(const tagged<Type>& x) { return value_ != x.value_; }