qse/ase/stx/context.c

72 lines
1.7 KiB
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2005-05-19 16:41:10 +00:00
* $Id: context.c,v 1.4 2005-05-19 16:41:10 bacon Exp $
2005-05-15 18:37:00 +00:00
*/
#include <xp/stx/context.h>
#include <xp/stx/object.h>
2005-05-18 04:01:51 +00:00
#define XP_STX_CONTEXT_SIZE 4
2005-05-15 18:37:00 +00:00
#define XP_STX_CONTEXT_IP 0
#define XP_STX_CONTEXT_METHOD 1
#define XP_STX_CONTEXT_ARGUMENTS 2
#define XP_STX_CONTEXT_TEMPORARIES 3
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-18 04:01:51 +00:00
context = xp_stx_alloc_object(stx,XP_STX_CONTEXT_SIZE);
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;
return context;
}
static xp_stx_byte_t __fetch_byte (xp_stx_t* stx, xp_stx_word_t context)
{
xp_stx_word_t method, ip;
ip = XP_STX_AT(stx,context,XP_STX_CONTEXT_IP);
method = XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD);
/* increment instruction pointer */
XP_STX_AT(stx,context,XP_STX_CONTEXT_IP) =
XP_STX_TO_SMALLINT((XP_STX_FROM_SMALLINT(ip) + 1));
return XP_STX_BYTEAT(stx,method,XP_STX_FROM_SMALLINT(ip));
}
int xp_stx_run_context (xp_stx_t* stx, xp_stx_word_t context)
{
xp_stx_byte_t byte, operand;
while (!stx->__wantabort) {
/* check_process_switch (); // hopefully */
byte = __fetch_byte (stx, context);
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:
operand = __fetch_byte (stx, context);
break;
case SEND_UNARY_MESSAGE:
2005-05-16 14:14:34 +00:00
operand = __fetch_byte (stx, context);
2005-05-15 18:37:00 +00:00
break;
case HALT:
goto exit_run_context;
}
}
exit_run_context:
return 0;
}