factor/native/run.c

122 lines
1.8 KiB
C
Raw Normal View History

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-12-31 02:38:58 -05:00
executing = F;
2004-07-16 02:26:21 -04:00
}
2005-01-01 19:30:57 -05:00
INLINE void execute(F_WORD* word)
{
((XT)(word->xt))(word);
}
2004-07-16 02:26:21 -04:00
void run(void)
{
CELL next;
/* Error handling. */
2004-12-10 21:39:45 -05:00
#ifdef WIN32
setjmp(toplevel);
#else
sigsetjmp(toplevel, 1);
2004-12-10 21:39:45 -05:00
#endif
2004-11-06 15:51:17 -05:00
if(thrown_error != F)
{
2004-11-09 12:29:25 -05:00
if(thrown_keep_stacks)
{
ds = thrown_ds;
cs = thrown_cs;
callframe = thrown_callframe;
executing = thrown_executing;
2004-11-09 12:29:25 -05:00
}
else
{
2004-11-09 12:29:25 -05:00
fix_stacks();
callframe = F;
executing = F;
}
2004-11-09 12:29:25 -05:00
2004-11-06 15:51:17 -05:00
dpush(thrown_error);
/* Notify any 'catch' blocks */
call(userenv[BREAK_ENV]);
thrown_error = F;
}
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();
2005-01-01 19:30:57 -05:00
executing = 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(type_of(next) == WORD_TYPE)
2005-01-01 19:30:57 -05:00
execute(untag_word_fast(next));
2004-07-16 02:26:21 -04:00
else
dpush(next);
2004-07-16 02:26:21 -04:00
}
}
/* XT of deferred words */
2005-01-01 19:30:57 -05:00
void undefined(F_WORD* word)
2004-07-16 02:26:21 -04:00
{
general_error(ERROR_UNDEFINED_WORD,tag_object(word));
2004-07-16 02:26:21 -04:00
}
/* XT of compound definitions */
2005-01-01 19:30:57 -05:00
void docol(F_WORD* word)
2004-07-16 02:26:21 -04:00
{
call(word->def);
executing = tag_object(word);
2004-09-28 00:24:36 -04:00
}
/* pushes word parameter */
2005-01-01 19:30:57 -05:00
void dosym(F_WORD* word)
2004-09-28 00:24:36 -04:00
{
dpush(word->def);
2004-07-16 02:26:21 -04:00
}
void primitive_execute(void)
{
2005-01-01 19:30:57 -05:00
execute(untag_word(dpop()));
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)
{
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)
{
F_FIXNUM e = to_fixnum(dpeek());
2004-07-16 02:26:21 -04:00
if(e < 0 || e >= USER_ENV)
range_error(F,0,tag_fixnum(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)
{
F_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,0,tag_fixnum(e),USER_ENV);
2004-08-20 18:48:08 -04:00
userenv[e] = value;
2004-07-16 02:26:21 -04:00
}