factor/native/word.c

67 lines
1.5 KiB
C
Raw Normal View History

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. */
void update_xt(F_WORD* word)
2004-07-16 02:26:21 -04:00
{
word->xt = primitive_to_xt(untag_fixnum_fast(word->primitive));
2004-07-16 02:26:21 -04:00
}
/* <word> ( name vocabulary -- word ) */
2004-07-16 02:26:21 -04:00
void primitive_word(void)
{
F_WORD *word;
CELL name, vocabulary;
2005-06-16 18:50:49 -04:00
maybe_gc(sizeof(F_WORD));
vocabulary = dpop();
name = dpop();
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 */
word->name = name;
word->vocabulary = vocabulary;
word->primitive = tag_fixnum(0);
word->def = F;
2005-11-27 17:45:48 -05:00
word->props = F;
word->xt = (CELL)undefined;
dpush(tag_object(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
{
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
}
void fixup_word(F_WORD* word)
2004-07-16 02:26:21 -04:00
{
2005-03-29 20:34:29 -05:00
/* If this is a compiled word, relocate the code pointer. Otherwise,
reset it based on the primitive number of the word. */
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->name);
data_fixup(&word->vocabulary);
data_fixup(&word->def);
data_fixup(&word->props);
2004-07-16 02:26:21 -04:00
}
void collect_word(F_WORD* word)
2004-07-16 02:26:21 -04:00
{
copy_handle(&word->name);
copy_handle(&word->vocabulary);
2005-05-12 01:02:39 -04:00
copy_handle(&word->def);
copy_handle(&word->props);
2004-07-16 02:26:21 -04:00
}