6 /* Compile a word definition with the non-optimizing compiler. Allocates memory */
7 void factor_vm::jit_compile_word(cell word_, cell def_, bool relocating)
9 data_root<word> word(word_,this);
10 data_root<quotation> def(def_,this);
12 /* Refuse to compile this word more than once, because quot_compiled_p()
13 depends on the identity of its code block */
14 if(word->code && word.value() == special_objects[LAZY_JIT_COMPILE_WORD])
17 code_block *compiled = jit_compile_quot(word.value(),def.value(),relocating);
18 word->code = compiled;
20 if(to_boolean(word->pic_def)) jit_compile_quot(word->pic_def,relocating);
21 if(to_boolean(word->pic_tail_def)) jit_compile_quot(word->pic_tail_def,relocating);
24 cell factor_vm::find_all_words()
26 return instances(WORD_TYPE);
29 void factor_vm::compile_all_words()
31 data_root<array> words(find_all_words(),this);
33 cell length = array_capacity(words.untagged());
34 for(cell i = 0; i < length; i++)
36 data_root<word> word(array_nth(words.untagged(),i),this);
38 if(!word->code || !word->code->optimized_p())
39 jit_compile_word(word.value(),word->def,false);
41 update_word_entry_point(word.untagged());
45 word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_)
47 data_root<object> vocab(vocab_,this);
48 data_root<object> name(name_,this);
50 data_root<word> new_word(allot<word>(sizeof(word)),this);
52 new_word->hashcode = hashcode_;
53 new_word->vocabulary = vocab.value();
54 new_word->name = name.value();
55 new_word->def = special_objects[OBJ_UNDEFINED];
56 new_word->props = false_object;
57 new_word->counter = tag_fixnum(0);
58 new_word->pic_def = false_object;
59 new_word->pic_tail_def = false_object;
60 new_word->subprimitive = false_object;
61 new_word->profiling = NULL;
62 new_word->code = NULL;
64 jit_compile_word(new_word.value(),new_word->def,true);
65 if(counting_profiler_p)
67 code_block *profiling_block = compile_profiling_stub(new_word.value());
68 new_word->profiling = profiling_block;
69 initialize_code_block(new_word->profiling);
72 update_word_entry_point(new_word.untagged());
74 return new_word.untagged();
77 /* (word) ( name vocabulary hashcode -- word ) */
78 void factor_vm::primitive_word()
80 cell hashcode = ctx->pop();
81 cell vocab = ctx->pop();
82 cell name = ctx->pop();
83 ctx->push(tag<word>(allot_word(name,vocab,hashcode)));
86 /* word-code ( word -- start end ) */
87 void factor_vm::primitive_word_code()
89 data_root<word> w(ctx->pop(),this);
92 if(counting_profiler_p)
94 ctx->push(from_unsigned_cell((cell)w->profiling->entry_point()));
95 ctx->push(from_unsigned_cell((cell)w->profiling + w->profiling->size()));
99 ctx->push(from_unsigned_cell((cell)w->code->entry_point()));
100 ctx->push(from_unsigned_cell((cell)w->code + w->code->size()));
104 void factor_vm::update_word_entry_point(word *w)
106 if(counting_profiler_p && w->profiling)
107 w->entry_point = w->profiling->entry_point();
109 w->entry_point = w->code->entry_point();
112 void factor_vm::primitive_optimized_p()
114 word *w = untag_check<word>(ctx->peek());
115 ctx->replace(tag_boolean(w->code->optimized_p()));
118 void factor_vm::primitive_wrapper()
120 wrapper *new_wrapper = allot<wrapper>(sizeof(wrapper));
121 new_wrapper->object = ctx->peek();
122 ctx->replace(tag<wrapper>(new_wrapper));