factor/native/run.c

127 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-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-12-10 21:39:45 -05:00
#ifdef WIN32
setjmp(toplevel);
__try
{
#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;
}
else
fix_stacks();
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();
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)
{
executing = (F_WORD*)UNTAG(next);
2004-08-20 18:48:08 -04:00
EXECUTE(executing);
2004-07-16 02:26:21 -04:00
}
else
dpush(next);
2004-07-16 02:26:21 -04:00
}
2004-12-10 21:39:45 -05:00
#ifdef WIN32
}
__except (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION ?
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
{
2004-12-11 15:02:34 -05:00
signal_error(SIGSEGV);
2004-12-10 21:39:45 -05:00
}
#endif
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)
{
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,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,e,USER_ENV);
2004-08-20 18:48:08 -04:00
userenv[e] = value;
2004-07-16 02:26:21 -04:00
}