*** empty log message ***
This commit is contained in:
parent
a5a65f1079
commit
f69814e193
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: bytecode.c,v 1.9 2005-08-11 16:16:04 bacon Exp $
|
* $Id: bytecode.c,v 1.10 2005-09-11 13:17:35 bacon Exp $
|
||||||
*/
|
*/
|
||||||
#include <xp/stx/bytecode.h>
|
#include <xp/stx/bytecode.h>
|
||||||
#include <xp/stx/class.h>
|
#include <xp/stx/class.h>
|
||||||
@ -23,6 +23,7 @@ int xp_stx_decode (xp_stx_t* stx, xp_word_t class)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <xp/bas/stdio.h>
|
||||||
static void __dump_object (xp_stx_t* stx, xp_word_t obj)
|
static void __dump_object (xp_stx_t* stx, xp_word_t obj)
|
||||||
{
|
{
|
||||||
if (XP_STX_IS_SMALLINT(obj)) {
|
if (XP_STX_IS_SMALLINT(obj)) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: interp.c,v 1.6 2005-08-16 15:49:04 bacon Exp $
|
* $Id: interp.c,v 1.7 2005-09-11 13:17:35 bacon Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <xp/stx/interp.h>
|
#include <xp/stx/interp.h>
|
||||||
@ -11,23 +11,42 @@
|
|||||||
#define XP_STX_CONTEXT_SIZE 5
|
#define XP_STX_CONTEXT_SIZE 5
|
||||||
#define XP_STX_CONTEXT_STACK 0
|
#define XP_STX_CONTEXT_STACK 0
|
||||||
#define XP_STX_CONTEXT_STACK_TOP 1
|
#define XP_STX_CONTEXT_STACK_TOP 1
|
||||||
#define XP_STX_CONTEXT_METHOD 2
|
#define XP_STX_CONTEXT_RECEIVER 2
|
||||||
#define XP_STX_CONTEXT_RECEIVER 3
|
#define XP_STX_CONTEXT_PC 3
|
||||||
#define XP_STX_CONTEXT_IP 4
|
#define XP_STX_CONTEXT_METHOD 4
|
||||||
|
|
||||||
struct xp_stx_context_t
|
struct xp_stx_context_t
|
||||||
{
|
{
|
||||||
xp_stx_objhdr_t header;
|
xp_stx_objhdr_t header;
|
||||||
xp_word_t stack;
|
xp_word_t stack;
|
||||||
xp_word_t stack_top;
|
xp_word_t stack_top;
|
||||||
xp_word_t method;
|
|
||||||
xp_word_t receiver;
|
xp_word_t receiver;
|
||||||
xp_word_t ip;
|
xp_word_t pc;
|
||||||
|
xp_word_t method;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct xp_stx_context_t xp_stx_context_t;
|
typedef struct xp_stx_context_t xp_stx_context_t;
|
||||||
|
|
||||||
xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t method, xp_word_t receiver)
|
/* data structure for internal vm operation */
|
||||||
|
struct vmcontext_t
|
||||||
|
{
|
||||||
|
/* from context */
|
||||||
|
xp_word_t* stack;
|
||||||
|
xp_word_t stack_size;
|
||||||
|
xp_word_t stack_top;
|
||||||
|
xp_word_t receiver;
|
||||||
|
xp_word_t pc;
|
||||||
|
|
||||||
|
/* from method */
|
||||||
|
xp_byte_t* bytecodes;
|
||||||
|
xp_word_t bytecode_size;
|
||||||
|
xp_word_t* literals;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct vmcontext_t vmcontext_t;
|
||||||
|
|
||||||
|
|
||||||
|
xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t receiver, xp_word_t method)
|
||||||
{
|
{
|
||||||
xp_word_t context;
|
xp_word_t context;
|
||||||
xp_stx_context_t* ctxobj;
|
xp_stx_context_t* ctxobj;
|
||||||
@ -39,37 +58,41 @@ xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t method, xp_word_t receive
|
|||||||
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
||||||
ctxobj->stack = xp_stx_new_array (stx, 256); /* TODO: initial stack size */
|
ctxobj->stack = xp_stx_new_array (stx, 256); /* TODO: initial stack size */
|
||||||
ctxobj->stack_top = XP_STX_TO_SMALLINT(0);
|
ctxobj->stack_top = XP_STX_TO_SMALLINT(0);
|
||||||
ctxobj->method = method;
|
|
||||||
ctxobj->receiver = receiver;
|
ctxobj->receiver = receiver;
|
||||||
ctxobj->ip = XP_STX_TO_SMALLINT(0);
|
ctxobj->pc = XP_STX_TO_SMALLINT(0);
|
||||||
|
ctxobj->method = method;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static int __push_receiver_variable (
|
static int __push_receiver_variable (
|
||||||
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
|
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
|
||||||
static int __push_temporary_variable (
|
static int __push_temporary_variable (
|
||||||
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
|
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
|
||||||
|
*/
|
||||||
|
|
||||||
int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
|
int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
|
||||||
{
|
{
|
||||||
xp_stx_context_t* ctxobj;
|
xp_stx_context_t* ctxobj;
|
||||||
xp_stx_method_t* mthobj;
|
xp_stx_method_t* mthobj;
|
||||||
xp_stx_byte_object_t* bytecodes;
|
vmcontext_t vmc;
|
||||||
xp_word_t bytecode_size;
|
int code, next;
|
||||||
xp_word_t* literals;
|
|
||||||
xp_word_t pc = 0;
|
|
||||||
int code, next, next2;
|
|
||||||
|
|
||||||
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
|
||||||
mthobj = (xp_stx_method_t*)XP_STX_OBJECT(stx, ctxobj->method);
|
mthobj = (xp_stx_method_t*)XP_STX_OBJECT(stx,ctxobj->method);
|
||||||
|
|
||||||
literals = mthobj->literals;
|
vmc.stack = XP_STX_DATA(stx,ctxobj->stack);
|
||||||
bytecodes = XP_STX_BYTE_OBJECT(stx, mthobj->bytecodes);
|
vmc.stack_size = XP_STX_SIZE(stx,ctxobj->stack);
|
||||||
bytecode_size = XP_STX_SIZE(stx, mthobj->bytecodes);
|
vmc.receiver = ctxobj->receiver;
|
||||||
|
vmc.pc = ctxobj->pc;
|
||||||
|
|
||||||
while (pc < bytecode_size) {
|
vmc.literals = mthobj->literals;
|
||||||
code = bytecodes->data[pc++];
|
vmc.bytecodes = XP_STX_DATA(stx, mthobj->bytecodes);
|
||||||
|
vmc.bytecode_size = XP_STX_SIZE(stx, mthobj->bytecodes);
|
||||||
|
|
||||||
|
while (vmc.pc < vmc.bytecode_size) {
|
||||||
|
code = vmc.bytecodes[vmc.pc++];
|
||||||
|
|
||||||
if (code >= 0x00 && code <= 0x3F) {
|
if (code >= 0x00 && code <= 0x3F) {
|
||||||
/* stack - push */
|
/* stack - push */
|
||||||
@ -78,10 +101,10 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
|
|||||||
|
|
||||||
switch (what) {
|
switch (what) {
|
||||||
case 0: /* receiver variable */
|
case 0: /* receiver variable */
|
||||||
__push_receiver_variable (stx, index, ctxobj);
|
vmc.stack[vmc.stack_top++] = XP_STX_WORD_AT(stx, vmc.receiver, index);
|
||||||
break;
|
break;
|
||||||
case 1: /* temporary variable */
|
case 1: /* temporary variable */
|
||||||
__push_temporary_variable (stx, index, ctxobj);
|
//vmc.stack[vmc.stack_top++] = XP_STX_WORD_AT(stx, vmc.temporary, index);
|
||||||
break;
|
break;
|
||||||
case 2: /* literal constant */
|
case 2: /* literal constant */
|
||||||
break;
|
break;
|
||||||
@ -101,11 +124,20 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* more code .... */
|
||||||
|
|
||||||
|
else if (code >= 0xF0 && code <= 0xFF) {
|
||||||
|
/* primitive */
|
||||||
|
next = vmc.bytecodes[vmc.pc++];
|
||||||
|
__dispatch_primitive (next);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static int __push_receiver_variable (
|
static int __push_receiver_variable (
|
||||||
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj)
|
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj)
|
||||||
{
|
{
|
||||||
@ -137,3 +169,14 @@ static int __push_temporary_variable (
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int __dispatch_primitive (xp_stx_t* stx, int no, xp_stx_context_t* ctxobj)
|
||||||
|
{
|
||||||
|
switch (no) {
|
||||||
|
case 0:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
SRCS = stx.c memory.c object.c symbol.c class.c \
|
SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c \
|
||||||
dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c
|
context.c name.c token.c parser.c bootstrp.c bytecode.c interp.c
|
||||||
OBJS = stx.obj memory.obj object.obj symbol.obj class.obj \
|
OBJS = stx.obj memory.obj object.obj symbol.obj class.obj dict.obj misc.obj\
|
||||||
dict.obj misc.obj context.obj name.obj token.obj parser.obj bootstrp.obj bytecode.obj
|
context.obj name.obj token.obj parser.obj bootstrp.obj bytecode.obj interp.obj
|
||||||
OUT = xpstx.lib
|
OUT = xpstx.lib
|
||||||
|
|
||||||
CC = lcc
|
CC = lcc
|
||||||
|
Loading…
Reference in New Issue
Block a user