: 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
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
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
! 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 )
: 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
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 */
/* 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)
return;
}
}
- ctx->push(true_object);
+ ctx->push(special_objects[OBJ_CANONICAL_TRUE]);
}
}
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;
}
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);
if (to_boolean(ptr->base))
ptr->update_address();
else
- ptr->expired = true_object;
+ ptr->expired = special_objects[OBJ_CANONICAL_TRUE];
break;
}
case DLL_TYPE: {
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;
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);
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];
};
}
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);
}
/* 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;
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;
// booleans
cell tag_boolean(cell untagged) {
- return (untagged ? true_object : false_object);
+ return untagged ? special_objects[OBJ_CANONICAL_TRUE] : false_object;
}
// byte arrays
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);