*** empty log message ***

This commit is contained in:
hyung-hwan 2005-09-11 15:15:35 +00:00
parent f69814e193
commit ef790d9aa8
12 changed files with 86 additions and 71 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: bootstrp.c,v 1.31 2005-08-15 16:03:57 bacon Exp $
* $Id: bootstrp.c,v 1.32 2005-09-11 15:15:35 bacon Exp $
*/
#include <xp/stx/bootstrp.h>
@ -114,7 +114,7 @@ static class_info_t class_info[] =
{
XP_TEXT("Context"),
XP_TEXT("Object"),
XP_NULL,
XP_TEXT("stack stackTop receiver pc method"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
@ -122,7 +122,7 @@ static class_info_t class_info[] =
{
XP_TEXT("Method"),
XP_TEXT("Object"),
XP_TEXT("text selector bytecodes"),
XP_TEXT("text selector bytecodes tmpcount"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_WORD_INDEXABLE

View File

@ -1,5 +1,5 @@
/*
* $Id: bytecode.c,v 1.10 2005-09-11 13:17:35 bacon Exp $
* $Id: bytecode.c,v 1.11 2005-09-11 15:15:35 bacon Exp $
*/
#include <xp/stx/bytecode.h>
#include <xp/stx/class.h>
@ -61,16 +61,26 @@ static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data)
xp_word_t* literals;
xp_word_t literal_count, i;
xp_word_t method_class;
xp_stx_class_t* method_class_obj;
class_obj = (xp_stx_class_t*)data;
xp_printf (XP_TEXT("Method: %s\n"), XP_STX_DATA(stx, key));
xp_printf (XP_TEXT("* Method: %s\n"), XP_STX_DATA(stx, key));
method_obj = (xp_stx_method_t*)XP_STX_OBJECT(stx, value);
literals = method_obj->literals;
/*
literal_count = XP_STX_SIZE(stx, value) -
(XP_STX_FROM_SMALLINT(class_obj->spec) >> XP_STX_SPEC_INDEXABLE_BITS);
*/
method_class = XP_STX_CLASS(stx,value);
method_class_obj = XP_STX_OBJECT(stx, method_class);
literal_count = XP_STX_SIZE(stx,value) -
(XP_STX_FROM_SMALLINT(method_class_obj->spec) >> XP_STX_SPEC_INDEXABLE_BITS);
xp_printf (XP_TEXT("literal count %d\n"), literal_count);
xp_printf (XP_TEXT("* Literal Count: %d, Temporary Count: %d\n"),
literal_count, XP_STX_FROM_SMALLINT(method_obj->tmpcount));
for (i = 0; i < literal_count; i++) {
xp_printf (XP_TEXT("%d. ["), i);
__dump_object (stx, literals[i]);

View File

@ -1,5 +1,5 @@
/*
* $Id: class.c,v 1.23 2005-07-19 15:52:19 bacon Exp $
* $Id: class.c,v 1.24 2005-09-11 15:15:35 bacon Exp $
*/
#include <xp/stx/class.h>
@ -112,3 +112,28 @@ xp_word_t xp_stx_lookup_class_variable (
return stx->nil;
}
xp_word_t xp_stx_lookup_method (
xp_stx_t* stx, xp_word_t class_index, const xp_char_t* name)
{
xp_stx_class_t* class_obj;
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class_index);
xp_assert (class_obj != XP_NULL);
/* TODO: can a metaclas have class variables? */
if (class_obj->header.class != stx->class_metaclass &&
class_obj->class_variables != stx->nil) {
if (xp_stx_dict_lookup(stx,
class_obj->methods,name) != stx->nil) return class_index;
}
if (class_obj->superclass != stx->nil) {
xp_word_t tmp;
tmp = xp_stx_lookup_method (
stx, class_obj->superclass, name);
if (tmp != stx->nil) return tmp;
}
return stx->nil;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: class.h,v 1.13 2005-08-18 15:28:18 bacon Exp $
* $Id: class.h,v 1.14 2005-09-11 15:15:35 bacon Exp $
*/
#ifndef _XP_STX_CLASS_H_
@ -71,6 +71,8 @@ int xp_stx_get_instance_variable_index (
xp_word_t xp_stx_lookup_class_variable (
xp_stx_t* stx, xp_word_t class_index, const xp_char_t* name);
xp_word_t xp_stx_lookup_method (
xp_stx_t* stx, xp_word_t class_index, const xp_char_t* name);
#ifdef __cplusplus
}

View File

@ -1,5 +1,5 @@
/*
* $Id: interp.c,v 1.7 2005-09-11 13:17:35 bacon Exp $
* $Id: interp.c,v 1.8 2005-09-11 15:15:35 bacon Exp $
*/
#include <xp/stx/interp.h>
@ -51,12 +51,14 @@ xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t receiver, xp_word_t metho
xp_word_t context;
xp_stx_context_t* ctxobj;
xp_printf (XP_TEXT("%d, %d\n"), receiver, method);
context = xp_stx_alloc_word_object(
stx, XP_NULL, XP_STX_CONTEXT_SIZE, XP_NULL, 0);
XP_STX_CLASS(stx,context) = stx->class_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, 512); /* TODO: initial stack size */
ctxobj->stack_top = XP_STX_TO_SMALLINT(0);
ctxobj->receiver = receiver;
ctxobj->pc = XP_STX_TO_SMALLINT(0);
@ -65,13 +67,6 @@ xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t receiver, xp_word_t metho
return context;
}
/*
static int __push_receiver_variable (
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
static int __push_temporary_variable (
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj);
*/
int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
{
xp_stx_context_t* ctxobj;
@ -84,8 +79,12 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
vmc.stack = XP_STX_DATA(stx,ctxobj->stack);
vmc.stack_size = XP_STX_SIZE(stx,ctxobj->stack);
/* the beginning of the stack is reserved for temporaries */
vmc.stack_top =
XP_STX_FROM_SMALLINT(ctxobj->stack_top) +
XP_STX_FROM_SMALLINT(mthobj->tmpcount);
vmc.receiver = ctxobj->receiver;
vmc.pc = ctxobj->pc;
vmc.pc = XP_STX_FROM_SMALLINT(ctxobj->pc);
vmc.literals = mthobj->literals;
vmc.bytecodes = XP_STX_DATA(stx, mthobj->bytecodes);
@ -104,9 +103,10 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
vmc.stack[vmc.stack_top++] = XP_STX_WORD_AT(stx, vmc.receiver, index);
break;
case 1: /* temporary variable */
//vmc.stack[vmc.stack_top++] = XP_STX_WORD_AT(stx, vmc.temporary, index);
vmc.stack[vmc.stack_top++] = vmc.stack[index];
break;
case 2: /* literal constant */
vmc.stack[vmc.stack_top++] = vmc.literals[index];
break;
case 3: /* literal variable */
break;
@ -119,8 +119,10 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
switch (what) {
case 4: /* receiver variable */
XP_STX_WORD_AT(stx,vmc.receiver,index) = vmc.stack[--vmc.stack_top];
break;
case 5: /* temporary location */
vmc.stack[index] = vmc.stack[--vmc.stack_top];
break;
}
}
@ -137,45 +139,11 @@ int xp_stx_interp (xp_stx_t* stx, xp_word_t context)
return 0;
}
/*
static int __push_receiver_variable (
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj)
{
xp_word_t* stack;
xp_word_t stack_top;
xp_assert (XP_STX_IS_WORD_OBJECT(stx, ctxobj->receiver));
stack_top = XP_STX_FROM_SMALLINT(ctxobj->stack_top);
stack = XP_STX_DATA(stx, ctxobj->stack);
stack[stack_top++] = XP_STX_WORD_AT(stx, ctxobj->receiver, index);
ctxobj->stack_top = XP_STX_TO_SMALLINT(stack_top);
return 0;
}
static int __push_temporary_variable (
xp_stx_t* stx, int index, xp_stx_context_t* ctxobj)
{
xp_word_t* stack;
xp_word_t stack_top;
xp_assert (XP_STX_IS_WORD_OBJECT(stx, ctxobj->receiver));
stack_top = XP_STX_FROM_SMALLINT(ctxobj->stack_top);
stack = XP_STX_DATA(stx, ctxobj->stack);
stack[stack_top++] = XP_STX_WORD_AT(stx, ctxobj->receiver, index);
ctxobj->stack_top = XP_STX_TO_SMALLINT(stack_top);
return 0;
}
*/
static int __dispatch_primitive (xp_stx_t* stx, int no, xp_stx_context_t* ctxobj)
{
switch (no) {
case 0:
xp_printf (XP_TEXT("Hello, STX Smalltalk\n"));
break;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: interp.h,v 1.4 2005-08-18 15:28:18 bacon Exp $
* $Id: interp.h,v 1.5 2005-09-11 15:15:35 bacon Exp $
*/
#ifndef _XP_STX_INTERP_H_
@ -11,6 +11,9 @@
extern "C" {
#endif
xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t receiver, xp_word_t method);
int xp_stx_interp (xp_stx_t* stx, xp_word_t context);
#ifdef __cplusplus
}
#endif

View File

@ -1,6 +1,5 @@
SRCS = \
stx.c memory.c object.c symbol.c class.c \
dict.c misc.c context.c name.c token.c parser.c bootstrp.c bytecode.c
SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c array.c \
name.c token.c parser.c bootstrp.c bytecode.c interp.c
OBJS = $(SRCS:.c=.obj)
OUT = xpstx.lib

View File

@ -1,6 +1,6 @@
SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c \
SRCS = stx.c memory.c object.c symbol.c class.c dict.c misc.c array.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 dict.obj misc.obj\
OBJS = stx.obj memory.obj object.obj symbol.obj class.obj dict.obj misc.obj array.obj \
context.obj name.obj token.obj parser.obj bootstrp.obj bytecode.obj interp.obj
OUT = xpstx.lib

View File

@ -1,5 +1,5 @@
/*
* $Id: method.h,v 1.6 2005-08-18 15:39:40 bacon Exp $
* $Id: method.h,v 1.7 2005-09-11 15:15:35 bacon Exp $
*/
#ifndef _XP_STX_METHOD_H_
@ -7,10 +7,11 @@
#include <xp/stx/stx.h>
#define XP_STX_METHOD_SIZE 3
#define XP_STX_METHOD_SIZE 4
#define XP_STX_METHOD_TEXT 0
#define XP_STX_METHOD_SELECTOR 1
#define XP_STX_METHOD_BYTECODES 2
#define XP_STX_METHOD_TMPCOUNT 3
/* dolphin smalltalk's flags representation
@ -29,8 +30,8 @@ struct xp_stx_method_t
xp_stx_objhdr_t header;
xp_word_t text;
xp_word_t selector; /* is this necessary? */
xp_word_t flags;
xp_word_t bytecodes;
xp_word_t tmpcount;
xp_word_t literals[1];
};

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.c,v 1.68 2005-08-15 16:03:57 bacon Exp $
* $Id: parser.c,v 1.69 2005-09-11 15:15:35 bacon Exp $
*/
#include <xp/stx/parser.h>
@ -374,7 +374,7 @@ static INLINE int __emit_do_primitive (xp_stx_parser_t* parser, int no)
{
xp_assert (no >= 0x0 && no <= 0xFFF);
EMIT_CODE (parser, DO_PRIMITIVE & ((no >> 8) & 0x0F));
EMIT_CODE (parser, DO_PRIMITIVE | ((no >> 8) & 0x0F));
EMIT_CODE (parser, no & 0xFF);
return 0;
@ -524,11 +524,10 @@ static int __finish_method (xp_stx_parser_t* parser)
method_obj->bytecodes = xp_stx_instantiate (
stx, stx->class_bytearray, XP_NULL,
parser->bytecode.buffer, parser->bytecode.size);
/*
method_obj->stack_size = XP_STX_TO_SMALLINT(100);
method_obj->temporary_size =
/* TODO: better way to store argument count & temporary count */
method_obj->tmpcount =
XP_STX_TO_SMALLINT(parser->temporary_count);
*/
xp_stx_dict_put (stx, class_obj->methods, selector, method);
return 0;

View File

@ -12,6 +12,7 @@
#include <xp/stx/bootstrp.h>
#include <xp/stx/class.h>
#include <xp/stx/bytecode.h>
#include <xp/stx/interp.h>
#ifdef __linux
#include <mcheck.h>
@ -162,6 +163,10 @@ int xp_main (int argc, xp_char_t* argv[])
xp_printf (XP_TEXT("parser error <%s>\n"),
xp_stx_parser_error_string (&parser));
}
xp_stx_interp (&stx,
xp_stx_new_context (&stx, n,
xp_stx_lookup_method(&stx, n, XP_TEXT("main"))));
}
exit_program:

View File

@ -1,4 +1,7 @@
main
| a |
a := nil.
| a b |
<primitive: 0>
a := 1.
b := 3.
^nil