2004-07-16 02:26:21 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
void clear_environment(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < USER_ENV; i++)
|
2004-10-27 21:21:31 -04:00
|
|
|
userenv[i] = F;
|
2004-08-23 18:46:46 -04:00
|
|
|
profile_depth = 0;
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
2004-07-27 23:29:37 -04:00
|
|
|
#define EXECUTE(w) ((XT)(w->xt))()
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
void run(void)
|
|
|
|
{
|
|
|
|
CELL next;
|
|
|
|
|
|
|
|
/* Error handling. */
|
2004-08-16 21:25:01 -04:00
|
|
|
sigsetjmp(toplevel, 1);
|
2004-10-31 14:36:42 -05:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
for(;;)
|
|
|
|
{
|
2004-08-20 18:48:08 -04:00
|
|
|
if(callframe == F)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
2004-08-20 18:48:08 -04:00
|
|
|
callframe = cpop();
|
2004-08-23 01:13:09 -04:00
|
|
|
cpop();
|
2004-07-16 02:26:21 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-08-20 18:48:08 -04:00
|
|
|
callframe = (CELL)untag_cons(callframe);
|
|
|
|
next = get(callframe);
|
|
|
|
callframe = get(callframe + CELLS);
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
if(TAG(next) == WORD_TYPE)
|
|
|
|
{
|
2004-08-20 18:48:08 -04:00
|
|
|
executing = (WORD*)UNTAG(next);
|
|
|
|
EXECUTE(executing);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
else
|
2004-08-12 17:36:36 -04:00
|
|
|
dpush(next);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XT of deferred words */
|
|
|
|
void undefined()
|
|
|
|
{
|
2004-08-20 18:48:08 -04:00
|
|
|
general_error(ERROR_UNDEFINED_WORD,tag_word(executing));
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XT of compound definitions */
|
2004-08-23 01:13:09 -04:00
|
|
|
void docol(void)
|
2004-07-16 02:26:21 -04:00
|
|
|
{
|
2004-08-23 01:13:09 -04:00
|
|
|
call(executing->parameter);
|
2004-09-28 00:24:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pushes word parameter */
|
|
|
|
void dosym(void)
|
|
|
|
{
|
|
|
|
dpush(executing->parameter);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_execute(void)
|
|
|
|
{
|
2004-08-23 01:13:09 -04:00
|
|
|
executing = untag_word(dpop());
|
2004-08-20 18:48:08 -04:00
|
|
|
EXECUTE(executing);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_call(void)
|
|
|
|
{
|
2004-08-23 01:13:09 -04:00
|
|
|
call(dpop());
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_ifte(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
CELL f = dpop();
|
2004-07-16 02:26:21 -04:00
|
|
|
CELL t = dpop();
|
|
|
|
CELL cond = dpop();
|
2004-08-23 01:13:09 -04:00
|
|
|
call(untag_boolean(cond) ? t : f);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_getenv(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
FIXNUM e = to_fixnum(dpeek());
|
2004-07-16 02:26:21 -04:00
|
|
|
if(e < 0 || e >= USER_ENV)
|
|
|
|
range_error(F,e,USER_ENV);
|
2004-08-20 18:48:08 -04:00
|
|
|
drepl(userenv[e]);
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void primitive_setenv(void)
|
|
|
|
{
|
2004-08-12 17:36:36 -04:00
|
|
|
FIXNUM e = to_fixnum(dpop());
|
2004-07-16 02:26:21 -04:00
|
|
|
CELL value = dpop();
|
|
|
|
if(e < 0 || e >= USER_ENV)
|
|
|
|
range_error(F,e,USER_ENV);
|
2004-08-20 18:48:08 -04:00
|
|
|
userenv[e] = value;
|
2004-07-16 02:26:21 -04:00
|
|
|
}
|