#include "master.hpp" namespace factor { word *factor_vm::allot_word(cell name_, cell vocab_, cell hashcode_) { data_root vocab(vocab_,this); data_root name(name_,this); data_root new_word(allot(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); update_word_xt(new_word.untagged()); if(profiling_p) relocate_code_block(new_word->profiling); return new_word.untagged(); } /* (word) ( name vocabulary hashcode -- word ) */ void factor_vm::primitive_word() { cell hashcode = dpop(); cell vocab = dpop(); cell name = dpop(); dpush(tag(allot_word(name,vocab,hashcode))); } /* word-xt ( word -- start end ) */ void factor_vm::primitive_word_xt() { data_root w(dpop(),this); w.untag_check(this); if(profiling_p) { dpush(allot_cell((cell)w->profiling->xt())); dpush(allot_cell((cell)w->profiling + w->profiling->size())); } else { dpush(allot_cell((cell)w->code->xt())); dpush(allot_cell((cell)w->code + w->code->size())); } } /* Allocates memory */ void factor_vm::update_word_xt(word *w_) { data_root w(w_,this); if(profiling_p) { if(!w->profiling) { /* Note: can't do w->profiling = ... since LHS evaluates before RHS, and if RHS does a GC, we will have an invalid pointer on the LHS */ code_block *profiling = compile_profiling_stub(w.value()); w->profiling = profiling; } w->xt = w->profiling->xt(); } else w->xt = w->code->xt(); } void factor_vm::primitive_optimized_p() { word *w = untag_check(dpeek()); drepl(tag_boolean(w->code->optimized_p())); } void factor_vm::primitive_wrapper() { wrapper *new_wrapper = allot(sizeof(wrapper)); new_wrapper->object = dpeek(); drepl(tag(new_wrapper)); } }