From ef790d9aa819ccf89ef88cbed7fe26932c048c4a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 11 Sep 2005 15:15:35 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/bootstrp.c | 6 ++--- ase/stx/bytecode.c | 16 +++++++++--- ase/stx/class.c | 27 ++++++++++++++++++- ase/stx/class.h | 4 ++- ase/stx/interp.c | 60 ++++++++++--------------------------------- ase/stx/interp.h | 5 +++- ase/stx/makefile.bcc | 5 ++-- ase/stx/makefile.lcc | 4 +-- ase/stx/method.h | 7 ++--- ase/stx/parser.c | 11 ++++---- ase/test/stx/parser.c | 5 ++++ ase/test/stx/test.st | 7 +++-- 12 files changed, 86 insertions(+), 71 deletions(-) diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index 18fedace..1a7abd1e 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -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 @@ -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 diff --git a/ase/stx/bytecode.c b/ase/stx/bytecode.c index c2d77e79..a7103af5 100644 --- a/ase/stx/bytecode.c +++ b/ase/stx/bytecode.c @@ -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 #include @@ -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]); diff --git a/ase/stx/class.c b/ase/stx/class.c index 0e4410a1..3744d49c 100644 --- a/ase/stx/class.c +++ b/ase/stx/class.c @@ -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 @@ -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; +} diff --git a/ase/stx/class.h b/ase/stx/class.h index 64f504ab..5d814305 100644 --- a/ase/stx/class.h +++ b/ase/stx/class.h @@ -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 } diff --git a/ase/stx/interp.c b/ase/stx/interp.c index db196620..5e4ec5cc 100644 --- a/ase/stx/interp.c +++ b/ase/stx/interp.c @@ -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 @@ -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; } diff --git a/ase/stx/interp.h b/ase/stx/interp.h index e36ed09f..223733d6 100644 --- a/ase/stx/interp.h +++ b/ase/stx/interp.h @@ -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 diff --git a/ase/stx/makefile.bcc b/ase/stx/makefile.bcc index cf78bb1b..a23bf9cf 100644 --- a/ase/stx/makefile.bcc +++ b/ase/stx/makefile.bcc @@ -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 diff --git a/ase/stx/makefile.lcc b/ase/stx/makefile.lcc index 7fcebc23..0d1eff6d 100644 --- a/ase/stx/makefile.lcc +++ b/ase/stx/makefile.lcc @@ -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 diff --git a/ase/stx/method.h b/ase/stx/method.h index 7f405d54..747bc25f 100644 --- a/ase/stx/method.h +++ b/ase/stx/method.h @@ -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 -#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]; }; diff --git a/ase/stx/parser.c b/ase/stx/parser.c index ebb32159..7fccdf04 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -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 @@ -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; diff --git a/ase/test/stx/parser.c b/ase/test/stx/parser.c index 4bca2c10..7a3f9df3 100644 --- a/ase/test/stx/parser.c +++ b/ase/test/stx/parser.c @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef __linux #include @@ -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: diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 5f9c83f6..0d23a094 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -1,4 +1,7 @@ main - | a | - a := nil. + | a b | + + + a := 1. + b := 3. ^nil