]> gitweb.factorcode.org Git - factor.git/blobdiff - vm/math.hpp
audio.engine.test: cleanup using
[factor.git] / vm / math.hpp
index b39ee80b6f3b5895864e096f8e2f83bb63347523..c0b6f7ed326049cd5a0cc570b291cc09f7980cf1 100644 (file)
@@ -5,30 +5,28 @@ static const fixnum fixnum_max =
 static const fixnum fixnum_min = (-((fixnum)1 << (WORD_SIZE - TAG_BITS - 1)));
 static const fixnum array_size_max = ((cell)1 << (WORD_SIZE - TAG_BITS - 2));
 
-/* Allocates memory */
+// Allocates memory
 inline cell factor_vm::from_signed_cell(fixnum x) {
   if (x < fixnum_min || x > fixnum_max)
     return tag<bignum>(fixnum_to_bignum(x));
-  else
-    return tag_fixnum(x);
+  return tag_fixnum(x);
 }
 
-/* Allocates memory */
+// Allocates memory
 inline cell factor_vm::from_unsigned_cell(cell x) {
   if (x > (cell)fixnum_max)
     return tag<bignum>(cell_to_bignum(x));
-  else
-    return tag_fixnum(x);
+  return tag_fixnum(x);
 }
 
-/* Allocates memory */
+// Allocates memory
 inline cell factor_vm::allot_float(double n) {
   boxed_float* flo = allot<boxed_float>(sizeof(boxed_float));
   flo->n = n;
   return tag(flo);
 }
 
-/* Allocates memory */
+// Allocates memory
 inline bignum* factor_vm::float_to_bignum(cell tagged) {
   return double_to_bignum(untag_float(tagged));
 }
@@ -50,16 +48,13 @@ inline double factor_vm::fixnum_to_float(cell tagged) {
 }
 
 inline cell factor_vm::unbox_array_size() {
-  cell obj = ctx->peek();
-  if (TAG(obj) == FIXNUM_TYPE) {
-    fixnum n = untag_fixnum(obj);
-    if (n >= 0 && n < (fixnum)array_size_max) {
-      ctx->pop();
-      return n;
-    }
+  cell obj = ctx->pop();
+  fixnum n = to_fixnum_strict(obj);
+  if (n >= 0 && n < (fixnum)array_size_max) {
+    return n;
   }
-
-  return unbox_array_size_slow();
+  general_error(ERROR_ARRAY_SIZE, obj, tag_fixnum(array_size_max));
+  return 0; // can't happen
 }
 
 VM_C_API cell from_signed_cell(fixnum integer, factor_vm* vm);