]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: now special-objects is used for -1, 0, 1 and t
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 10 Dec 2015 09:07:57 +0000 (10:07 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Thu, 10 Dec 2015 09:22:38 +0000 (10:22 +0100)
The fields in the image_header aren't read or written to but I haven't
changed the format yet.

basis/bootstrap/image/image.factor
vm/alien.cpp
vm/bignumint.hpp
vm/contexts.cpp
vm/factor.cpp
vm/image.cpp
vm/image.hpp
vm/slot_visitor.hpp
vm/vm.hpp

index 44d8e5cf172997ccba35093df6f85bc0762573b1..5bdacc390cf3d13f340aa9a7b633bf3782424dd4 100755 (executable)
@@ -86,8 +86,8 @@ SYMBOL: objects
 : put-object ( n obj -- )
     <eq-wrapper> objects get set-at ;
 
-! Constants
-
+! Constants need to be synced with
+!   vm/image.hpp
 CONSTANT: image-magic 0x0f0e0d0c
 CONSTANT: image-version 4
 
@@ -96,10 +96,6 @@ CONSTANT: data-base 1024
 CONSTANT: header-size 10
 
 CONSTANT: data-heap-size-offset 3
-CONSTANT: t-offset              6
-CONSTANT: 0-offset              7
-CONSTANT: 1-offset              8
-CONSTANT: -1-offset             9
 
 SYMBOL: sub-primitives
 
@@ -199,10 +195,10 @@ GENERIC: prepare-object ( obj -- ptr )
     0 emit ! size of data heap set later
     0 emit ! reloc base of code heap is 0
     0 emit ! size of code heap is 0
-    0 emit ! pointer to t object
-    0 emit ! pointer to bignum 0
-    0 emit ! pointer to bignum 1
-    0 emit ! pointer to bignum -1
+    0 emit ! reserved
+    0 emit ! reserved
+    0 emit ! reserved
+    0 emit ! reserved
     special-object-count [ f prepare-object emit ] times ;
 
 ! Bignums
@@ -257,15 +253,8 @@ M: float prepare-object
 ! Special objects
 
 ! Padded with fixnums for 8-byte alignment
-
-: t, ( -- ) t t-offset fixup ;
-
 M: f prepare-object drop \ f type-number ;
 
-:  0, ( -- )  0 >bignum prepare-object  0-offset fixup ;
-:  1, ( -- )  1 >bignum prepare-object  1-offset fixup ;
-: -1, ( -- ) -1 >bignum prepare-object -1-offset fixup ;
-
 ! Words
 
 : word-sub-primitive ( word -- obj )
@@ -494,7 +483,7 @@ M: quotation prepare-object
 : build-image ( -- image )
     600,000 <vector> bootstrapping-image set
     60,000 <hashtable> objects set
-    emit-image-header t, 0, 1, -1,
+    emit-image-header
     "Building generic words..." print flush
     build-generics
     "Serializing words..." print flush
index 5a99e9accef23c685d950bfad7c083872553acac..58fc5776205626f5bf05a0a670c3cb3e38b89319 100644 (file)
@@ -158,7 +158,7 @@ void factor_vm::primitive_dll_validp() {
   if (to_boolean(library))
     ctx->replace(tag_boolean(untag_check<dll>(library)->handle != NULL));
   else
-    ctx->replace(true_object);
+    ctx->replace(special_objects[OBJ_CANONICAL_TRUE]);
 }
 
 /* gets the address of an object representing a C pointer */
index 9c5640d5a5fcc5c2e12ae43adb0575bf38ff85c5..7003bc189dbc988eabbf507c547952d0e714de35 100644 (file)
@@ -81,8 +81,9 @@ typedef int64_t bignum_twodigit_type;
 
 /* These definitions are here to facilitate caching of the constants
    0, 1, and -1. */
-#define BIGNUM_ZERO() untag<bignum>(bignum_zero)
-#define BIGNUM_ONE(neg_p) untag<bignum>(neg_p ? bignum_neg_one : bignum_pos_one)
+#define BIGNUM_ZERO() untag<bignum>(special_objects[OBJ_BIGNUM_ZERO])
+#define BIGNUM_ONE(neg_p) untag<bignum>(        \
+            special_objects[neg_p ? OBJ_BIGNUM_NEG_ONE : OBJ_BIGNUM_POS_ONE])
 
 #define HD_LOW(digit) ((digit) & BIGNUM_HALF_DIGIT_MASK)
 #define HD_HIGH(digit) ((digit) >> BIGNUM_HALF_DIGIT_LENGTH)
index a58365b4fa8b13630efe23da892dd69405ff0c26..8480ee7bf79e458e3c6f6fa1d582128711aa03c4 100644 (file)
@@ -291,7 +291,7 @@ void factor_vm::primitive_check_datastack() {
         return;
       }
     }
-    ctx->push(true_object);
+    ctx->push(special_objects[OBJ_CANONICAL_TRUE]);
   }
 }
 
index 9abc378eb3d556de2d988efb389a0bdb03ea2839..73c4282ad49723615a2bdea6a4ad7402b47724dd 100644 (file)
@@ -118,7 +118,7 @@ void factor_vm::prepare_boot_image() {
       quot->entry_point = lazy_jit_compile_entry_point();
   }
 
-  special_objects[OBJ_STAGE2] = true_object;
+  special_objects[OBJ_STAGE2] = special_objects[OBJ_CANONICAL_TRUE];
 
   std::cout << "done" << std::endl;
 }
index b1b982aa47aafb5fa4c5fb78257383a1da5346a5..f8a8d07438495d04d1e24de6f6ab0d146ac5a635 100644 (file)
@@ -2,16 +2,6 @@
 
 namespace factor {
 
-/* Certain special objects in the image are known to the runtime */
-void factor_vm::init_objects(image_header* h) {
-  memcpy(special_objects, h->special_objects, sizeof(special_objects));
-
-  true_object = h->true_object;
-  bignum_zero = h->bignum_zero;
-  bignum_pos_one = h->bignum_pos_one;
-  bignum_neg_one = h->bignum_neg_one;
-}
-
 void factor_vm::load_data_heap(FILE* file, image_header* h, vm_parameters* p) {
   p->tenured_size = std::max((h->data_size * 3) / 2, p->tenured_size);
 
@@ -93,7 +83,7 @@ void factor_vm::fixup_data(cell data_offset, cell code_offset) {
         if (to_boolean(ptr->base))
           ptr->update_address();
         else
-          ptr->expired = true_object;
+          ptr->expired = special_objects[OBJ_CANONICAL_TRUE];
         break;
       }
       case DLL_TYPE: {
@@ -183,7 +173,8 @@ void factor_vm::load_image(vm_parameters* p) {
 
   raw_fclose(file);
 
-  init_objects(&h);
+  /* Certain special objects in the image are known to the runtime */
+  memcpy(special_objects, h.special_objects, sizeof(special_objects));
 
   cell data_offset = data->tenured->start - h.data_relocation_base;
   cell code_offset = code->allocator->start - h.code_relocation_base;
@@ -209,11 +200,6 @@ bool factor_vm::save_image(const vm_char* saving_filename,
   h.code_relocation_base = code->allocator->start;
   h.code_size = code->allocator->occupied_space();
 
-  h.true_object = true_object;
-  h.bignum_zero = bignum_zero;
-  h.bignum_pos_one = bignum_pos_one;
-  h.bignum_neg_one = bignum_neg_one;
-
   for (cell i = 0; i < special_object_count; i++)
     h.special_objects[i] =
         (save_special_p(i) ? special_objects[i] : false_object);
index e1a71c67811b2297f9fcfff94d5805247486a1ad..c43e8e9fc740951652f1c32f7d40bf704d960a51 100644 (file)
@@ -21,14 +21,12 @@ struct image_header {
   cell code_relocation_base;
   /* size of code heap */
   cell code_size;
-  /* tagged pointer to t singleton */
-  cell true_object;
-  /* tagged pointer to bignum 0 */
-  cell bignum_zero;
-  /* tagged pointer to bignum 1 */
-  cell bignum_pos_one;
-  /* tagged pointer to bignum -1 */
-  cell bignum_neg_one;
+
+  cell reserved_1;
+  cell reserved_2;
+  cell reserved_3;
+  cell reserved_4;
+
   /* Initial user environment */
   cell special_objects[special_object_count];
 };
index 66152074f58638721879368a9fe80d97d1608a75..2e49d5db50f497e3a947ab76125a6771b5e1ebee 100644 (file)
@@ -193,11 +193,6 @@ void slot_visitor<Fixup>::visit_stack_elements(segment* region, cell* top) {
 }
 
 template <typename Fixup> void slot_visitor<Fixup>::visit_all_roots() {
-  visit_handle(&parent->true_object);
-  visit_handle(&parent->bignum_zero);
-  visit_handle(&parent->bignum_pos_one);
-  visit_handle(&parent->bignum_neg_one);
-
   FACTOR_FOR_EACH(parent->data_roots) {
     visit_handle(*iter);
   }
index 505132ca75a447d802f38d51217230113345964a..c1b63e0ada73c756f90fe1ba3ca1e42cae1584aa 100644 (file)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -66,9 +66,6 @@ struct factor_vm {
   /* Active contexts, for tracing by the GC */
   std::set<context*> active_contexts;
 
-  /* Canonical truth value. In Factor, 't' */
-  cell true_object;
-
   /* External entry points */
   c_to_factor_func_type c_to_factor_func;
 
@@ -130,11 +127,6 @@ struct factor_vm {
   bool fep_disabled;
   bool full_output;
 
-  /* Canonical bignums */
-  cell bignum_zero;
-  cell bignum_pos_one;
-  cell bignum_neg_one;
-
   /* Method dispatch statistics */
   dispatch_statistics dispatch_stats;
 
@@ -439,7 +431,7 @@ struct factor_vm {
 
   // booleans
   cell tag_boolean(cell untagged) {
-    return (untagged ? true_object : false_object);
+    return untagged ? special_objects[OBJ_CANONICAL_TRUE] : false_object;
   }
 
   // byte arrays
@@ -614,7 +606,6 @@ struct factor_vm {
   void primitive_callback_room();
 
   // image
-  void init_objects(image_header* h);
   void load_data_heap(FILE* file, image_header* h, vm_parameters* p);
   void load_code_heap(FILE* file, image_header* h, vm_parameters* p);
   bool save_image(const vm_char* saving_filename, const vm_char* filename);