qse/ase/stx/context.c

76 lines
1.7 KiB
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2007-03-22 11:19:28 +00:00
* $Id: context.c,v 1.12 2007-03-22 11:19:28 bacon Exp $
2005-05-15 18:37:00 +00:00
*/
2007-03-22 11:19:28 +00:00
#include <ase/stx/context.h>
#include <ase/stx/object.h>
#include <ase/stx/class.h>
#include <ase/stx/misc.h>
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
ase_word_t ase_stx_new_context (ase_stx_t* stx,
ase_word_t method, ase_word_t args, ase_word_t temp)
2005-05-15 18:37:00 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t context;
ase_stx_context_t* obj;
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
context = ase_stx_alloc_word_object(
stx, ASE_NULL, ASE_STX_CONTEXT_SIZE, ASE_NULL, 0);
obj = (ase_stx_context_t*)ASE_STX_OBJECT(stx,context);
obj->header.class = ase_stx_lookup_class(stx,ASE_T("Context"));
obj->ip = ASE_STX_TO_SMALLINT(0);
2005-05-21 16:11:06 +00:00
obj->method = method;
obj->arguments = args;
obj->temporaries = temp;
2005-05-15 18:37:00 +00:00
return context;
}
2007-03-22 11:19:28 +00:00
static ase_byte_t __fetch_byte (
ase_stx_t* stx, ase_stx_context_t* context_obj)
2005-05-15 18:37:00 +00:00
{
2007-03-22 11:19:28 +00:00
ase_word_t ip, method;
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (ASE_STX_IS_SMALLINT(context_obj->ip));
ip = ASE_STX_FROM_SMALLINT(context_obj->ip);
2005-05-21 16:11:06 +00:00
method = context_obj->method;
2005-05-15 18:37:00 +00:00
/* increment instruction pointer */
2007-03-22 11:19:28 +00:00
context_obj->ip = ASE_STX_TO_SMALLINT(ip + 1);
2005-05-15 18:37:00 +00:00
2007-03-22 11:19:28 +00:00
ase_assert (ASE_STX_TYPE(stx,method) == ASE_STX_BYTE_INDEXED);
return ASE_STX_BYTE_AT(stx,method,ip);
2005-05-15 18:37:00 +00:00
}
2007-03-22 11:19:28 +00:00
int ase_stx_run_context (ase_stx_t* stx, ase_word_t context)
2005-05-15 18:37:00 +00:00
{
2007-03-22 11:19:28 +00:00
ase_byte_t byte, operand;
ase_stx_context_t* context_obj;
2005-05-21 16:11:06 +00:00
2007-03-22 11:19:28 +00:00
context_obj = (ase_stx_context_t*)ASE_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
2007-03-22 11:19:28 +00:00
printf (ASE_T("code: %x\n"), byte);
2005-05-19 16:41:10 +00:00
#else
2007-03-22 11:19:28 +00:00
ase_printf (ASE_T("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;
}