]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: refactored factor_vm::unbox_array_size()
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 29 May 2014 17:08:01 +0000 (19:08 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sat, 7 Jun 2014 10:13:59 +0000 (12:13 +0200)
vm/math.cpp
vm/math.hpp

index cc1fce796e98709c138d3dc2fc8ae607c3c90a07..8b99895e39fee401908758fb33b344621b16cf8a 100644 (file)
@@ -190,24 +190,6 @@ void factor_vm::primitive_bignum_log2() {
   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 */
 void factor_vm::primitive_fixnum_to_float() {
   ctx->replace(allot_float(fixnum_to_float(ctx->peek())));
index b39ee80b6f3b5895864e096f8e2f83bb63347523..04daf74d90ad33ea6f8b6273c2e76d1139b62792 100644 (file)
@@ -50,16 +50,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(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);