From d1c0760ec2279aa12a4dd72a0b71d1904a1f5b32 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 15 Aug 2005 16:03:57 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/array.c | 18 ++++++ ase/stx/array.h | 21 +++++++ ase/stx/bootstrp.c | 20 ++---- ase/stx/interp.c | 143 ++++++++++++++++++++----------------------- ase/stx/makefile.cl | 5 +- ase/stx/makefile.in | 5 +- ase/stx/parser.c | 6 +- ase/stx/stx.c | 6 +- ase/stx/stx.h | 3 +- ase/test/stx/test.st | 2 + 10 files changed, 127 insertions(+), 102 deletions(-) create mode 100644 ase/stx/array.c create mode 100644 ase/stx/array.h diff --git a/ase/stx/array.c b/ase/stx/array.c new file mode 100644 index 00000000..1087e621 --- /dev/null +++ b/ase/stx/array.c @@ -0,0 +1,18 @@ +/* + * $Id: array.c,v 1.1 2005-08-15 16:03:57 bacon Exp $ + */ + +#include +#include +#include + +xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size) +{ + xp_word_t x; + + xp_assert (stx->class_array != stx->nil); + x = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, size); + XP_STX_CLASS(stx,x) = stx->class_array; + + return x; +} diff --git a/ase/stx/array.h b/ase/stx/array.h new file mode 100644 index 00000000..3e03bc94 --- /dev/null +++ b/ase/stx/array.h @@ -0,0 +1,21 @@ +/* + * $Id: array.h,v 1.1 2005-08-15 16:03:57 bacon Exp $ + */ + +#ifndef _XP_STX_ARRAY_H_ +#define _XP_STX_ARRAY_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index e19be497..18fedace 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -1,5 +1,5 @@ /* - * $Id: bootstrp.c,v 1.30 2005-08-11 09:57:54 bacon Exp $ + * $Id: bootstrp.c,v 1.31 2005-08-15 16:03:57 bacon Exp $ */ #include @@ -273,17 +273,6 @@ static class_info_t class_info[] = } }; -xp_word_t INLINE __new_array (xp_stx_t* stx, xp_word_t size) -{ - xp_word_t x; - - xp_assert (stx->class_array != stx->nil); - x = xp_stx_alloc_word_object (stx, XP_NULL, 0, XP_NULL, size); - XP_STX_CLASS(stx,x) = stx->class_array; - - return x; -} - xp_word_t INLINE __new_string (xp_stx_t* stx, const xp_char_t* str) { xp_word_t x; @@ -310,6 +299,7 @@ int xp_stx_bootstrap (xp_stx_t* stx) stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray")); stx->class_string = xp_stx_new_class (stx, XP_TEXT("String")); stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character")); + stx->class_context = xp_stx_new_class (stx, XP_TEXT("Context")); stx->class_system_dictionary = xp_stx_new_class (stx, XP_TEXT("SystemDictionary")); stx->class_method = @@ -329,7 +319,7 @@ int xp_stx_bootstrap (xp_stx_t* stx) /* for some fun here */ { xp_word_t array; - array = __new_array (stx, 1); + array = xp_stx_new_array (stx, 1); XP_STX_WORD_AT(stx,array,0) = object_meta; XP_STX_WORD_AT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array; } @@ -541,7 +531,7 @@ static void __create_builtin_classes (xp_stx_t* stx) /* fill subclasses */ for (p = class_info; p->name != XP_NULL; p++) { n = __count_subclasses (p->name); - array = __new_array (stx, n); + array = xp_stx_new_array (stx, n); __set_subclasses (stx, XP_STX_DATA(stx,array), p->name); class = xp_stx_lookup_class(stx, p->name); @@ -553,7 +543,7 @@ static void __create_builtin_classes (xp_stx_t* stx) /* fill subclasses for metaclasses */ for (p = class_info; p->name != XP_NULL; p++) { n = __count_subclasses (p->name); - array = __new_array (stx, n); + array = xp_stx_new_array (stx, n); __set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name); class = xp_stx_lookup_class(stx, p->name); diff --git a/ase/stx/interp.c b/ase/stx/interp.c index 982b013b..9ac7015e 100644 --- a/ase/stx/interp.c +++ b/ase/stx/interp.c @@ -1,107 +1,96 @@ /* - * $Id: interp.c,v 1.4 2005-06-08 16:00:51 bacon Exp $ + * $Id: interp.c,v 1.5 2005-08-15 16:03:57 bacon Exp $ */ #include +#include +#include +#include -#define XP_STX_PROCESS_SIZE 3 -#define XP_STX_PROCESS_STACK 0 -#define XP_STX_PROCESS_STACK_TOP 1 -#define XP_STX_PROCESS_LINK 2 +#define XP_STX_CONTEXT_SIZE 4 +#define XP_STX_CONTEXT_STACK 0 +#define XP_STX_CONTEXT_STACK_TOP 1 +#define XP_STX_CONTEXT_METHOD 2 +#define XP_STX_CONTEXT_IP 3 -#define XP_STX_CONTEXT_SIZE 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[] = +struct xp_stx_context_t { - 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 + xp_stx_objhdr_t header; + xp_word_t stack; + xp_word_t stack_top; + xp_word_t method; + xp_word_t ip; }; -xp_word_t xp_stx_new_method (xp_stx_t* stx) -{ - xp_word_t method; - method = xp_stx_alloc_object(XP_STX_METHOD_SIZE); +typedef struct xp_stx_context_t xp_stx_context_t; - return method; -} - -xp_word_t xp_stx_new_context (xp_stx_t* stx, - xp_word_t method, xp_word_t args, xp_word_t temp) +xp_word_t xp_stx_new_context (xp_stx_t* stx, xp_word_t method) { xp_word_t context; + xp_stx_context_t* ctxobj; - context = xp_stx_alloc_object(XP_STX_CONTEXT_SIZE); + context = xp_stx_alloc_word_object( + stx, XP_NULL, XP_STX_CONTEXT_SIZE, XP_NULL, 0); XP_STX_CLASS(stx,context) = stx->class_context; - 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; + + ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context); + ctxobj->stack = xp_stx_new_array (stx, 256); /* TODO: initial stack size */ + ctxobj->stack_top = XP_STX_TO_SMALLINT(0); + ctxobj->method = method; + ctxobj->ip = XP_STX_TO_SMALLINT(0); return context; } -xp_word_t xp_stx_new_process (xp_stx_t* stx, xp_word_t method) +int xp_stx_interp (xp_stx_t* stx, xp_word_t context) { - xp_word_t process, stx; + xp_stx_context_t* ctxobj; + xp_stx_method_t* mthobj; + xp_stx_byte_object_t* bytecodes; + xp_word_t bytecode_size; + xp_word_t* literals; + xp_word_t pc = 0; + int code, next, next2; - process = xp_stx_alloc_object(XP_STX_PROCESS_SIZE); - stack = xp_new_array(stx,50); - - XP_STX_CLASS(stx,process) = stx->class_process; - XP_STX_AT(stx,process,XP_STX_PROCESS_STACK) = stack; - XP_STX_AT(stx,process,XP_STX_PROCESS_STACKTOP) = XP_STX_FROM_SMALLINT(6); - XP_STX_AT(stx,process,XP_STX_PROCESS_LINK) = XP_STX_FROM_SMALLINT(1); + ctxobj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context); + mthobj = (xp_stx_method_t*)XP_STX_OBJECT(stx, ctxobj->method); - XP_STX_AT(stx,stack,0) = stx->nil; /* argument */ - XP_STX_AT(stx,stack,1) = XP_STX_FROM_SMALLINT(0); /* previous link */ - XP_STX_AT(stx,stack,2) = stx->nil; /* context */ - XP_STX_AT(stx,stack,3) = XP_STX_FROM_SMALLINT(1); /* return point */ - XP_STX_AT(stx,stack,4) = method; - XP_STX_AT(stx,stack,5) = XP_STX_FROM_SMALLINT(1); /* byte offset */ + literals = mthobj->literals; + bytecodes = XP_STX_BYTE_OBJECT(stx, mthobj->bytecodes); + bytecode_size = XP_STX_SIZE(stx, mthobj->bytecodes); - return process; -} + while (pc < bytecode_size) { + code = bytecodes->data[pc++]; -int xp_stx_execute (xp_stx_t* stx, xp_word_t process) -{ - int low, high; - byte_code_func_t bcfunc; + if (code >= 0x00 && code <= 0x3F) { + /* stack - push */ + int what = code >> 4; + int index = code & 0x0F; - 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); + switch (what) { + case 0: /* receiver variable */ + break; + case 1: /* temporary variable */ + break; + case 2: /* literal constant */ + break; + case 3: /* literal variable */ + break; + } } + else if (code >= 0x40 && code <= 0x5F) { + /* stack - store */ + int what = code >> 4; + int index = code & 0x0F; - bcfunc = byte_code_funcs[high]; - if (bcfunc != XP_NULL) { - bcfunc (stx, low); + switch (what) { + case 4: /* receiver variable */ + break; + case 5: /* temporary location */ + break; + } } - } + } return 0; } diff --git a/ase/stx/makefile.cl b/ase/stx/makefile.cl index e4ee5125..0530b2f0 100644 --- a/ase/stx/makefile.cl +++ b/ase/stx/makefile.cl @@ -1,6 +1,7 @@ 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 + stx.c memory.c object.c symbol.c class.c array.c \ + dict.c misc.c context.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.in b/ase/stx/makefile.in index 8fceb67b..04619f8b 100644 --- a/ase/stx/makefile.in +++ b/ase/stx/makefile.in @@ -1,5 +1,6 @@ -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 array.c \ + dict.c misc.c context.c name.c token.c parser.c bootstrp.c \ + bytecode.c interp.c OBJS = $(SRCS:.c=.o) OUT = libxpstx.a diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 77393654..ebb32159 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.67 2005-08-11 16:16:04 bacon Exp $ + * $Id: parser.c,v 1.68 2005-08-15 16:03:57 bacon Exp $ */ #include @@ -844,7 +844,6 @@ static int __parse_expression (xp_stx_parser_t* parser) if (__parse_basic_expression(parser, XP_NULL) == -1) return -1; } - return 0; } @@ -988,9 +987,10 @@ static int __parse_primary_ident (xp_stx_parser_t* parser, const xp_char_t* iden /* if (xp_strcmp(token->name.buffer, XP_TEXT("self")) == 0) { - EMIT_PUSH_LITERAL (parser, i); + EMIT_CODE (parser, PUSH_SELF); } else if (xp_strcmp(token->name.buffer, XP_TEXT("super")) == 0) { + EMIT_CODE (parser, PUSH_SUPER); } */ if (xp_strcmp(ident, XP_TEXT("nil")) == 0) { diff --git a/ase/stx/stx.c b/ase/stx/stx.c index 558b72f7..193e4434 100644 --- a/ase/stx/stx.c +++ b/ase/stx/stx.c @@ -1,5 +1,5 @@ /* - * $Id: stx.c,v 1.36 2005-08-11 09:57:54 bacon Exp $ + * $Id: stx.c,v 1.37 2005-08-15 16:03:57 bacon Exp $ */ #include @@ -44,9 +44,11 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity) stx->class_object = XP_STX_NIL; stx->class_class = XP_STX_NIL; - stx->class_bytearray = XP_STX_NIL; stx->class_array = XP_STX_NIL; + stx->class_bytearray = XP_STX_NIL; stx->class_string = XP_STX_NIL; + stx->class_character = XP_STX_NIL; + stx->class_context = XP_STX_NIL; stx->class_system_dictionary = XP_STX_NIL; stx->class_method = XP_STX_NIL; stx->class_smallinteger = XP_STX_NIL; diff --git a/ase/stx/stx.h b/ase/stx/stx.h index a5fb0797..5dab3900 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.40 2005-08-11 09:57:54 bacon Exp $ + * $Id: stx.h,v 1.41 2005-08-15 16:03:57 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -87,6 +87,7 @@ struct xp_stx_t xp_word_t class_bytearray; xp_word_t class_string; xp_word_t class_character; + xp_word_t class_context; xp_word_t class_system_dictionary; xp_word_t class_method; xp_word_t class_smallinteger; diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 6195b3c1..5f9c83f6 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -1,2 +1,4 @@ main + | a | + a := nil. ^nil