VM: now special-objects is used for -1, 0, 1 and t

The fields in the image_header aren't read or written to but I haven't
changed the format yet.
db4
Björn Lindqvist 2015-12-10 10:07:57 +01:00
parent 339b1b6466
commit 1a72f731e0
9 changed files with 23 additions and 63 deletions

View File

@ -86,8 +86,8 @@ SYMBOL: objects
: put-object ( n obj -- ) : put-object ( n obj -- )
<eq-wrapper> objects get set-at ; <eq-wrapper> objects get set-at ;
! Constants ! Constants need to be synced with
! vm/image.hpp
CONSTANT: image-magic 0x0f0e0d0c CONSTANT: image-magic 0x0f0e0d0c
CONSTANT: image-version 4 CONSTANT: image-version 4
@ -96,10 +96,6 @@ CONSTANT: data-base 1024
CONSTANT: header-size 10 CONSTANT: header-size 10
CONSTANT: data-heap-size-offset 3 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 SYMBOL: sub-primitives
@ -199,10 +195,10 @@ GENERIC: prepare-object ( obj -- ptr )
0 emit ! size of data heap set later 0 emit ! size of data heap set later
0 emit ! reloc base of code heap is 0 0 emit ! reloc base of code heap is 0
0 emit ! size of code heap is 0 0 emit ! size of code heap is 0
0 emit ! pointer to t object 0 emit ! reserved
0 emit ! pointer to bignum 0 0 emit ! reserved
0 emit ! pointer to bignum 1 0 emit ! reserved
0 emit ! pointer to bignum -1 0 emit ! reserved
special-object-count [ f prepare-object emit ] times ; special-object-count [ f prepare-object emit ] times ;
! Bignums ! Bignums
@ -257,15 +253,8 @@ M: float prepare-object
! Special objects ! Special objects
! Padded with fixnums for 8-byte alignment ! Padded with fixnums for 8-byte alignment
: t, ( -- ) t t-offset fixup ;
M: f prepare-object drop \ f type-number ; 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 ! Words
: word-sub-primitive ( word -- obj ) : word-sub-primitive ( word -- obj )
@ -494,7 +483,7 @@ M: quotation prepare-object
: build-image ( -- image ) : build-image ( -- image )
600,000 <vector> bootstrapping-image set 600,000 <vector> bootstrapping-image set
60,000 <hashtable> objects set 60,000 <hashtable> objects set
emit-image-header t, 0, 1, -1, emit-image-header
"Building generic words..." print flush "Building generic words..." print flush
build-generics build-generics
"Serializing words..." print flush "Serializing words..." print flush

View File

@ -158,7 +158,7 @@ void factor_vm::primitive_dll_validp() {
if (to_boolean(library)) if (to_boolean(library))
ctx->replace(tag_boolean(untag_check<dll>(library)->handle != NULL)); ctx->replace(tag_boolean(untag_check<dll>(library)->handle != NULL));
else else
ctx->replace(true_object); ctx->replace(special_objects[OBJ_CANONICAL_TRUE]);
} }
/* gets the address of an object representing a C pointer */ /* gets the address of an object representing a C pointer */

View File

@ -81,8 +81,9 @@ typedef int64_t bignum_twodigit_type;
/* These definitions are here to facilitate caching of the constants /* These definitions are here to facilitate caching of the constants
0, 1, and -1. */ 0, 1, and -1. */
#define BIGNUM_ZERO() untag<bignum>(bignum_zero) #define BIGNUM_ZERO() untag<bignum>(special_objects[OBJ_BIGNUM_ZERO])
#define BIGNUM_ONE(neg_p) untag<bignum>(neg_p ? bignum_neg_one : bignum_pos_one) #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_LOW(digit) ((digit) & BIGNUM_HALF_DIGIT_MASK)
#define HD_HIGH(digit) ((digit) >> BIGNUM_HALF_DIGIT_LENGTH) #define HD_HIGH(digit) ((digit) >> BIGNUM_HALF_DIGIT_LENGTH)

View File

@ -291,7 +291,7 @@ void factor_vm::primitive_check_datastack() {
return; return;
} }
} }
ctx->push(true_object); ctx->push(special_objects[OBJ_CANONICAL_TRUE]);
} }
} }

View File

@ -118,7 +118,7 @@ void factor_vm::prepare_boot_image() {
quot->entry_point = lazy_jit_compile_entry_point(); 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; std::cout << "done" << std::endl;
} }

View File

@ -2,16 +2,6 @@
namespace factor { 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) { 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); 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)) if (to_boolean(ptr->base))
ptr->update_address(); ptr->update_address();
else else
ptr->expired = true_object; ptr->expired = special_objects[OBJ_CANONICAL_TRUE];
break; break;
} }
case DLL_TYPE: { case DLL_TYPE: {
@ -183,7 +173,8 @@ void factor_vm::load_image(vm_parameters* p) {
raw_fclose(file); 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 data_offset = data->tenured->start - h.data_relocation_base;
cell code_offset = code->allocator->start - h.code_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_relocation_base = code->allocator->start;
h.code_size = code->allocator->occupied_space(); 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++) for (cell i = 0; i < special_object_count; i++)
h.special_objects[i] = h.special_objects[i] =
(save_special_p(i) ? special_objects[i] : false_object); (save_special_p(i) ? special_objects[i] : false_object);

View File

@ -21,14 +21,12 @@ struct image_header {
cell code_relocation_base; cell code_relocation_base;
/* size of code heap */ /* size of code heap */
cell code_size; cell code_size;
/* tagged pointer to t singleton */
cell true_object; cell reserved_1;
/* tagged pointer to bignum 0 */ cell reserved_2;
cell bignum_zero; cell reserved_3;
/* tagged pointer to bignum 1 */ cell reserved_4;
cell bignum_pos_one;
/* tagged pointer to bignum -1 */
cell bignum_neg_one;
/* Initial user environment */ /* Initial user environment */
cell special_objects[special_object_count]; cell special_objects[special_object_count];
}; };

View 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() { 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) { FACTOR_FOR_EACH(parent->data_roots) {
visit_handle(*iter); visit_handle(*iter);
} }

View File

@ -66,9 +66,6 @@ struct factor_vm {
/* Active contexts, for tracing by the GC */ /* Active contexts, for tracing by the GC */
std::set<context*> active_contexts; std::set<context*> active_contexts;
/* Canonical truth value. In Factor, 't' */
cell true_object;
/* External entry points */ /* External entry points */
c_to_factor_func_type c_to_factor_func; c_to_factor_func_type c_to_factor_func;
@ -130,11 +127,6 @@ struct factor_vm {
bool fep_disabled; bool fep_disabled;
bool full_output; bool full_output;
/* Canonical bignums */
cell bignum_zero;
cell bignum_pos_one;
cell bignum_neg_one;
/* Method dispatch statistics */ /* Method dispatch statistics */
dispatch_statistics dispatch_stats; dispatch_statistics dispatch_stats;
@ -439,7 +431,7 @@ struct factor_vm {
// booleans // booleans
cell tag_boolean(cell untagged) { cell tag_boolean(cell untagged) {
return (untagged ? true_object : false_object); return untagged ? special_objects[OBJ_CANONICAL_TRUE] : false_object;
} }
// byte arrays // byte arrays
@ -614,7 +606,6 @@ struct factor_vm {
void primitive_callback_room(); void primitive_callback_room();
// image // image
void init_objects(image_header* h);
void load_data_heap(FILE* file, image_header* h, vm_parameters* p); void load_data_heap(FILE* file, image_header* h, vm_parameters* p);
void load_code_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); bool save_image(const vm_char* saving_filename, const vm_char* filename);