2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
/* When a word is executed we jump to the value of the xt field. However this
|
|
|
|
value is an unportable function pointer, so in the image we store a primitive
|
|
|
|
number that indexes a list of xts. */
|
2004-12-10 21:46:42 -05:00
|
|
|
void update_xt(F_WORD* word)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
|
|
|
word->xt = primitive_to_xt(word->primitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <word> ( primitive parameter plist -- word ) */
|
|
|
|
void primitive_word(void)
|
|
|
|
{
|
2004-12-24 02:52:02 -05:00
|
|
|
F_WORD* word;
|
2004-10-12 23:49:43 -04:00
|
|
|
|
|
|
|
maybe_garbage_collection();
|
|
|
|
|
2004-12-24 02:52:02 -05:00
|
|
|
word = allot_object(WORD_TYPE,sizeof(F_WORD));
|
2004-12-27 22:58:43 -05:00
|
|
|
word->hashcode = tag_fixnum((CELL)word); /* initial address */
|
2004-12-24 02:52:02 -05:00
|
|
|
word->xt = (CELL)undefined;
|
|
|
|
word->primitive = 0;
|
|
|
|
word->parameter = F;
|
|
|
|
word->plist = F;
|
|
|
|
word->call_count = 0;
|
|
|
|
word->allot_count = 0;
|
|
|
|
dpush(tag_word(word));
|
2004-08-23 01:13:09 -04:00
|
|
|
}
|
|
|
|
|
2004-12-24 02:52:02 -05:00
|
|
|
void primitive_update_xt(void)
|
2004-08-29 03:20:19 -04:00
|
|
|
{
|
2004-12-24 02:52:02 -05:00
|
|
|
update_xt(untag_word(dpop()));
|
2004-08-29 03:20:19 -04:00
|
|
|
}
|
|
|
|
|
2004-12-24 02:52:02 -05:00
|
|
|
void primitive_word_compiledp(void)
|
2004-08-29 03:20:19 -04:00
|
|
|
{
|
2004-12-10 21:46:42 -05:00
|
|
|
F_WORD* word = untag_word(dpop());
|
2004-12-24 02:52:02 -05:00
|
|
|
box_boolean(word->xt != (CELL)docol && word->xt != (CELL)dosym);
|
2004-08-29 03:20:19 -04:00
|
|
|
}
|
|
|
|
|
2004-12-24 02:52:02 -05:00
|
|
|
void primitive_to_word(void)
|
2004-10-04 23:58:53 -04:00
|
|
|
{
|
2004-12-24 02:52:02 -05:00
|
|
|
type_check(WORD_TYPE,dpeek());
|
2004-10-04 23:58:53 -04:00
|
|
|
}
|
|
|
|
|
2004-12-10 21:46:42 -05:00
|
|
|
void fixup_word(F_WORD* word)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
2004-12-25 02:55:03 -05:00
|
|
|
if(word->xt >= code_relocation_base
|
|
|
|
&& word->xt < code_relocation_base
|
|
|
|
- compiling.base + compiling.limit)
|
|
|
|
code_fixup(&word->xt);
|
|
|
|
else
|
|
|
|
update_xt(word);
|
|
|
|
|
|
|
|
data_fixup(&word->parameter);
|
|
|
|
data_fixup(&word->plist);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-12-10 21:46:42 -05:00
|
|
|
void collect_word(F_WORD* word)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
|
|
|
copy_object(&word->parameter);
|
|
|
|
copy_object(&word->plist);
|
|
|
|
}
|