factor/native/run.c

156 lines
2.3 KiB
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
2005-01-01 19:30:57 -05:00
INLINE void execute(F_WORD* word)
{
((XT)(word->xt))(word);
2005-01-01 19:30:57 -05:00
}
2004-07-16 02:26:21 -04:00
/* Called from platform_run() */
void init_errors(void)
2004-07-16 02:26:21 -04:00
{
thrown_error = F;
2005-10-11 21:46:14 -04:00
SETJMP(toplevel);
if(throwing)
2004-11-06 15:51:17 -05:00
{
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]);
throwing = false;
2004-11-06 15:51:17 -05:00
}
}
void run_once(void)
{
CELL next;
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
{
if(cs == cs_bot)
return;
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
switch(type_of(next))
{
case WORD_TYPE:
2005-01-01 19:30:57 -05:00
execute(untag_word_fast(next));
break;
case WRAPPER_TYPE:
dpush(untag_wrapper_fast(next)->object);
break;
default:
dpush(next);
break;
}
2004-07-16 02:26:21 -04:00
}
}
void run(void)
{
init_errors();
run_once();
}
/* Called by compiled callbacks after nest_stacks() and boxing registers */
void run_nullary_callback(CELL quot)
{
call(quot);
run_once();
unnest_stacks();
}
/* Called by compiled callbacks after nest_stacks() and boxing registers */
CELL run_unary_callback(CELL quot)
{
CELL retval;
nest_stacks();
call(quot);
run_once();
retval = dpeek();
unnest_stacks();
return retval;
}
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
{
2006-02-07 19:09:46 -05:00
general_error(ERROR_UNDEFINED_WORD,tag_object(word),true);
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();
2005-03-29 20:34:29 -05:00
call(cond == F ? f : t);
2004-07-16 02:26:21 -04:00
}
void primitive_dispatch(void)
{
F_ARRAY *a = untag_array_fast(dpop());
F_FIXNUM n = untag_fixnum_fast(dpop());
call(get(AREF(a,n)));
}
2004-07-16 02:26:21 -04:00
void primitive_getenv(void)
{
2005-04-25 21:39:34 -04:00
F_FIXNUM e = untag_fixnum_fast(dpeek());
2004-08-20 18:48:08 -04:00
drepl(userenv[e]);
2004-07-16 02:26:21 -04:00
}
void primitive_setenv(void)
{
2005-04-25 21:39:34 -04:00
F_FIXNUM e = untag_fixnum_fast(dpop());
2004-07-16 02:26:21 -04:00
CELL value = dpop();
2004-08-20 18:48:08 -04:00
userenv[e] = value;
2004-07-16 02:26:21 -04:00
}