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
							parent
							
								
									339b1b6466
								
							
						
					
					
						commit
						1a72f731e0
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -291,7 +291,7 @@ void factor_vm::primitive_check_datastack() {
 | 
			
		|||
        return;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    ctx->push(true_object);
 | 
			
		||||
    ctx->push(special_objects[OBJ_CANONICAL_TRUE]);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										20
									
								
								vm/image.cpp
								
								
								
								
							
							
						
						
									
										20
									
								
								vm/image.cpp
								
								
								
								
							| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								vm/image.hpp
								
								
								
								
							
							
						
						
									
										14
									
								
								vm/image.hpp
								
								
								
								
							| 
						 | 
				
			
			@ -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];
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								vm/vm.hpp
								
								
								
								
							
							
						
						
									
										11
									
								
								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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue