2005-05-15 18:37:00 +00:00
|
|
|
/*
|
2005-05-23 14:43:03 +00:00
|
|
|
* $Id: context.c,v 1.7 2005-05-23 14:43:03 bacon Exp $
|
2005-05-15 18:37:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <xp/stx/context.h>
|
|
|
|
#include <xp/stx/object.h>
|
2005-05-23 14:43:03 +00:00
|
|
|
#include <xp/stx/class.h>
|
2005-05-21 16:11:06 +00:00
|
|
|
#include <xp/stx/misc.h>
|
2005-05-15 18:37:00 +00:00
|
|
|
|
|
|
|
xp_stx_word_t xp_stx_new_context (xp_stx_t* stx,
|
|
|
|
xp_stx_word_t method, xp_stx_word_t args, xp_stx_word_t temp)
|
|
|
|
{
|
|
|
|
xp_stx_word_t context;
|
2005-05-21 16:11:06 +00:00
|
|
|
xp_stx_context_t* obj;
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-22 04:34:22 +00:00
|
|
|
context = xp_stx_alloc_word_object(stx,XP_STX_CONTEXT_SIZE);
|
2005-05-21 16:11:06 +00:00
|
|
|
/*
|
2005-05-15 18:37:00 +00:00
|
|
|
XP_STX_CLASS(stx,context) = stx->class_context;
|
|
|
|
XP_STX_AT(stx,context,XP_STX_CONTEXT_IP) = XP_STX_TO_SMALLINT(0);
|
|
|
|
XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD) = method;
|
|
|
|
XP_STX_AT(stx,context,XP_STX_CONTEXT_ARGUMENTS) = args;
|
|
|
|
XP_STX_AT(stx,context,XP_STX_CONTEXT_TEMPORARIES) = temp;
|
2005-05-21 16:11:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
obj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
2005-05-23 14:43:03 +00:00
|
|
|
obj->header.class = xp_stx_lookup_class(stx,XP_STX_TEXT("Context"));
|
2005-05-21 16:11:06 +00:00
|
|
|
obj->ip = XP_STX_TO_SMALLINT(0);
|
|
|
|
obj->method = method;
|
|
|
|
obj->arguments = args;
|
|
|
|
obj->temporaries = temp;
|
2005-05-15 18:37:00 +00:00
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2005-05-21 16:11:06 +00:00
|
|
|
static xp_stx_byte_t __fetch_byte (
|
|
|
|
xp_stx_t* stx, xp_stx_context_t* context_obj)
|
2005-05-15 18:37:00 +00:00
|
|
|
{
|
2005-05-21 16:11:06 +00:00
|
|
|
xp_stx_word_t ip, method;
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-21 16:11:06 +00:00
|
|
|
xp_stx_assert (XP_STX_IS_SMALLINT(context_obj->ip));
|
|
|
|
ip = XP_STX_FROM_SMALLINT(context_obj->ip);
|
|
|
|
method = context_obj->method;
|
2005-05-15 18:37:00 +00:00
|
|
|
|
|
|
|
/* increment instruction pointer */
|
2005-05-21 16:11:06 +00:00
|
|
|
context_obj->ip = XP_STX_TO_SMALLINT(ip + 1);
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-21 16:11:06 +00:00
|
|
|
xp_stx_assert (XP_STX_TYPE(stx,method) == XP_STX_BYTE_INDEXED);
|
|
|
|
return XP_STX_BYTEAT(stx,method,ip);
|
2005-05-15 18:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int xp_stx_run_context (xp_stx_t* stx, xp_stx_word_t context)
|
|
|
|
{
|
|
|
|
xp_stx_byte_t byte, operand;
|
2005-05-21 16:11:06 +00:00
|
|
|
xp_stx_context_t* context_obj;
|
|
|
|
|
|
|
|
context_obj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
2005-05-15 18:37:00 +00:00
|
|
|
|
|
|
|
while (!stx->__wantabort) {
|
|
|
|
/* check_process_switch (); // hopefully */
|
2005-05-21 16:11:06 +00:00
|
|
|
byte = __fetch_byte (stx, context_obj);
|
2005-05-15 18:37:00 +00:00
|
|
|
|
2005-05-19 16:41:10 +00:00
|
|
|
#ifdef _DOS
|
|
|
|
printf (XP_TEXT("code: %x\n"), byte);
|
|
|
|
#else
|
2005-05-15 18:37:00 +00:00
|
|
|
xp_printf (XP_TEXT("code: %x\n"), byte);
|
2005-05-19 16:41:10 +00:00
|
|
|
#endif
|
2005-05-15 18:37:00 +00:00
|
|
|
|
|
|
|
switch (byte) {
|
|
|
|
case PUSH_OBJECT:
|
2005-05-21 16:11:06 +00:00
|
|
|
operand = __fetch_byte (stx, context_obj);
|
2005-05-15 18:37:00 +00:00
|
|
|
break;
|
|
|
|
case SEND_UNARY_MESSAGE:
|
2005-05-21 16:11:06 +00:00
|
|
|
operand = __fetch_byte (stx, context_obj);
|
2005-05-15 18:37:00 +00:00
|
|
|
break;
|
|
|
|
case HALT:
|
|
|
|
goto exit_run_context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit_run_context:
|
|
|
|
return 0;
|
|
|
|
}
|