VM: refactors the prepare_boot_image method
easier to read if the methods compile_all_words and initialize_all_quotations which are only used once are "inlined"db4
							parent
							
								
									bf8fe25271
								
							
						
					
					
						commit
						d911bc45fd
					
				| 
						 | 
					@ -95,9 +95,29 @@ void factor_vm::init_parameters_from_args(vm_parameters* p, int argc,
 | 
				
			||||||
void factor_vm::prepare_boot_image() {
 | 
					void factor_vm::prepare_boot_image() {
 | 
				
			||||||
  std::cout << "*** Stage 2 early init... " << std::flush;
 | 
					  std::cout << "*** Stage 2 early init... " << std::flush;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  compile_all_words();
 | 
					  // Compile all words.
 | 
				
			||||||
 | 
					  data_root<array> words(instances(WORD_TYPE), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cell n_words = array_capacity(words.untagged());
 | 
				
			||||||
 | 
					  for (cell i = 0; i < n_words; i++) {
 | 
				
			||||||
 | 
					    data_root<word> word(array_nth(words.untagged(), i), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    FACTOR_ASSERT(!word->entry_point);
 | 
				
			||||||
 | 
					    jit_compile_word(word.value(), word->def, false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  update_code_heap_words(true);
 | 
					  update_code_heap_words(true);
 | 
				
			||||||
  initialize_all_quotations();
 | 
					
 | 
				
			||||||
 | 
					  // Initialize all quotations
 | 
				
			||||||
 | 
					  data_root<array> quotations(instances(QUOTATION_TYPE), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cell n_quots = array_capacity(quotations.untagged());
 | 
				
			||||||
 | 
					  for (cell i = 0; i < n_quots; i++) {
 | 
				
			||||||
 | 
					    data_root<quotation> quot(array_nth(quotations.untagged(), i), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!quot->entry_point)
 | 
				
			||||||
 | 
					      quot->entry_point = lazy_jit_compile_entry_point();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  special_objects[OBJ_STAGE2] = true_object;
 | 
					  special_objects[OBJ_STAGE2] = true_object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::cout << "done" << std::endl;
 | 
					  std::cout << "done" << std::endl;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -364,17 +364,4 @@ void factor_vm::primitive_quotation_compiled_p() {
 | 
				
			||||||
  ctx->push(tag_boolean(quotation_compiled_p(quot)));
 | 
					  ctx->push(tag_boolean(quotation_compiled_p(quot)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory */
 | 
					 | 
				
			||||||
void factor_vm::initialize_all_quotations() {
 | 
					 | 
				
			||||||
  cell all_quots = instances(QUOTATION_TYPE);
 | 
					 | 
				
			||||||
  data_root<array> quotations(all_quots, this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  cell length = array_capacity(quotations.untagged());
 | 
					 | 
				
			||||||
  for (cell i = 0; i < length; i++) {
 | 
					 | 
				
			||||||
    data_root<quotation> quot(array_nth(quotations.untagged(), i), this);
 | 
					 | 
				
			||||||
    if (!quot->entry_point)
 | 
					 | 
				
			||||||
      quot.untagged()->entry_point = lazy_jit_compile_entry_point();
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -461,8 +461,6 @@ struct factor_vm {
 | 
				
			||||||
  void primitive_word_optimized_p();
 | 
					  void primitive_word_optimized_p();
 | 
				
			||||||
  void primitive_wrapper();
 | 
					  void primitive_wrapper();
 | 
				
			||||||
  void jit_compile_word(cell word_, cell def_, bool relocating);
 | 
					  void jit_compile_word(cell word_, cell def_, bool relocating);
 | 
				
			||||||
  cell find_all_words();
 | 
					 | 
				
			||||||
  void compile_all_words();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // math
 | 
					  // math
 | 
				
			||||||
  void primitive_bignum_to_fixnum();
 | 
					  void primitive_bignum_to_fixnum();
 | 
				
			||||||
| 
						 | 
					@ -683,7 +681,6 @@ struct factor_vm {
 | 
				
			||||||
  cell lazy_jit_compile(cell quot);
 | 
					  cell lazy_jit_compile(cell quot);
 | 
				
			||||||
  bool quotation_compiled_p(quotation* quot);
 | 
					  bool quotation_compiled_p(quotation* quot);
 | 
				
			||||||
  void primitive_quotation_compiled_p();
 | 
					  void primitive_quotation_compiled_p();
 | 
				
			||||||
  void initialize_all_quotations();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // dispatch
 | 
					  // dispatch
 | 
				
			||||||
  cell search_lookup_alist(cell table, cell klass);
 | 
					  cell search_lookup_alist(cell table, cell klass);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								vm/words.cpp
								
								
								
								
							
							
						
						
									
										16
									
								
								vm/words.cpp
								
								
								
								
							| 
						 | 
					@ -24,22 +24,6 @@ void factor_vm::jit_compile_word(cell word_, cell def_, bool relocating) {
 | 
				
			||||||
    jit_compile_quotation(word->pic_tail_def, relocating);
 | 
					    jit_compile_quotation(word->pic_tail_def, relocating);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Allocates memory */
 | 
					 | 
				
			||||||
cell factor_vm::find_all_words() { return instances(WORD_TYPE); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Allocates memory */
 | 
					 | 
				
			||||||
void factor_vm::compile_all_words() {
 | 
					 | 
				
			||||||
  data_root<array> words(find_all_words(), this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  cell length = array_capacity(words.untagged());
 | 
					 | 
				
			||||||
  for (cell i = 0; i < length; i++) {
 | 
					 | 
				
			||||||
    data_root<word> word(array_nth(words.untagged(), i), this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!word->entry_point || !word->code()->optimized_p())
 | 
					 | 
				
			||||||
      jit_compile_word(word.value(), word->def, false);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Allocates memory */
 | 
					/* Allocates memory */
 | 
				
			||||||
word* factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) {
 | 
					word* factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) {
 | 
				
			||||||
  data_root<object> vocab(vocab_, this);
 | 
					  data_root<object> vocab(vocab_, this);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue