2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
2004-08-05 15:18:31 -04:00
|
|
|
WORD* word(CELL primitive, CELL parameter, CELL plist)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
2004-08-05 16:49:55 -04:00
|
|
|
WORD* word = allot_object(WORD_TYPE,sizeof(WORD));
|
2004-08-29 04:03:16 -04:00
|
|
|
word->hashcode = (CELL)word; /* initial address */
|
2004-07-16 02:26:21 -04:00
|
|
|
word->xt = primitive_to_xt(primitive);
|
|
|
|
word->primitive = primitive;
|
|
|
|
word->parameter = parameter;
|
|
|
|
word->plist = plist;
|
2004-08-23 01:13:09 -04:00
|
|
|
word->call_count = 0;
|
2004-08-29 04:03:16 -04:00
|
|
|
word->allot_count = 0;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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(WORD* word)
|
|
|
|
{
|
|
|
|
word->xt = primitive_to_xt(word->primitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <word> ( primitive parameter plist -- word ) */
|
|
|
|
void primitive_word(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
CELL plist = dpop();
|
2004-07-16 02:26:21 -04:00
|
|
|
FIXNUM primitive;
|
|
|
|
CELL parameter = dpop();
|
2004-07-29 17:18:41 -04:00
|
|
|
primitive = to_fixnum(dpop());
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(tag_word(word(primitive,parameter,plist)));
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-08-29 04:03:16 -04:00
|
|
|
void primitive_word_hashcode(void)
|
|
|
|
{
|
|
|
|
drepl(tag_fixnum(untag_word(dpeek())->hashcode));
|
|
|
|
}
|
|
|
|
|
2004-09-06 02:32:04 -04:00
|
|
|
void primitive_word_xt(void)
|
|
|
|
{
|
|
|
|
drepl(tag_cell(untag_word(dpeek())->xt));
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_xt(void)
|
|
|
|
{
|
|
|
|
WORD* word = untag_word(dpop());
|
2004-09-19 17:39:28 -04:00
|
|
|
word->xt = unbox_integer();
|
2004-09-06 02:32:04 -04:00
|
|
|
}
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
void primitive_word_primitive(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(tag_fixnum(untag_word(dpeek())->primitive));
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_primitive(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
WORD* word = untag_word(dpop());
|
2004-07-29 17:18:41 -04:00
|
|
|
word->primitive = to_fixnum(dpop());
|
2004-07-16 02:26:21 -04:00
|
|
|
update_xt(word);
|
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_word_parameter(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(untag_word(dpeek())->parameter);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_parameter(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
WORD* word = untag_word(dpop());
|
|
|
|
word->parameter = dpop();
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_word_plist(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
drepl(untag_word(dpeek())->plist);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_plist(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
WORD* word = untag_word(dpop());
|
|
|
|
word->plist = dpop();
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-08-23 01:13:09 -04:00
|
|
|
void primitive_word_call_count(void)
|
|
|
|
{
|
2004-09-06 02:32:04 -04:00
|
|
|
drepl(tag_cell(untag_word(dpeek())->call_count));
|
2004-08-23 01:13:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_call_count(void)
|
|
|
|
{
|
|
|
|
WORD* word = untag_word(dpop());
|
|
|
|
word->call_count = to_fixnum(dpop());
|
|
|
|
}
|
|
|
|
|
2004-08-29 03:20:19 -04:00
|
|
|
void primitive_word_allot_count(void)
|
|
|
|
{
|
2004-09-06 02:32:04 -04:00
|
|
|
drepl(tag_cell(untag_word(dpeek())->allot_count));
|
2004-08-29 03:20:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_set_word_allot_count(void)
|
|
|
|
{
|
|
|
|
WORD* word = untag_word(dpop());
|
|
|
|
word->allot_count = to_fixnum(dpop());
|
|
|
|
}
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
void fixup_word(WORD* word)
|
|
|
|
{
|
2004-09-08 02:31:03 -04:00
|
|
|
update_xt(word);
|
2004-07-16 02:26:21 -04:00
|
|
|
fixup(&word->parameter);
|
|
|
|
fixup(&word->plist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_word(WORD* word)
|
|
|
|
{
|
|
|
|
copy_object(&word->parameter);
|
|
|
|
copy_object(&word->plist);
|
|
|
|
}
|