*** empty log message ***

This commit is contained in:
hyung-hwan 2005-05-08 15:22:45 +00:00
parent 6bb94d4f67
commit ca6170b0a8
4 changed files with 124 additions and 52 deletions

View File

@ -1,9 +1,10 @@
/* /*
* $Id: object.c,v 1.5 2005-05-08 13:45:51 bacon Exp $ * $Id: object.c,v 1.6 2005-05-08 15:22:45 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
#include <xp/stx/memory.h> #include <xp/stx/memory.h>
#include <xp/bas/string.h>
/* n: number of instance variables */ /* n: number of instance variables */
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)
@ -17,9 +18,9 @@ xp_stx_word_t xp_stx_alloc_object (xp_stx_t* stx, xp_stx_word_t n)
n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t)); n * xp_sizeof(xp_stx_word_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil; XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x00); XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x00);
while (n--) XP_STX_OBJECT_AT(&stx->memory,idx,n) = stx->nil; while (n--) XP_STX_AT(stx,idx,n) = stx->nil;
return idx; return idx;
} }
@ -33,36 +34,72 @@ xp_stx_word_t xp_stx_alloc_byte_object (xp_stx_t* stx, xp_stx_word_t n)
&stx->memory, n + xp_sizeof(xp_stx_object_t)); &stx->memory, n + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil; XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x01); XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x01);
while (n--) XP_STX_OBJECT_BYTEAT(&stx->memory,idx,n) = 0; while (n--) XP_STX_BYTEAT(stx,idx,n) = 0;
return idx; return idx;
} }
/* n: length of the string */ xp_stx_word_t xp_stx_alloc_string_object (xp_stx_t* stx, xp_stx_char_t* str)
xp_stx_word_t xp_stx_alloc_string_object (
xp_stx_t* stx, xp_stx_char_t* str, xp_stx_word_t n)
{ {
xp_stx_word_t idx; xp_stx_word_t idx, n;
n = xp_strlen(str);
idx = xp_stx_memory_alloc (&stx->memory, idx = xp_stx_memory_alloc (&stx->memory,
(n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t)); (n + 1) * xp_sizeof(xp_stx_char_t) + xp_sizeof(xp_stx_object_t));
if (idx >= stx->memory.capacity) return idx; /* failed */ if (idx >= stx->memory.capacity) return idx; /* failed */
XP_STX_OBJECT_CLASS(&stx->memory,idx) = stx->nil; XP_STX_CLASS(stx,idx) = stx->nil;
XP_STX_OBJECT_ACCESS(&stx->memory,idx) = ((n << 2) | 0x02); XP_STX_ACCESS(stx,idx) = ((n << 2) | 0x02);
XP_STX_OBJECT_CHARAT(&stx->memory,idx,n) = XP_STX_CHAR('\0'); XP_STX_CHARAT(stx,idx,n) = XP_STX_CHAR('\0');
while (n--) XP_STX_OBJECT_CHARAT(&stx->memory,idx,n) = str[n]; while (n--) XP_STX_CHARAT(stx,idx,n) = str[n];
return idx; return idx;
} }
xp_stx_word_t xp_stx_instantiate_symbol ( struct class_info_t
xp_stx_t* stx, xp_stx_char_t* str, xp_stx_word_t len) {
const xp_stx_char_t* name;
xp_size_word_t inst_vars;
};
typedef struct class_info_t class_info_t;
class_info_t class_info[] =
{
{ XP_STX_TEXT("Class"), 5 },
{ XP_STX_TEXT("Metaclass"), 5 },
{ XP_NULL, 0 }
};
/*
xp_stx_word_t xp_stx_instantiate_symbol (xp_stx_t* stx, xp_stx_char_t* name)
{ {
xp_stx_word_t x; xp_stx_word_t x;
x = xp_stx_alloc_string_object (stx, str, len,); return x;
if (x
} }
xp_stx_word_t xp_stx_instantiate_class (xp_stx_t* stx, xp_stx_char_t* name)
{
xp_stx_word_t x;
x = xp_str_alloc_object (str, classSize);
XP_STX_CLASS(stx,x) = globalValue("Metaclass");
XP_STX_AT(stx,x,sizeInClass) = XP_STX_TO_SMALLINT(classSize);
y = xp_str_alloc_object (str, classSize):
XP_STX_CLASS(stx,y) = x;
return x;
}
xp_stx_word_t xp_stx_instantiate_string (xp_stx_t* stx, xp_stx_char_t* str)
{
xp_stx_word_t x;
x = xp_stx_alloc_string_object (stx, str);
XP_STX_CLASS(&stx->memory,x) = stx->class_string;
return x;
}
*/

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.h,v 1.3 2005-05-08 11:16:07 bacon Exp $ * $Id: object.h,v 1.4 2005-05-08 15:22:45 bacon Exp $
*/ */
#ifndef _XP_STX_OBJECT_H_ #ifndef _XP_STX_OBJECT_H_
@ -17,8 +17,7 @@ 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_string_object (xp_stx_t* stx, xp_stx_char_t* str);
xp_stx_t* stx, xp_stx_char_t* str, xp_stx_word_t n);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,9 +1,10 @@
/* /*
* $Id: stx.c,v 1.4 2005-05-08 11:16:07 bacon Exp $ * $Id: stx.c,v 1.5 2005-05-08 15:22:45 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/object.h>
#include <xp/bas/memory.h> #include <xp/bas/memory.h>
#include <xp/bas/assert.h> #include <xp/bas/assert.h>
@ -36,20 +37,67 @@ void xp_stx_close (xp_stx_t* stx)
int xp_stx_bootstrap (xp_stx_t* stx) int xp_stx_bootstrap (xp_stx_t* stx)
{ {
xp_stx_word_t symbols; xp_stx_word_t hash_table, symbol_table;
xp_stx_word_t symbol_Symbol, symbol_Symbol_class;
xp_stx_word_t class_Symbol, class_Metaclass;
xp_stx_word_t class_UndefinedObject;
stx->nil = xp_stx_memory_alloc (&stx->memory, 0); stx->nil = xp_stx_alloc_object (stx, 0);
stx->true = xp_stx_memory_alloc (&stx->memory, 0); stx->true = xp_stx_alloc_object (stx, 0);
stx->false = xp_stx_memory_alloc (&stx->memory, 0); stx->false = xp_stx_alloc_object (stx, 0);
xp_assert (stx->nil == XP_STX_NIL); xp_assert (stx->nil == XP_STX_NIL);
xp_assert (stx->true == XP_STX_TRUE); xp_assert (stx->true == XP_STX_TRUE);
xp_assert (stx->false == XP_STX_FALSE); xp_assert (stx->false == XP_STX_FALSE);
symbol_table = xp_stx_memory_alloc (&stx->memory, 1); /* TODO: decide the size of this hash table */
XP_STX_OBJECT_AT(&stx->memory, symbol_table, 0) = hash_table; hash_table = xp_stx_alloc_object (stx, 1000);
symbol_table = xp_stx_alloc_object (stx, 1);
XP_STX_AT(stx,symbol_table,0) = hash_table;
symbol_Symbol = xp_stx_instantiate_symbol (XP_STX_TEXT("Symbol"));
symbol_Symbol_class = xp_stx_instantiate_symbol (XP_STX_TEXT("Symbol class"));
class_Symbol = xp_stx_instantiate_class (XP_STX_TEXT("Symbol"));
XP_STX_CLASS(stx,symbol_Symbol) = class_Symbol;
XP_STX_CLASS(stx,symbol_Symbol_class) = class_Symbol;
class_Metaclass = xp_stx_instantiate_class (XP_STX_TEXT("Metaclass"));
XP_STX_CLASS(stx,class_Symbol) = class_Metaclass;
XP_STX_CLASS(stx,class_Metaclass) = class_Metaclass;
class_UndefinedObject = xp_stx_instantiate_class (XP_STX_TEXT("UndefinedObject"));
class_True = xp_stx_instantiate_class (XP_STX_TEXT("True"));
class_False = xp_stx_instantiate_class (XP_STX_TEXT("False"));
symbol_nil = xp_stx_instantiate_symbol (XP_STX_TEXT("nil"));
symbol_true = xp_stx_instantiate_symbol (XP_STX_TEXT("true"));
symbol_false = xp_stx_instantiate_symbol (XP_STX_TEXT("false"));
XP_STX_CLASS(stx,stx->nil) = class_UndefinedObject;
XP_STX_CLASS(stx,stx->true) = class_True;
XP_STX_CLASS(stx,stx->false) = class_False;
insert_into_symbol_table (stx, symbol_table, symbol_nil, stx->nil);
insert_into_symbol_table (stx, symbol_table, symbol_true, stx->true);
insert_into_symbol_table (stx, symbol_table, symbol_false, stx->false);
class_Link = xp_stx_instantiate_class (XP_STX_TEXT("Link"));
/*
TODO here
*/
class_Array = xp_stx_instantiate_class (XP_STX_TEXT("Array"));
class_SymbolTable = xp_stx_instantiate_class (XP_STX_TEXT("SymbolTable"));
XP_STX_CLASS(stx,hash_table) = class_Array;
XP_STX_CLASS(stx,symbol_table) = class_SymbolTable;
insert_into_symbol_table (stx, symbol_table, symbol_table, symbol_table);
class_Object = xp_stx_instantiate_class (XP_STX_TEXT("Object"));
class_Class = xp_stx_instantiate_class (XP_STX_TEXT("Class"));
XP_STX_AT(stx,classOf(class_Object),superClass,class_Class);
XP_STX_OBJECT_CLASS(&stx->memory, sbs) = symbol_class;
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.h,v 1.4 2005-05-08 11:16:07 bacon Exp $ * $Id: stx.h,v 1.5 2005-05-08 15:22:45 bacon Exp $
*/ */
#ifndef _XP_STX_STX_H_ #ifndef _XP_STX_STX_H_
@ -84,12 +84,6 @@ struct xp_stx_t
((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_STRING_OBJECT(mem,idx) \
((xp_stx_string_object_t*)((mem)->slots[idx])) ((xp_stx_string_object_t*)((mem)->slots[idx]))
*/
#define XP_STX_OBJECT(mem,idx) ((mem)->slots[idx])
#define XP_STX_OBJECT_ACCESS(mem,idx) (XP_STX_OBJECT(mem,(idx))->access)
#define XP_STX_OBJECT_CLASS(mem,idx) (XP_STX_OBJECT(mem,(idx))->class)
/*
#define XP_STX_OBJECT_DATA(mem,idx) \ #define XP_STX_OBJECT_DATA(mem,idx) \
(((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x00)? \ (((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x00)? \
(XP_STX_OBJECT(mem,idx)).data): \ (XP_STX_OBJECT(mem,idx)).data): \
@ -98,22 +92,16 @@ struct xp_stx_t
(XP_STX_STRING_OBJECT(mem,idx)).data)) (XP_STX_STRING_OBJECT(mem,idx)).data))
*/ */
#define XP_STX_OBJECT_AT(mem,idx,n) \ #define XP_STX_OBJECT(stx,idx) (((stx)->memory).slots[idx])
(((xp_stx_word_t*)(XP_STX_OBJECT(mem,idx) + 1))[n]) #define XP_STX_ACCESS(stx,idx) (XP_STX_OBJECT(stx,(idx))->access)
#define XP_STX_OBJECT_BYTEAT(mem,idx,n) \ #define XP_STX_CLASS(stx,idx) (XP_STX_OBJECT(stx,(idx))->class)
(((xp_stx_byte_t*)(XP_STX_OBJECT(mem,idx) + 1))[n])
#define XP_STX_OBJECT_CHARAT(mem,idx,n) \
(((xp_stx_char_t*)(XP_STX_OBJECT(mem,idx) + 1))[n])
/* #define XP_STX_AT(stx,idx,n) \
#define XP_STX_OBJECT_DATA(mem,idx) \ (((xp_stx_word_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
(((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x00)? \ #define XP_STX_BYTEAT(stx,idx,n) \
(((xp_stx_word_t*)XP_STX_OBJECT(mem,idx)) + 1): \ (((xp_stx_byte_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
(((XP_STX_OBJECT_ACCESS(mem,idx) & 0x03) == 0x01)? \ #define XP_STX_CHARAT(stx,idx,n) \
(((xp_stx_byte_t*)XP_STX_OBJECT(mem,idx)) + 1): \ (((xp_stx_char_t*)(XP_STX_OBJECT(stx,idx) + 1))[n])
(((xp_stx_char_t*)XP_STX_OBJECT(mem,idx)) + 1)))
*/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {