From 1781d8acf44f29444d0ff84d9329fd04b9defb88 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 13 May 2005 16:45:55 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/interp.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ ase/stx/interp.h | 16 ++++++++++ 2 files changed, 93 insertions(+) create mode 100644 ase/stx/interp.c create mode 100644 ase/stx/interp.h diff --git a/ase/stx/interp.c b/ase/stx/interp.c new file mode 100644 index 00000000..d76c1ad6 --- /dev/null +++ b/ase/stx/interp.c @@ -0,0 +1,77 @@ +/* + * $Id: interp.c,v 1.1 2005-05-13 16:45:55 bacon Exp $ + */ + +#include + +#define XP_STX_PROCESS_DIMENSION 3 +#define XP_STX_PROCESS_STACK 0 +#define XP_STX_PROCESS_STACK_TOP 1 +#define XP_STX_PROCESS_LINK 2 + +#define XP_STX_CONTEXT_DIMENSION 6 +#define XP_STX_PROCESS_LINK 0 +#define XP_STX_PROCESS_METHOD 1 +#define XP_STX_PROCESS_ARGUMENTS 2 +#define XP_STX_PROCESS_TEMPORARIES 3 + +typedef int (*byte_code_func_t) (xp_stx_t* + +static byte_code_func_t byte_code_funcs[] = +{ + XP_NULL, + push_instance, + push_argyment, + push_temporary, + push_literal, + push_constant, + store_instance, + store_temporary, + send_message, + send_unary, + send_binary, + XP_NULL, + do_primitive, + XP_NULL, + do_special +}; + +int 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; + + context = xp_stx_alloc_object(XP_STX_CONTEXT_DIMENSION); + XP_STX_CLASS(stx,context) = stx->context_class; + 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; +} + +int xp_stx_execute (xp_stx_t* stx, xp_stx_word_t process) +{ + int low, high; + byte_code_func_t bcfunc; + + stack = XP_STX_AT(stx,process,XP_PROCESS_STACK); + stack_top = XP_STX_AT(stx,process,XP_PROCESS_STACK_TOP); + link = XP_STX_AT(stx,process,XP_PROCESS_LINK); + + for (;;) { + low = (high = nextByte(&es)) & 0x0F; + high >>= 4; + if(high == 0) { + high = low; + low = nextByte(&es); + } + + bcfunc = byte_code_funcs[high]; + if (bcfunc != XP_NULL) { + bcfunc (stx, low); + } + } + + return 0; +} diff --git a/ase/stx/interp.h b/ase/stx/interp.h new file mode 100644 index 00000000..2b7a79b0 --- /dev/null +++ b/ase/stx/interp.h @@ -0,0 +1,16 @@ +/* + * $Id: interp.h,v 1.1 2005-05-13 16:45:55 bacon Exp $ + */ + +#ifndef _XP_STX_INTERP_H_ +#define _XP_STX_INTERP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif