*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-23 14:43:03 +00:00
parent 7abd54ea12
commit 05951ad1bf
8 changed files with 174 additions and 73 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: bootstrp.c,v 1.1 2005-05-23 12:06:53 bacon Exp $
* $Id: bootstrp.c,v 1.2 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/bootstrp.h>
@ -11,6 +11,7 @@
static void __create_bootstrapping_objects (xp_stx_t* stx);
static void __create_builtin_classes (xp_stx_t* stx);
static xp_stx_word_t __count_names (const xp_stx_char_t* str);
struct class_info_t
{
@ -23,117 +24,122 @@ struct class_info_t
typedef struct class_info_t class_info_t;
#define T XP_STX_TEXT
static class_info_t class_info[] =
{
{
T("Object"),
XP_STX_TEXT("Object"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("UndefinedObject"),
T("Object"),
XP_STX_TEXT("UndefinedObject"),
XP_STX_TEXT("Object"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Behavior"),
T("Object"),
T("name instanceSize methods superclass intsanceVariables classVariables poolDictionaries category"),
XP_STX_TEXT("Behavior"),
XP_STX_TEXT("Object"),
XP_STX_TEXT("name instanceSize methods superclass intsanceVariables classVariables poolDictionaries category"),
XP_NULL,
XP_NULL
},
{
T("Class"),
T("Behavior"),
XP_STX_TEXT("Class"),
XP_STX_TEXT("Behavior"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Metaclass"),
T("Behavior"),
XP_STX_TEXT("Metaclass"),
XP_STX_TEXT("Behavior"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Block"),
T("Object"),
T("context argCount argLoc bytePointer"),
XP_STX_TEXT("Block"),
XP_STX_TEXT("Object"),
XP_STX_TEXT("context argCount argLoc bytePointer"),
XP_NULL,
XP_NULL
},
{
T("Boolean"),
T("Object"),
XP_STX_TEXT("Boolean"),
XP_STX_TEXT("Object"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("True"),
T("Boolean"),
XP_STX_TEXT("True"),
XP_STX_TEXT("Boolean"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("False"),
T("Boolean"),
XP_STX_TEXT("False"),
XP_STX_TEXT("Boolean"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Context"),
T("Object"),
XP_STX_TEXT("Context"),
XP_STX_TEXT("Object"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Method"),
T("Object"),
T("text message bytecodes literals stackSize temporarySize class"),
XP_STX_TEXT("Method"),
XP_STX_TEXT("Object"),
XP_STX_TEXT("text message bytecodes literals stackSize temporarySize class"),
XP_NULL,
XP_NULL
},
{
T("Magnitude"),
T("Object"),
XP_STX_TEXT("Magnitude"),
XP_STX_TEXT("Object"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("Collection"),
T("Magnitude"),
XP_STX_TEXT("Collection"),
XP_STX_TEXT("Magnitude"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("IndexedCollection"),
T("Collection"),
XP_STX_TEXT("IndexedCollection"),
XP_STX_TEXT("Collection"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("SymbolTable"),
T("IndexedCollection"),
XP_STX_TEXT("Array"),
XP_STX_TEXT("IndexedCollection"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
T("SystemDictionary"),
T("IndexedCollection"),
XP_STX_TEXT("SymbolTable"),
XP_STX_TEXT("IndexedCollection"),
XP_NULL,
XP_NULL,
XP_NULL
},
{
XP_STX_TEXT("SystemDictionary"),
XP_STX_TEXT("IndexedCollection"),
XP_NULL,
XP_NULL,
XP_NULL
@ -147,6 +153,11 @@ static class_info_t class_info[] =
}
};
int xp_stx_new_array (xp_stx_t* stx, xp_stx_word_t size)
{
return 0;
}
int xp_stx_bootstrap (xp_stx_t* stx)
{
xp_stx_word_t symbol_Smalltalk;
@ -154,6 +165,11 @@ int xp_stx_bootstrap (xp_stx_t* stx)
xp_stx_word_t tmp;
__create_bootstrapping_objects (stx);
/* array class is precreated for easier instansition
* of builtin classes */
stx->class_array = xp_stx_new_class (stx, XP_STX_TEXT("Array"));
__create_builtin_classes (stx);
/* more initialization */
@ -299,14 +315,17 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
symbol_Pairlink, stx->class_pairlink);
}
static void __create_builtin_classes (xp_stx_t* stx)
{
class_info_t* p = class_info;
xp_stx_word_t class;
class_info_t* p;
xp_stx_word_t class, array;
xp_stx_class_t* class_obj;
xp_stx_word_object_t* array_obj;
xp_stx_word_t n;
while (p->name != XP_NULL) {
xp_stx_assert (stx->class_array != stx->nil);
for (p = class_info; p->name != XP_NULL; p++) {
class = xp_stx_lookup_class(stx, p->name);
if (class == stx->nil) {
class = xp_stx_new_class (stx, p->name);
@ -318,6 +337,58 @@ static void __create_builtin_classes (xp_stx_t* stx)
class_obj->superclass = (p->superclass == XP_NULL)?
stx->nil: xp_stx_lookup_class(stx,p->superclass);
p++;
/*TODO:handle variables of super class first.... */
if (p->instance_variables != XP_NULL) {
n = __count_names (p->instance_variables);
array = xp_stx_new_array (stx, n);
array_obj = XP_STX_DATA(stx,array);
__set_names (array_obj, p->instance_variables);
class_obj->variables = array;
}
if (p->class_variables != XP_NULL) {
n = __count_names (p->instance_variables);
array = xp_stx_new_array (stx, n);
class_obj->classvars = array;
}
}
}
static xp_stx_word_t __count_names (const xp_stx_char_t* str)
{
xp_stx_word_t n = 0;
const xp_stx_char_t* p = str;
do {
while (*p == XP_STX_CHAR(' ') ||
*p == XP_STX_CHAR('\t')) p++;
if (*p == XP_STX_CHAR('\0')) break;
n++;
while (*p != XP_STX_CHAR(' ') &&
*p != XP_STX_CHAR('\t') &&
*p != XP_STX_CHAR('\0')) p++;
} while (1);
return n;
}
static void __set_names (const xp_stx_char_t* str)
{
xp_stx_word_t n = 0;
const xp_stx_char_t* p = str;
do {
while (*p == XP_STX_CHAR(' ') ||
*p == XP_STX_CHAR('\t')) p++;
if (*p == XP_STX_CHAR('\0')) break;
n++;
while (*p != XP_STX_CHAR(' ') &&
*p != XP_STX_CHAR('\t') &&
*p != XP_STX_CHAR('\0')) p++;
} while (1);
return n;
}

View File

@ -1,9 +1,10 @@
/*
* $Id: context.c,v 1.6 2005-05-22 04:34:22 bacon Exp $
* $Id: context.c,v 1.7 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/context.h>
#include <xp/stx/object.h>
#include <xp/stx/class.h>
#include <xp/stx/misc.h>
xp_stx_word_t xp_stx_new_context (xp_stx_t* stx,
@ -22,7 +23,7 @@ xp_stx_word_t xp_stx_new_context (xp_stx_t* stx,
*/
obj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
obj->header.class = stx->class_context;
obj->header.class = xp_stx_lookup_class(stx,XP_STX_TEXT("Context"));
obj->ip = XP_STX_TO_SMALLINT(0);
obj->method = method;
obj->arguments = args;

View File

@ -1,5 +1,5 @@
/*
* $Id: object.c,v 1.21 2005-05-22 15:03:20 bacon Exp $
* $Id: object.c,v 1.22 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/object.h>
@ -135,20 +135,6 @@ 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);
return xp_stx_strxhash (
&XP_STX_CHARAT(stx,idx,0), XP_STX_SIZE(stx,idx));
XP_STX_DATA(stx,idx), XP_STX_SIZE(stx,idx));
}
int xp_stx_lookup_global (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t* value)
{
xp_stx_word_t link;
/* TODO: maybe xp_stx_hash_object is required instead of
xp_stx_hash_char_object. */
link = xp_stx_hash_lookup (stx, stx->smalltalk,
xp_stx_hash_char_object(stx,key), key);
if (link == stx->nil) return -1;
*value = XP_STX_AT(stx,link,XP_STX_PAIRLINK_VALUE);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: parser.c,v 1.3 2005-05-22 15:03:20 bacon Exp $
* $Id: parser.c,v 1.4 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/parser.h>
@ -48,9 +48,9 @@ int xp_stx_parser_parse_method (xp_stx_parser_t* parser, const xp_char_t* text)
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) {

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.c,v 1.27 2005-05-22 15:38:31 bacon Exp $
* $Id: stx.c,v 1.28 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/stx.h>
@ -32,8 +32,7 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_stx_word_t capacity)
stx->class_metaclass = XP_STX_NIL;
stx->class_pairlink = XP_STX_NIL;
stx->class_method = XP_STX_NIL;
stx->class_context = XP_STX_NIL;
stx->class_array = XP_STX_NIL;
stx->__wantabort = xp_false;
return stx;

View File

@ -1,5 +1,5 @@
/*
* $Id: stx.h,v 1.20 2005-05-22 15:03:20 bacon Exp $
* $Id: stx.h,v 1.21 2005-05-23 14:43:03 bacon Exp $
*/
#ifndef _XP_STX_STX_H_
@ -80,9 +80,8 @@ struct xp_stx_t
xp_stx_word_t class_symbol;
xp_stx_word_t class_metaclass;
xp_stx_word_t class_pairlink;
xp_stx_word_t class_method;
xp_stx_word_t class_context;
xp_stx_word_t class_array;
xp_bool_t __malloced;
xp_bool_t __wantabort; /* TODO: make it a function pointer */

View File

@ -1,5 +1,5 @@
/*
* $Id: symbol.c,v 1.5 2005-05-22 04:34:22 bacon Exp $
* $Id: symbol.c,v 1.6 2005-05-23 14:43:03 bacon Exp $
*/
#include <xp/stx/symbol.h>
@ -52,7 +52,44 @@ xp_stx_word_t xp_stx_new_symbol (xp_stx_t* stx, const xp_stx_char_t* name)
link = next;
} while (1);
}
return x;
}
xp_stx_word_t xp_stx_new_symbol_with_len (
{
xp_stx_word_t x, hash, table, link, next;
table = stx->symbol_table;
hash = xp_stx_strhash(name) % XP_STX_SIZE(stx,table);
link = XP_STX_AT(stx,table,hash);
if (link == stx->nil) {
x = xp_stx_alloc_char_object (stx, name);
XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,table,hash) = xp_stx_new_symlink(stx,x);
}
else {
do {
x = XP_STX_AT(stx,link,XP_STX_SYMLINK_SYMBOL);
xp_stx_assert (XP_STX_CLASS(stx,x) == stx->class_symbol);
if (xp_stx_strxcmp (
&XP_STX_CHARAT(stx,x,0),
XP_STX_SIZE(stx,x), name) == 0) return x;
next = XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK);
if (next == stx->nil) {
x = xp_stx_alloc_char_object (stx, name);
XP_STX_CLASS(stx,x) = stx->class_symbol;
XP_STX_AT(stx,link,XP_STX_SYMLINK_LINK) =
xp_stx_new_symlink(stx,x);
break;
}
link = next;
} while (1);
}
return x;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: symbol.h,v 1.3 2005-05-21 15:55:49 bacon Exp $
* $Id: symbol.h,v 1.4 2005-05-23 14:43:03 bacon Exp $
*/
#ifndef _XP_STX_SYMBOL_H_
@ -11,6 +11,15 @@
#define XP_STX_SYMLINK_LINK 0
#define XP_STX_SYMLINK_SYMBOL 1
struct xp_stx_symlink_t
{
xp_stx_objhdr_t header;
xp_stx_word_t link;
xp_stx_word_t symbol;
};
typedef struct xp_stx_symlink_t xp_stx_symlink_t;
#ifdef __cplusplus
extern "C" {
#endif
@ -23,7 +32,6 @@ xp_stx_word_t xp_stx_new_symbol_pp (
void xp_stx_traverse_symbol_table (
xp_stx_t* stx, void (*func) (xp_stx_t*,xp_stx_word_t));
#ifdef __cplusplus
}
#endif