]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: put the singletons t, -1, 0 and 1 in the special objects table
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 9 Dec 2015 20:31:13 +0000 (21:31 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 9 Dec 2015 20:31:13 +0000 (21:31 +0100)
Having them there instead of as fields in the vm struct removes a bunch
of special handling. This commit just adds them and doesn't remove the
old ones to avoid potential chicken-and-egg bootstrap problems.

basis/bootstrap/image/image-tests.factor
basis/bootstrap/image/image.factor
core/kernel/kernel.factor
vm/objects.hpp

index 2e91ce40993221feafe17bdabc6233c1ce174fc5..d41d676ca94ba3b46d1a0ec7899a2470b2bfb82c 100644 (file)
@@ -31,6 +31,26 @@ IN: bootstrap.image.tests
     H{ } [ special-objects set emit-jit-data ] keep assoc-size
 ] unit-test
 
-{ 90 } [
+{ 95 } [
     50 <vector> [ bootstrapping-image set emit-image-header ] keep length
 ] unit-test
+
+! emit-bignum
+{ V{
+    ! 33 bignum
+    32 0 33
+    ! -108 bignum
+    32 1 108
+} } [
+    V{ } bootstrapping-image set
+    33 emit-bignum
+    -108 emit-bignum
+    bootstrapping-image get
+] unit-test
+
+! prepare-object - what does this mean?
+{ 269 } [
+    V{ } clone bootstrapping-image set
+    H{ } clone objects set
+    55 >bignum prepare-object
+] unit-test
index e407d0399f6add6db4bbcda716aa98ba88d471c9..44d8e5cf172997ccba35093df6f85bc0762573b1 100755 (executable)
@@ -433,6 +433,12 @@ M: quotation prepare-object
 : emit-words ( -- )
     all-words [ emit-word ] each ;
 
+: emit-singletons ( -- )
+    t OBJ-CANONICAL-TRUE special-objects get set-at
+    0 >bignum OBJ-BIGNUM-ZERO special-objects get set-at
+    1 >bignum OBJ-BIGNUM-POS-ONE special-objects get set-at
+    -1 >bignum OBJ-BIGNUM-NEG-ONE special-objects get set-at ;
+
 : emit-global ( -- )
     {
         dictionary source-files builtins
@@ -497,6 +503,8 @@ M: quotation prepare-object
     emit-jit-data
     "Serializing global namespace..." print flush
     emit-global
+    "Serializing singletons..." print flush
+    emit-singletons
     "Serializing special object table..." print flush
     emit-special-objects
     "Performing word fixups..." print flush
index 611ba18d97d38ff19e7f6e18198b98bc0e95f8b0..7821a6abeab0d02f151f5055684d8ed2515d5eec 100644 (file)
@@ -309,8 +309,7 @@ ERROR: assert got expect ;
 
 ! Special object count and identifiers must be kept in sync with:
 !   vm/objects.hpp
-!   basis/bootstrap/image/image.factor
-CONSTANT: special-object-count 80
+CONSTANT: special-object-count 85
 
 CONSTANT: OBJ-WALKER-HOOK 3
 
@@ -409,6 +408,12 @@ CONSTANT: OBJ-VM-COMPILE-TIME 75
 CONSTANT: OBJ-VM-VERSION 76
 CONSTANT: OBJ-VM-GIT-LABEL 77
 
+CONSTANT: OBJ-CANONICAL-TRUE 78
+
+CONSTANT: OBJ-BIGNUM-ZERO 79
+CONSTANT: OBJ-BIGNUM-POS-ONE 80
+CONSTANT: OBJ-BIGNUM-NEG-ONE 81
+
 ! Context object count and identifiers must be kept in sync with:
 !   vm/contexts.hpp
 
index 9696be26276f5af72687b84d006cf1521d1dcc25..dc29b0382a62543a0f6093ee68936452f43c6da5 100644 (file)
@@ -4,7 +4,7 @@ namespace factor {
 //   core/kernel/kernel.factor
 //   basis/bootstrap/image/image.factor
 
-static const cell special_object_count = 80;
+static const cell special_object_count = 85;
 
 enum special_object {
   OBJ_WALKER_HOOK = 3, /* non-local exit hook, used by library only */
@@ -110,6 +110,15 @@ enum special_object {
   OBJ_VM_COMPILE_TIME = 75, /* when the binary was built */
   OBJ_VM_VERSION = 76, /* factor version */
   OBJ_VM_GIT_LABEL = 77, /* git label (git describe --all --long) */
+
+  /* Canonical truth value. In Factor, 't' */
+  OBJ_CANONICAL_TRUE = 78,
+
+  /* Canonical bignums. These needs to be kept in the image in case
+     some heap objects refer to them. */
+  OBJ_BIGNUM_ZERO,
+  OBJ_BIGNUM_POS_ONE,
+  OBJ_BIGNUM_NEG_ONE = 81,
 };
 
 /* save-image-and-exit discards special objects that are filled in on startup
@@ -118,7 +127,9 @@ enum special_object {
 #define OBJ_LAST_SAVE OBJ_STAGE2
 
 inline static bool save_special_p(cell i) {
-  return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE);
+  /* Need to fix the order here. */
+  return (i >= OBJ_FIRST_SAVE && i <= OBJ_LAST_SAVE) ||
+      (i >= OBJ_CANONICAL_TRUE);
 }
 
 template <typename Iterator> void object::each_slot(Iterator& iter) {