From 997da1dc1172753bbfa1272d883aa46646015574 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 22 May 2005 15:03:20 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/class.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ ase/stx/class.h | 47 +++++++++++++++++++++++++++++++++++++++ ase/stx/hash.c | 40 ++++++++++++++++++++++++++++++++- ase/stx/hash.h | 14 +++++++++++- ase/stx/makefile.lcc | 6 +++-- ase/stx/object.c | 35 +---------------------------- ase/stx/object.h | 31 +------------------------- ase/stx/parser.c | 24 +++++++++++++++++++- ase/stx/parser.h | 7 ++++-- ase/stx/scanner.c | 25 +++++++++++++++++++++ ase/stx/scanner.h | 4 ++-- ase/stx/stx.c | 5 +++-- ase/stx/stx.h | 4 +++- 13 files changed, 219 insertions(+), 76 deletions(-) create mode 100644 ase/stx/class.c create mode 100644 ase/stx/class.h diff --git a/ase/stx/class.c b/ase/stx/class.c new file mode 100644 index 00000000..bce37446 --- /dev/null +++ b/ase/stx/class.c @@ -0,0 +1,53 @@ +/* + * $Id: class.c,v 1.1 2005-05-22 15:03:20 bacon Exp $ + */ + +#include +#include +#include +#include +#include + +xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name) +{ + xp_stx_word_t meta, class; + xp_stx_word_t /*meta_name,*/ class_name; + + meta = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE); + XP_STX_CLASS(stx,meta) = stx->class_metaclass; + XP_STX_AT(stx,meta,XP_STX_CLASS_SPEC) = + XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); + + class = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE); + XP_STX_CLASS(stx,class) = meta; + + /* + meta_name = xp_stx_new_symbol_pp ( + stx, name, XP_STX_TEXT(""), XP_STX_TEXT(" class")); + XP_STX_AT(stx,meta,XP_STX_CLASS_NAME) = meta_name; + */ + class_name = xp_stx_new_symbol (stx, name); + XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name; + + /* + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_char_object(stx, meta_name), + meta_name, meta); + */ + xp_stx_hash_insert (stx, stx->smalltalk, + xp_stx_hash_char_object(stx, class_name), + class_name, class); + + return class; +} + +xp_stx_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_stx_char_t* name) +{ + xp_stx_word_t link; + + link = xp_stx_hash_lookup_symbol (stx, stx->smalltalk, name); + if (link == stx->nil) return stx->nil; + + return XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE); +} + diff --git a/ase/stx/class.h b/ase/stx/class.h new file mode 100644 index 00000000..82430fa5 --- /dev/null +++ b/ase/stx/class.h @@ -0,0 +1,47 @@ +/* + * $Id: class.h,v 1.1 2005-05-22 15:03:20 bacon Exp $ + */ + +#ifndef _XP_STX_CLASS_H_ +#define _XP_STX_CLASS_H_ + +#include + +/* definitions for common objects */ +#define XP_STX_CLASS_SIZE 8 +#define XP_STX_CLASS_NAME 0 +#define XP_STX_CLASS_SPEC 1 +#define XP_STX_CLASS_METHODS 2 +#define XP_STX_CLASS_SUPERCLASS 3 +#define XP_STX_CLASS_VARIABLES 4 +#define XP_STX_CLASS_CLASSVARS 5 +#define XP_STX_CLASS_POOLDICT 6 +#define XP_STX_CLASS_CATEGORY 7 + +struct xp_stx_class_t +{ + xp_stx_objhdr_t header; + xp_stx_word_t name; + xp_stx_word_t spec; + xp_stx_word_t methods; + xp_stx_word_t superclass; + xp_stx_word_t variables; + xp_stx_word_t classvars; + xp_stx_word_t pooldict; + xp_stx_word_t category; +}; + +typedef struct xp_stx_class_t xp_stx_class_t; + +#ifdef __cplusplus +extern "C" { +#endif + +xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name); +xp_stx_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_stx_char_t* name); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ase/stx/hash.c b/ase/stx/hash.c index 95a4e243..5233fdcd 100644 --- a/ase/stx/hash.c +++ b/ase/stx/hash.c @@ -1,5 +1,5 @@ /* - * $Id: hash.c,v 1.16 2005-05-22 04:34:22 bacon Exp $ + * $Id: hash.c,v 1.17 2005-05-22 15:03:20 bacon Exp $ */ #include @@ -10,12 +10,20 @@ xp_stx_word_t xp_stx_new_pairlink ( xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value) { xp_stx_word_t x; + xp_stx_pairlink_t* obj; x = xp_stx_alloc_word_object (stx, XP_STX_PAIRLINK_SIZE); + obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx, x); + /* XP_STX_CLASS(stx,x) = stx->class_pairlink; XP_STX_AT(stx,x,XP_STX_PAIRLINK_LINK) = stx->nil; XP_STX_AT(stx,x,XP_STX_PAIRLINK_KEY) = key; XP_STX_AT(stx,x,XP_STX_PAIRLINK_VALUE) = value; + */ + obj->header.class = stx->class_pairlink; + obj->link = stx->nil; + obj->key = key; + obj->value = value; return x; } @@ -26,6 +34,7 @@ xp_stx_word_t xp_stx_hash_lookup ( xp_stx_word_t hash, xp_stx_word_t key) { xp_stx_word_t link; + xp_stx_pairlink_t* obj; xp_stx_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED); @@ -33,8 +42,37 @@ xp_stx_word_t xp_stx_hash_lookup ( link = XP_STX_AT(stx,table,hash); while (link != stx->nil) { + /* if (XP_STX_AT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link; link = XP_STX_AT(stx,link,XP_STX_PAIRLINK_LINK); + */ + + obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx,link); + if (obj->key == key) return link; + link = obj->link; + } + + return stx->nil; /* not found */ +} + +xp_stx_word_t xp_stx_hash_lookup_symbol ( + xp_stx_t* stx, xp_stx_word_t table, const xp_stx_char_t* name) +{ + xp_stx_word_t link, hash; + xp_stx_pairlink_t* obj; + xp_stx_char_object_t* tmp; + + xp_stx_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED); + + hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table); + link = XP_STX_AT(stx,table,hash); + + while (link != stx->nil) { + obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx,link); + tmp = XP_STX_CHAR_OBJECT(stx,obj->key); + if (tmp->header.class == stx->class_symbol && + xp_stx_strcmp (tmp->data, name) == 0) return link; + link = obj->link; } return stx->nil; /* not found */ diff --git a/ase/stx/hash.h b/ase/stx/hash.h index 3832344b..fa42214c 100644 --- a/ase/stx/hash.h +++ b/ase/stx/hash.h @@ -1,5 +1,5 @@ /* - * $Id: hash.h,v 1.7 2005-05-19 15:04:21 bacon Exp $ + * $Id: hash.h,v 1.8 2005-05-22 15:03:20 bacon Exp $ */ #ifndef _XP_STX_HASH_H_ @@ -12,6 +12,16 @@ #define XP_STX_PAIRLINK_KEY 1 #define XP_STX_PAIRLINK_VALUE 2 +struct xp_stx_pairlink_t +{ + xp_stx_objhdr_t header; + xp_stx_word_t link; + xp_stx_word_t key; + xp_stx_word_t value; +}; + +typedef struct xp_stx_pairlink_t xp_stx_pairlink_t; + #ifdef __cplusplus extern "C" #endif @@ -22,6 +32,8 @@ xp_stx_word_t xp_stx_new_plink ( xp_stx_word_t xp_stx_hash_lookup ( xp_stx_t* stx, xp_stx_word_t table, xp_stx_word_t hash, xp_stx_word_t key); +xp_stx_word_t xp_stx_hash_lookup_symbol ( + xp_stx_t* stx, xp_stx_word_t table, const xp_stx_char_t* name); void xp_stx_hash_insert ( xp_stx_t* stx, xp_stx_word_t table, xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value); diff --git a/ase/stx/makefile.lcc b/ase/stx/makefile.lcc index fa738e1e..b1ac02f8 100644 --- a/ase/stx/makefile.lcc +++ b/ase/stx/makefile.lcc @@ -1,5 +1,7 @@ -SRCS = stx.c memory.c object.c symbol.c hash.c misc.c context.c token.c -OBJS = stx.obj memory.obj object.obj symbol.obj hash.obj misc.obj context.obj token.obj +SRCS = stx.c memory.c object.c symbol.c class.c \ + hash.c misc.c context.c token.c parser.c +OBJS = stx.obj memory.obj object.obj symbol.obj class.obj \ + hash.obj misc.obj context.obj token.obj parser.obj OUT = xpstx.lib CC = lcc diff --git a/ase/stx/object.c b/ase/stx/object.c index 3f948414..50f29a7d 100644 --- a/ase/stx/object.c +++ b/ase/stx/object.c @@ -1,5 +1,5 @@ /* - * $Id: object.c,v 1.20 2005-05-22 04:34:22 bacon Exp $ + * $Id: object.c,v 1.21 2005-05-22 15:03:20 bacon Exp $ */ #include @@ -138,39 +138,6 @@ xp_stx_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_stx_word_t idx) &XP_STX_CHARAT(stx,idx,0), XP_STX_SIZE(stx,idx)); } -xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name) -{ - xp_stx_word_t meta, class; - xp_stx_word_t /*meta_name,*/ class_name; - - meta = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE); - XP_STX_CLASS(stx,meta) = stx->class_metaclass; - XP_STX_AT(stx,meta,XP_STX_CLASS_SPEC) = - XP_STX_TO_SMALLINT(XP_STX_CLASS_SIZE); - - class = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE); - XP_STX_CLASS(stx,class) = meta; - - /* - meta_name = xp_stx_new_symbol_pp ( - stx, name, XP_STX_TEXT(""), XP_STX_TEXT(" class")); - XP_STX_AT(stx,meta,XP_STX_CLASS_NAME) = meta_name; - */ - class_name = xp_stx_new_symbol (stx, name); - XP_STX_AT(stx,class,XP_STX_CLASS_NAME) = class_name; - - /* - xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, meta_name), - meta_name, meta); - */ - xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, class_name), - class_name, class); - - return class; -} - int xp_stx_lookup_global ( xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value) { diff --git a/ase/stx/object.h b/ase/stx/object.h index 35fdacb2..e562b02a 100644 --- a/ase/stx/object.h +++ b/ase/stx/object.h @@ -1,5 +1,5 @@ /* - * $Id: object.h,v 1.15 2005-05-22 04:34:22 bacon Exp $ + * $Id: object.h,v 1.16 2005-05-22 15:03:20 bacon Exp $ */ #ifndef _XP_STX_OBJECT_H_ @@ -11,32 +11,6 @@ #define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01) #define XP_STX_FROM_SMALLINT(x) ((x) >> 1) -/* definitions for common objects */ -#define XP_STX_CLASS_SIZE 8 -#define XP_STX_CLASS_NAME 0 -#define XP_STX_CLASS_SPEC 1 -#define XP_STX_CLASS_METHODS 2 -#define XP_STX_CLASS_SUPERCLASS 3 -#define XP_STX_CLASS_VARIABLES 4 -#define XP_STX_CLASS_CLASSVARS 5 -#define XP_STX_CLASS_POOLDICT 6 -#define XP_STX_CLASS_CATEGORY 7 - -struct xp_stx_class_t -{ - xp_stx_objhdr_t header; - xp_stx_word_t name; - xp_stx_word_t spec; - xp_stx_word_t methods; - xp_stx_word_t superclass; - xp_stx_word_t variables; - xp_stx_word_t classvars; - xp_stx_word_t pooldict; - xp_stx_word_t category; -}; - -typedef struct xp_stx_class_t xp_stx_class_t; - #ifdef __cplusplus extern "C" { #endif @@ -48,9 +22,6 @@ xp_stx_word_t xp_stx_alloc_char_object ( xp_stx_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...); xp_stx_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_stx_word_t idx); -xp_stx_word_t xp_stx_new_class ( - xp_stx_t* stx, const xp_stx_char_t* name); - int xp_stx_lookup_global ( xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value); diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 4cd83e3f..574b4c53 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.2 2005-05-22 04:11:54 bacon Exp $ + * $Id: parser.c,v 1.3 2005-05-22 15:03:20 bacon Exp $ */ #include @@ -22,6 +22,7 @@ void xp_stx_parser_close (xp_stx_parser_t* parser) { if (parser->__malloced) xp_stx_free (parser); } +/* static void __emit_code ( xp_stx_t* stx, xp_stx_word_t method, int value) @@ -37,9 +38,30 @@ static void __emit_instruction ( } else __emit_code (high * 16 + low); } +*/ int xp_stx_parser_parse_method (xp_stx_parser_t* parser, const xp_char_t* text) { return 0; } + +int xp_stx_filein_raw (xp_stx_t* stx, xp_stx_getc_t getc) +{ + xp_cint_t c; + +/* + getc() + gettoken (); + if (token->type == XP_STX_TOKEN_IDENT) { + ident: + } +*/ + + return 0; +} + +int xp_stx_get_token () +{ +/* getc */ +} diff --git a/ase/stx/parser.h b/ase/stx/parser.h index 78b1578e..e34c5493 100644 --- a/ase/stx/parser.h +++ b/ase/stx/parser.h @@ -1,11 +1,12 @@ /* - * $Id: parser.h,v 1.2 2005-05-22 04:11:54 bacon Exp $ + * $Id: parser.h,v 1.3 2005-05-22 15:03:20 bacon Exp $ */ #ifndef _XP_STX_PARSER_H_ #define _XP_STX_PARSER_H_ #include +#include struct xp_stx_parser_t { @@ -19,9 +20,11 @@ extern "C" { #endif xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser); -int xp_stx_parser_close (xp_stx_parser_t* parser); +void xp_stx_parser_close (xp_stx_parser_t* parser); int xp_stx_parser_parse (xp_stx_parser_t* parser, const xp_char_t* text); +int xp_stx_filein_raw (xp_stx_t* parser, xp_stx_getc_t getc); + #ifdef __cplusplus } #endif diff --git a/ase/stx/scanner.c b/ase/stx/scanner.c index a6f7c1c7..2728dbdb 100644 --- a/ase/stx/scanner.c +++ b/ase/stx/scanner.c @@ -3,3 +3,28 @@ */ #include + +xp_stx_scanner_t* xp_stx_scanner_open (xp_stx_scanner_t* scanner) +{ + if (scanner == XP_NULL) { + scanner = (xp_stx_scanner_t*) + xp_stx_malloc (xp_sizeof(xp_stx_scanner_t)); + if (scanner == XP_NULL) return XP_NULL; + scanner->__malloced = xp_true; + } + else scanner->__malloced = xp_false; + + if (xp_stx_token_open (&scanner->token) == XP_NULL) { + if (scanner->__malloced) xp_stx_free (scanner); + return XP_NULL; + } + + return scanner; +}; + +void xp_stx_scanner_close (xp_stx_scanner_t* scanner) +{ + xp_stx_token_close (&scanner->token); + if (scanner->__malloced) xp_stx_free (scanner); +} + diff --git a/ase/stx/scanner.h b/ase/stx/scanner.h index f8c9f6f8..9c5e5b43 100644 --- a/ase/stx/scanner.h +++ b/ase/stx/scanner.h @@ -1,5 +1,5 @@ /* - * $Id: scanner.h,v 1.2 2005-05-22 13:41:14 bacon Exp $ + * $Id: scanner.h,v 1.3 2005-05-22 15:03:20 bacon Exp $ */ #ifndef _XP_STX_SCANNER_H_ @@ -21,7 +21,7 @@ extern "C" { #endif xp_stx_scanner_t* xp_stx_scanner_open (xp_stx_scanner_t* scanner); -void xp_stx_scanner_close (xp_stx_scanner_t* scanner): +void xp_stx_scanner_close (xp_stx_scanner_t* scanner); #ifdef __cplusplus } diff --git a/ase/stx/stx.c b/ase/stx/stx.c index 6d865021..17f51a4c 100644 --- a/ase/stx/stx.c +++ b/ase/stx/stx.c @@ -1,12 +1,13 @@ /* - * $Id: stx.c,v 1.25 2005-05-22 09:16:18 bacon Exp $ + * $Id: stx.c,v 1.26 2005-05-22 15:03:20 bacon Exp $ */ #include #include +#include +#include #include #include -#include #include static void __create_bootstrapping_objects (xp_stx_t* stx); diff --git a/ase/stx/stx.h b/ase/stx/stx.h index 781267bf..27287f37 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.19 2005-05-22 13:41:14 bacon Exp $ + * $Id: stx.h,v 1.20 2005-05-22 15:03:20 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -88,6 +88,8 @@ struct xp_stx_t xp_bool_t __wantabort; /* TODO: make it a function pointer */ }; +typedef xp_stx_cint_t (*xp_stx_getc_t) (void*); + #define XP_STX_NIL 0 #define XP_STX_TRUE 1 #define XP_STX_FALSE 2