VM: refactored factor_vm::unbox_array_size()
parent
327790391d
commit
03672ad938
18
vm/math.cpp
18
vm/math.cpp
|
@ -190,24 +190,6 @@ void factor_vm::primitive_bignum_log2() {
|
||||||
ctx->replace(tag<bignum>(bignum_integer_length(untag<bignum>(ctx->peek()))));
|
ctx->replace(tag<bignum>(bignum_integer_length(untag<bignum>(ctx->peek()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocates memory */
|
|
||||||
cell factor_vm::unbox_array_size_slow() {
|
|
||||||
if (tagged<object>(ctx->peek()).type() == BIGNUM_TYPE) {
|
|
||||||
bignum* zero = untag<bignum>(bignum_zero);
|
|
||||||
GC_BIGNUM(zero);
|
|
||||||
bignum* max = cell_to_bignum(array_size_max);
|
|
||||||
bignum* n = untag<bignum>(ctx->peek());
|
|
||||||
if (bignum_compare(n, zero) != bignum_comparison_less &&
|
|
||||||
bignum_compare(n, max) == bignum_comparison_less) {
|
|
||||||
ctx->pop();
|
|
||||||
return bignum_to_cell(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
general_error(ERROR_ARRAY_SIZE, ctx->pop(), tag_fixnum(array_size_max));
|
|
||||||
return 0; /* can't happen */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Allocates memory */
|
/* Allocates memory */
|
||||||
void factor_vm::primitive_fixnum_to_float() {
|
void factor_vm::primitive_fixnum_to_float() {
|
||||||
ctx->replace(allot_float(fixnum_to_float(ctx->peek())));
|
ctx->replace(allot_float(fixnum_to_float(ctx->peek())));
|
||||||
|
|
11
vm/math.hpp
11
vm/math.hpp
|
@ -50,16 +50,13 @@ inline double factor_vm::fixnum_to_float(cell tagged) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline cell factor_vm::unbox_array_size() {
|
inline cell factor_vm::unbox_array_size() {
|
||||||
cell obj = ctx->peek();
|
cell obj = ctx->pop();
|
||||||
if (TAG(obj) == FIXNUM_TYPE) {
|
fixnum n = to_fixnum(obj);
|
||||||
fixnum n = untag_fixnum(obj);
|
|
||||||
if (n >= 0 && n < (fixnum)array_size_max) {
|
if (n >= 0 && n < (fixnum)array_size_max) {
|
||||||
ctx->pop();
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
}
|
general_error(ERROR_ARRAY_SIZE, obj, tag_fixnum(array_size_max));
|
||||||
|
return 0; /* can't happen */
|
||||||
return unbox_array_size_slow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_C_API cell from_signed_cell(fixnum integer, factor_vm* vm);
|
VM_C_API cell from_signed_cell(fixnum integer, factor_vm* vm);
|
||||||
|
|
Loading…
Reference in New Issue