*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-21 15:55:50 +00:00
parent 85b20473ac
commit 70a5ead5cc
7 changed files with 59 additions and 52 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.c,v 1.18 2005-05-21 07:27:32 bacon Exp $ * $Id: object.c,v 1.19 2005-05-21 15:55:49 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
@ -45,7 +45,7 @@ xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n)
return idx; return idx;
} }
xp_stx_word_t xp_stx_alloc_string_object ( xp_stx_word_t xp_stx_alloc_char_object (
xp_stx_t* stx, const xp_stx_char_t* str) xp_stx_t* stx, const xp_stx_char_t* str)
{ {
xp_stx_word_t idx, n; xp_stx_word_t idx, n;
@ -64,7 +64,7 @@ xp_stx_word_t xp_stx_alloc_string_object (
return idx; return idx;
} }
xp_stx_word_t xp_stx_allocn_string_object (xp_stx_t* stx, ...) xp_stx_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...)
{ {
xp_stx_word_t idx, n = 0; xp_stx_word_t idx, n = 0;
const xp_stx_char_t* p; const xp_stx_char_t* p;
@ -96,7 +96,7 @@ xp_stx_word_t xp_stx_allocn_string_object (xp_stx_t* stx, ...)
return idx; return idx;
} }
xp_stx_word_t xp_stx_hash_string_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_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED); xp_stx_assert (XP_STX_TYPE(stx,idx) == XP_STX_CHAR_INDEXED);
return xp_stx_strxhash ( return xp_stx_strxhash (
@ -126,11 +126,11 @@ xp_stx_word_t xp_stx_new_class (xp_stx_t* stx, const xp_stx_char_t* name)
/* /*
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, meta_name), xp_stx_hash_char_object(stx, meta_name),
meta_name, meta); meta_name, meta);
*/ */
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, class_name), xp_stx_hash_char_object(stx, class_name),
class_name, class); class_name, class);
return class; return class;
@ -142,9 +142,9 @@ int xp_stx_lookup_global (
xp_stx_word_t link; xp_stx_word_t link;
/* TODO: maybe xp_stx_hash_object is required instead of /* TODO: maybe xp_stx_hash_object is required instead of
xp_stx_hash_string_object. */ xp_stx_hash_char_object. */
link = xp_stx_hash_lookup (stx, stx->smalltalk, link = xp_stx_hash_lookup (stx, stx->smalltalk,
xp_stx_hash_string_object(stx,key), key); xp_stx_hash_char_object(stx,key), key);
if (link == stx->nil) return -1; if (link == stx->nil) return -1;
*value = XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE); *value = XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.h,v 1.12 2005-05-18 04:01:51 bacon Exp $ * $Id: object.h,v 1.13 2005-05-21 15:55:49 bacon Exp $
*/ */
#ifndef _XP_STX_OBJECT_H_ #ifndef _XP_STX_OBJECT_H_
@ -28,11 +28,11 @@ extern "C" {
xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n); xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n);
xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n); xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n);
xp_stx_word_t xp_stx_alloc_string_object ( xp_stx_word_t xp_stx_alloc_char_object (
xp_stx_t* stx, const xp_stx_char_t* str); xp_stx_t* stx, const xp_stx_char_t* str);
xp_stx_word_t xp_stx_allocn_string_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_string_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_word_t xp_stx_new_class (
xp_stx_t* stx, const xp_stx_char_t* name); xp_stx_t* stx, const xp_stx_char_t* name);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.c,v 1.22 2005-05-21 07:27:32 bacon Exp $ * $Id: stx.c,v 1.23 2005-05-21 15:55:49 bacon Exp $
*/ */
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
@ -67,7 +67,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
symbol_Smalltalk = symbol_Smalltalk =
xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk")); xp_stx_new_symbol (stx, XP_STX_TEXT("Smalltalk"));
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx,symbol_Smalltalk), xp_stx_hash_char_object(stx,symbol_Smalltalk),
symbol_Smalltalk, stx->smalltalk); symbol_Smalltalk, stx->smalltalk);
/* create #nil, #true, #false */ /* create #nil, #true, #false */
@ -192,16 +192,16 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
/* register class names into the system dictionary */ /* register class names into the system dictionary */
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, symbol_Symlink), xp_stx_hash_char_object(stx, symbol_Symlink),
symbol_Symlink, stx->class_symlink); symbol_Symlink, stx->class_symlink);
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, symbol_Symbol), xp_stx_hash_char_object(stx, symbol_Symbol),
symbol_Symbol, stx->class_symbol); symbol_Symbol, stx->class_symbol);
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, symbol_Metaclass), xp_stx_hash_char_object(stx, symbol_Metaclass),
symbol_Metaclass, stx->class_metaclass); symbol_Metaclass, stx->class_metaclass);
xp_stx_hash_insert (stx, stx->smalltalk, xp_stx_hash_insert (stx, stx->smalltalk,
xp_stx_hash_string_object(stx, symbol_Pairlink), xp_stx_hash_char_object(stx, symbol_Pairlink),
symbol_Pairlink, stx->class_pairlink); symbol_Pairlink, stx->class_pairlink);
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.h,v 1.16 2005-05-20 04:01:12 bacon Exp $ * $Id: stx.h,v 1.17 2005-05-21 15:55:49 bacon Exp $
*/ */
#ifndef _XP_STX_STX_H_ #ifndef _XP_STX_STX_H_
@ -14,10 +14,11 @@ typedef xp_size_t xp_stx_word_t;
typedef xp_size_t xp_stx_size_t; typedef xp_size_t xp_stx_size_t;
typedef xp_size_t xp_stx_index_t; typedef xp_size_t xp_stx_index_t;
typedef struct xp_stx_objhdr_t xp_stx_objhdr_t;
typedef struct xp_stx_object_t xp_stx_object_t; typedef struct xp_stx_object_t xp_stx_object_t;
/* /*
typedef struct xp_stx_byte_object_t xp_stx_byte_object_t; typedef struct xp_stx_byte_object_t xp_stx_byte_object_t;
typedef struct xp_stx_string_object_t xp_stx_string_object_t; typedef struct xp_stx_char_object_t xp_stx_char_object_t;
*/ */
typedef struct xp_stx_memory_t xp_stx_memory_t; typedef struct xp_stx_memory_t xp_stx_memory_t;
typedef struct xp_stx_t xp_stx_t; typedef struct xp_stx_t xp_stx_t;
@ -30,28 +31,31 @@ typedef struct xp_stx_t xp_stx_t;
#define XP_STX_OBJECT_HEADER_SIZE \ #define XP_STX_OBJECT_HEADER_SIZE \
(xp_sizeof(xp_stx_object_t) - xp_sizeof(xp_stx_word_t)) (xp_sizeof(xp_stx_object_t) - xp_sizeof(xp_stx_word_t))
struct xp_stx_object_t struct xp_stx_objhdr_t
{ {
/* access - type: 2; size: rest; /* access - type: 2; size: rest;
* type - word indexed: 00 byte indexed: 01 char indexed: 10 * type - word indexed: 00 byte indexed: 01 char indexed: 10
*/ */
xp_stx_word_t access; xp_stx_word_t access;
xp_stx_word_t class; xp_stx_word_t class;
};
struct xp_stx_object_t
{
xp_stx_objhdr_t header;
/*xp_stx_word_t data[1];*/ /*xp_stx_word_t data[1];*/
}; };
/* /*
struct xp_stx_byte_object_t struct xp_stx_byte_object_t
{ {
xp_stx_word_t access; xp_stx_objhdr_t header;
xp_stx_word_t class;
xp_stx_byte_t data[1]; xp_stx_byte_t data[1];
}; };
struct xp_stx_string_object_t struct xp_stx_char_object_t
{ {
xp_stx_word_t access; xp_stx_objhdr_t header;
xp_stx_word_t class;
xp_stx_char_t data[1]; xp_stx_char_t data[1];
}; };
*/ */
@ -96,8 +100,8 @@ struct xp_stx_t
((xp_stx_object_t*)((mem)->slots[idx])) ((xp_stx_object_t*)((mem)->slots[idx]))
#define XP_STX_BYTE_OBJECT(mem,idx) \ #define XP_STX_BYTE_OBJECT(mem,idx) \
((xp_stx_byte_object_t*)((mem)->slots[idx])) ((xp_stx_byte_object_t*)((mem)->slots[idx]))
#define XP_STX_STRING_OBJECT(mem,idx) \ #define XP_STX_CHAR_OBJECT(mem,idx) \
((xp_stx_string_object_t*)((mem)->slots[idx])) ((xp_stx_char_object_t*)((mem)->slots[idx]))
#define XP_STX_OBJECT_DATA(mem,idx) \ #define XP_STX_OBJECT_DATA(mem,idx) \
((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_INDEXED)? \ ((XP_STX_OBJECT_TYPE(mem,idx) == XP_STX_INDEXED)? \
(XP_STX_OBJECT(mem,idx)).data): \ (XP_STX_OBJECT(mem,idx)).data): \
@ -107,8 +111,8 @@ struct xp_stx_t
*/ */
#define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx]) #define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx])
#define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->class) #define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.class)
#define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->access) #define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->header.access)
#define XP_STX_DATA(stx,idx) ((void*)(XP_STX_OBJECT(stx,idx) + 1)) #define XP_STX_DATA(stx,idx) ((void*)(XP_STX_OBJECT(stx,idx) + 1))
#define XP_STX_TYPE(stx,idx) (XP_STX_ACCESS(stx,idx) & 0x03) #define XP_STX_TYPE(stx,idx) (XP_STX_ACCESS(stx,idx) & 0x03)

View File

@ -1,23 +1,19 @@
/* /*
* $Id: symbol.c,v 1.3 2005-05-19 16:41:10 bacon Exp $ * $Id: symbol.c,v 1.4 2005-05-21 15:55:49 bacon Exp $
*/ */
#include <xp/stx/symbol.h> #include <xp/stx/symbol.h>
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/misc.h> #include <xp/stx/misc.h>
#define SYMLINK_SIZE 2
#define SYMLINK_LINK 0
#define SYMLINK_SYMBOL 1
xp_stx_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_stx_word_t sym) xp_stx_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_stx_word_t sym)
{ {
xp_stx_word_t x; xp_stx_word_t x;
x = xp_stx_alloc_object (stx, SYMLINK_SIZE); x = xp_stx_alloc_object (stx, XP_STX_SYMLINK_SIZE);
XP_STX_CLASS(stx,x) = stx->class_symlink; XP_STX_CLASS(stx,x) = stx->class_symlink;
/*XP_STX_AT(stx,x,SYMLINK_LINK) = stx->nil;*/ XP_STX_AT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil;
XP_STX_AT(stx,x,SYMLINK_SYMBOL) = sym; XP_STX_AT(stx,x,XP_STX_SYMLINK_SYMBOL) = sym;
return x; return x;
} }
@ -31,24 +27,24 @@ xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name)
link = XP_STX_AT(stx,table,hash); link = XP_STX_AT(stx,table,hash);
if (link == stx->nil) { if (link == stx->nil) {
x = xp_stx_alloc_string_object (stx, name); x = xp_stx_alloc_char_object (stx, name);
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x); XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x);
} }
else { else {
do { do {
x = XP_STX_AT(stx,link,SYMLINK_SYMBOL); x = XP_STX_AT(stx,link,XP_STX_SYMLINK_SYMBOL);
xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_stx_strxcmp ( if (xp_stx_strxcmp (
&XP_STX_CHARAT(stx,x,0), &XP_STX_CHARAT(stx,x,0),
XP_STX_SIZE(stx,x), name) == 0) return x; XP_STX_SIZE(stx,x), name) == 0) return x;
next = XP_STX_AT(stx,link,SYMLINK_LINK); next = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK);
if (next == stx->nil) { if (next == stx->nil) {
x = xp_stx_alloc_string_object (stx, name); x = xp_stx_alloc_char_object (stx, name);
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,link,SYMLINK_LINK) = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK) =
xp_stx_new_symlink(stx,x); xp_stx_new_symlink(stx,x);
break; break;
} }
@ -72,24 +68,24 @@ xp_stx_word_t xp_stx_new_symbol_pp (
link = XP_STX_AT(stx,table,hash); link = XP_STX_AT(stx,table,hash);
if (link == stx->nil) { if (link == stx->nil) {
x = xp_stx_allocn_string_object (stx, prefix, name, postfix); x = xp_stx_allocn_char_object (stx, prefix, name, postfix);
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x); XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x);
} }
else { else {
do { do {
x = XP_STX_AT(stx,link,SYMLINK_SYMBOL); x = XP_STX_AT(stx,link,XP_STX_SYMLINK_SYMBOL);
xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol); xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_stx_strxcmp ( if (xp_stx_strxcmp (
&XP_STX_CHARAT(stx,x,0), &XP_STX_CHARAT(stx,x,0),
XP_STX_SIZE(stx,x), name) == 0) return x; XP_STX_SIZE(stx,x), name) == 0) return x;
next = XP_STX_AT(stx,link,SYMLINK_LINK); next = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK);
if (next == stx->nil) { if (next == stx->nil) {
x = xp_stx_allocn_string_object (stx, prefix, name, postfix); x = xp_stx_allocn_char_object (stx, prefix, name, postfix);
XP_STX_CLASS(stx,x) = stx->class_symbol; XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,link,SYMLINK_LINK) = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK) =
xp_stx_new_symlink(stx,x); xp_stx_new_symlink(stx,x);
break; break;
} }
@ -116,8 +112,8 @@ void xp_stx_traverse_symbol_table (
link = XP_STX_AT(stx,table,size); link = XP_STX_AT(stx,table,size);
while (link != stx->nil) { while (link != stx->nil) {
func (stx,XP_STX_AT(stx,link,SYMLINK_SYMBOL)); func (stx,XP_STX_AT(stx,link,XP_STX_SYMLINK_SYMBOL));
link = XP_STX_AT(stx,link,SYMLINK_LINK); link = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: symbol.h,v 1.2 2005-05-18 04:01:51 bacon Exp $ * $Id: symbol.h,v 1.3 2005-05-21 15:55:49 bacon Exp $
*/ */
#ifndef _XP_STX_SYMBOL_H_ #ifndef _XP_STX_SYMBOL_H_
@ -7,6 +7,10 @@
#include <xp/stx/stx.h> #include <xp/stx/stx.h>
#define XP_STX_SYMLINK_SIZE 2
#define XP_STX_SYMLINK_LINK 0
#define XP_STX_SYMLINK_SYMBOL 1
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -5,6 +5,7 @@
#define xp_printf printf #define xp_printf printf
#else #else
#include <xp/bas/stdio.h> #include <xp/bas/stdio.h>
#include <xp/bas/locale.h>
#endif #endif
#include <xp/stx/object.h> #include <xp/stx/object.h>
@ -28,10 +29,12 @@ int xp_main (int argc, xp_char_t* argv[])
xp_stx_t stx; xp_stx_t stx;
xp_stx_word_t i; xp_stx_word_t i;
#ifndef _DOS
if (xp_setlocale () == -1) { if (xp_setlocale () == -1) {
printf ("cannot set locale\n"); printf ("cannot set locale\n");
return -1; return -1;
} }
#endif
if (argc != 2) { /* TODO: argument processing */ if (argc != 2) { /* TODO: argument processing */
xp_printf (XP_TEXT("Usage: %s [-f imageFile] MainClass\n"), argv[0]); xp_printf (XP_TEXT("Usage: %s [-f imageFile] MainClass\n"), argv[0]);