word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) { data_root<object> vocab(vocab_,this); data_root<object> name(name_,this); data_root<word> new_word(allot<word>(sizeof(word)),this); new_word->hashcode = hashcode_; new_word->vocabulary = vocab.value(); new_word->name = name.value(); new_word->def = special_objects[OBJ_UNDEFINED]; new_word->props = false_object; new_word->counter = tag_fixnum(0); new_word->pic_def = false_object; new_word->pic_tail_def = false_object; new_word->subprimitive = false_object; new_word->profiling = NULL; new_word->code = NULL; jit_compile_word(new_word.value(),new_word->def,true); if(counting_profiler_p) { code_block *profiling_block = compile_profiling_stub(new_word.value()); new_word->profiling = profiling_block; initialize_code_block(new_word->profiling); } update_word_entry_point(new_word.untagged()); return new_word.untagged(); }
void factor_vm::primitive_modify_code_heap() { bool reset_inline_caches = to_boolean(ctx->pop()); bool update_existing_words = to_boolean(ctx->pop()); data_root<array> alist(ctx->pop(),this); cell count = array_capacity(alist.untagged()); if(count == 0) return; for(cell i = 0; i < count; i++) { data_root<array> pair(array_nth(alist.untagged(),i),this); data_root<word> word(array_nth(pair.untagged(),0),this); data_root<object> data(array_nth(pair.untagged(),1),this); switch(data.type()) { case QUOTATION_TYPE: jit_compile_word(word.value(),data.value(),false); break; case ARRAY_TYPE: { array *compiled_data = data.as<array>().untagged(); cell parameters = array_nth(compiled_data,0); cell literals = array_nth(compiled_data,1); cell relocation = array_nth(compiled_data,2); cell labels = array_nth(compiled_data,3); cell code = array_nth(compiled_data,4); code_block *compiled = add_code_block( code_block_optimized, code, labels, word.value(), relocation, parameters, literals); word->code = compiled; } break; default: critical_error("Expected a quotation or an array",data.value()); break; } update_word_entry_point(word.untagged()); } if(update_existing_words) update_code_heap_words(reset_inline_caches); else initialize_code_blocks(); }
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->code || !word->code->optimized_p()) jit_compile_word(word.value(),word->def,false); update_word_entry_point(word.untagged()); } }