*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-22 15:03:20 +00:00
parent 0bf97fb3bd
commit 997da1dc11
13 changed files with 219 additions and 76 deletions

53
ase/stx/class.c Normal file
View File

@ -0,0 +1,53 @@
/*
* $Id: class.c,v 1.1 2005-05-22 15:03:20 bacon Exp $
*/
#include <xp/stx/class.h>
#include <xp/stx/symbol.h>
#include <xp/stx/object.h>
#include <xp/stx/hash.h>
#include <xp/stx/misc.h>
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);
}

47
ase/stx/class.h Normal file
View File

@ -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 <xp/stx/stx.h>
/* 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

View File

@ -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 <xp/stx/hash.h> #include <xp/stx/hash.h>
@ -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_t* stx, xp_stx_word_t key, xp_stx_word_t value)
{ {
xp_stx_word_t x; xp_stx_word_t x;
xp_stx_pairlink_t* obj;
x = xp_stx_alloc_word_object (stx, XP_STX_PAIRLINK_SIZE); 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_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_LINK) = stx->nil;
XP_STX_AT(stx,x,XP_STX_PAIRLINK_KEY) = key; XP_STX_AT(stx,x,XP_STX_PAIRLINK_KEY) = key;
XP_STX_AT(stx,x,XP_STX_PAIRLINK_VALUE) = value; 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; 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 hash, xp_stx_word_t key)
{ {
xp_stx_word_t link; xp_stx_word_t link;
xp_stx_pairlink_t* obj;
xp_stx_assert (XP_STX_TYPE(stx,table) == XP_STX_WORD_INDEXED); 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); link = XP_STX_AT(stx,table,hash);
while (link != stx->nil) { while (link != stx->nil) {
/*
if (XP_STX_AT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link; if (XP_STX_AT(stx,link,XP_STX_PAIRLINK_KEY) == key) return link;
link = XP_STX_AT(stx,link,XP_STX_PAIRLINK_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 */ return stx->nil; /* not found */

View File

@ -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_ #ifndef _XP_STX_HASH_H_
@ -12,6 +12,16 @@
#define XP_STX_PAIRLINK_KEY 1 #define XP_STX_PAIRLINK_KEY 1
#define XP_STX_PAIRLINK_VALUE 2 #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 #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
@ -22,6 +32,8 @@ xp_stx_word_t xp_stx_new_plink (
xp_stx_word_t xp_stx_hash_lookup ( xp_stx_word_t xp_stx_hash_lookup (
xp_stx_t* stx, xp_stx_word_t table, xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key); 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 ( void xp_stx_hash_insert (
xp_stx_t* stx, xp_stx_word_t table, xp_stx_t* stx, xp_stx_word_t table,
xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value); xp_stx_word_t hash, xp_stx_word_t key, xp_stx_word_t value);

View File

@ -1,5 +1,7 @@
SRCS = stx.c memory.c object.c symbol.c hash.c misc.c context.c token.c SRCS = stx.c memory.c object.c symbol.c class.c \
OBJS = stx.obj memory.obj object.obj symbol.obj hash.obj misc.obj context.obj token.obj 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 OUT = xpstx.lib
CC = lcc CC = lcc

View File

@ -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 <xp/stx/object.h> #include <xp/stx/object.h>
@ -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_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 ( int xp_stx_lookup_global (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value) xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value)
{ {

View File

@ -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_ #ifndef _XP_STX_OBJECT_H_
@ -11,32 +11,6 @@
#define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01) #define XP_STX_TO_SMALLINT(x) (((x) << 1) | 0x01)
#define XP_STX_FROM_SMALLINT(x) ((x) >> 1) #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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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_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_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 ( int xp_stx_lookup_global (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value); xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value);

View File

@ -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 <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -22,6 +22,7 @@ void xp_stx_parser_close (xp_stx_parser_t* parser)
{ {
if (parser->__malloced) xp_stx_free (parser); if (parser->__malloced) xp_stx_free (parser);
} }
/*
static void __emit_code ( static void __emit_code (
xp_stx_t* stx, xp_stx_word_t method, int value) 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); else __emit_code (high * 16 + low);
} }
*/
int xp_stx_parser_parse_method (xp_stx_parser_t* parser, const xp_char_t* text) int xp_stx_parser_parse_method (xp_stx_parser_t* parser, const xp_char_t* text)
{ {
return 0; 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 */
}

View File

@ -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_ #ifndef _XP_STX_PARSER_H_
#define _XP_STX_PARSER_H_ #define _XP_STX_PARSER_H_
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
#include <xp/stx/scanner.h>
struct xp_stx_parser_t struct xp_stx_parser_t
{ {
@ -19,9 +20,11 @@ extern "C" {
#endif #endif
xp_stx_parser_t* xp_stx_parser_open (xp_stx_parser_t* parser); 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_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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -3,3 +3,28 @@
*/ */
#include <xp/stx/scanner.h> #include <xp/stx/scanner.h>
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);
}

View File

@ -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_ #ifndef _XP_STX_SCANNER_H_
@ -21,7 +21,7 @@ extern "C" {
#endif #endif
xp_stx_scanner_t* xp_stx_scanner_open (xp_stx_scanner_t* scanner); 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 #ifdef __cplusplus
} }

View File

@ -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 <xp/stx/stx.h> #include <xp/stx/stx.h>
#include <xp/stx/memory.h> #include <xp/stx/memory.h>
#include <xp/stx/symbol.h>
#include <xp/stx/class.h>
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/hash.h> #include <xp/stx/hash.h>
#include <xp/stx/symbol.h>
#include <xp/stx/misc.h> #include <xp/stx/misc.h>
static void __create_bootstrapping_objects (xp_stx_t* stx); static void __create_bootstrapping_objects (xp_stx_t* stx);

View File

@ -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_ #ifndef _XP_STX_STX_H_
@ -88,6 +88,8 @@ struct xp_stx_t
xp_bool_t __wantabort; /* TODO: make it a function pointer */ 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_NIL 0
#define XP_STX_TRUE 1 #define XP_STX_TRUE 1
#define XP_STX_FALSE 2 #define XP_STX_FALSE 2