2009-05-02 05:04:19 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2009-05-04 02:46:13 -04:00
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-05-02 10:19:09 -04:00
|
|
|
F_WORD *allot_word(CELL vocab_, CELL name_)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 10:19:09 -04:00
|
|
|
gc_root<F_OBJECT> vocab(vocab_);
|
|
|
|
gc_root<F_OBJECT> name(name_);
|
|
|
|
|
|
|
|
gc_root<F_WORD> word(allot<F_WORD>(sizeof(F_WORD)));
|
2009-05-02 05:04:19 -04:00
|
|
|
|
|
|
|
word->hashcode = tag_fixnum((rand() << 16) ^ rand());
|
2009-05-02 10:19:09 -04:00
|
|
|
word->vocabulary = vocab.value();
|
|
|
|
word->name = name.value();
|
2009-05-02 05:04:19 -04:00
|
|
|
word->def = userenv[UNDEFINED_ENV];
|
|
|
|
word->props = F;
|
|
|
|
word->counter = tag_fixnum(0);
|
|
|
|
word->direct_entry_def = F;
|
|
|
|
word->subprimitive = F;
|
|
|
|
word->profiling = NULL;
|
|
|
|
word->code = NULL;
|
|
|
|
|
2009-05-02 10:19:09 -04:00
|
|
|
jit_compile_word(word.value(),word->def,true);
|
|
|
|
update_word_xt(word.value());
|
2009-05-02 05:04:19 -04:00
|
|
|
|
|
|
|
if(profiling_p)
|
|
|
|
relocate_code_block(word->profiling);
|
|
|
|
|
2009-05-02 10:19:09 -04:00
|
|
|
return word.untagged();
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* <word> ( name vocabulary -- word ) */
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(word)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
CELL vocab = dpop();
|
|
|
|
CELL name = dpop();
|
2009-05-02 21:47:29 -04:00
|
|
|
dpush(tag<F_WORD>(allot_word(vocab,name)));
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* word-xt ( word -- start end ) */
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(word_xt)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
F_WORD *word = untag_check<F_WORD>(dpop());
|
2009-05-02 05:04:19 -04:00
|
|
|
F_CODE_BLOCK *code = (profiling_p ? word->profiling : word->code);
|
|
|
|
dpush(allot_cell((CELL)code + sizeof(F_CODE_BLOCK)));
|
|
|
|
dpush(allot_cell((CELL)code + code->block.size));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocates memory */
|
2009-05-02 10:19:09 -04:00
|
|
|
void update_word_xt(CELL word_)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 10:19:09 -04:00
|
|
|
gc_root<F_WORD> word(word_);
|
|
|
|
|
2009-05-02 05:04:19 -04:00
|
|
|
if(profiling_p)
|
|
|
|
{
|
|
|
|
if(!word->profiling)
|
|
|
|
{
|
2009-05-02 10:19:09 -04:00
|
|
|
F_CODE_BLOCK *profiling = compile_profiling_stub(word.value());
|
2009-05-02 05:04:19 -04:00
|
|
|
word->profiling = profiling;
|
|
|
|
}
|
|
|
|
|
|
|
|
word->xt = (XT)(word->profiling + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
word->xt = (XT)(word->code + 1);
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(optimized_p)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
drepl(tag_boolean(word_optimized_p(untag_check<F_WORD>(dpeek()))));
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(wrapper)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 10:19:09 -04:00
|
|
|
F_WRAPPER *wrapper = allot<F_WRAPPER>(sizeof(F_WRAPPER));
|
2009-05-02 05:04:19 -04:00
|
|
|
wrapper->object = dpeek();
|
2009-05-02 21:47:29 -04:00
|
|
|
drepl(tag<F_WRAPPER>(wrapper));
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
2009-05-04 02:46:13 -04:00
|
|
|
|
|
|
|
}
|