*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-05 06:26:33 +00:00
parent bd9d441a4c
commit fd769d0f29
8 changed files with 68 additions and 75 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bootstrp.c,v 1.19 2005-07-05 04:29:31 bacon Exp $ * $Id: bootstrp.c,v 1.20 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/bootstrp.h> #include <xp/stx/bootstrp.h>
@ -248,7 +248,7 @@ xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size)
xp_word_t x; xp_word_t x;
xp_assert (stx->class_array != stx->nil); xp_assert (stx->class_array != stx->nil);
x = xp_stx_alloc_word_object (stx, size); x = xp_stx_alloc_word_object (stx, XP_NULL, size);
XP_STX_CLASS(stx,x) = stx->class_array; XP_STX_CLASS(stx,x) = stx->class_array;
return x; return x;
@ -341,9 +341,9 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
xp_word_t symbol_Pairlink; xp_word_t symbol_Pairlink;
/* allocate three keyword objects */ /* allocate three keyword objects */
stx->nil = xp_stx_alloc_word_object (stx, 0); stx->nil = xp_stx_alloc_word_object (stx, XP_NULL, 0);
stx->true = xp_stx_alloc_word_object (stx, 0); stx->true = xp_stx_alloc_word_object (stx, XP_NULL, 0);
stx->false = xp_stx_alloc_word_object (stx, 0); stx->false = xp_stx_alloc_word_object (stx, XP_NULL, 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);
@ -351,30 +351,30 @@ static void __create_bootstrapping_objects (xp_stx_t* stx)
/* symbol table & system dictionary */ /* symbol table & system dictionary */
/* TODO: symbol table and dictionary size */ /* TODO: symbol table and dictionary size */
stx->symbol_table = xp_stx_alloc_word_object (stx, 1000); stx->symbol_table = xp_stx_alloc_word_object (stx, XP_NULL, 1000);
stx->smalltalk = xp_stx_alloc_word_object (stx, 2000); stx->smalltalk = xp_stx_alloc_word_object (stx, XP_NULL, 2000);
stx->class_symlink = /* Symlink */ stx->class_symlink = /* Symlink */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_CLASS_SIZE);
stx->class_symbol = /* Symbol */ stx->class_symbol = /* Symbol */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_CLASS_SIZE);
stx->class_metaclass = /* Metaclass */ stx->class_metaclass = /* Metaclass */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_CLASS_SIZE);
stx->class_pairlink = /* Pairlink */ stx->class_pairlink = /* Pairlink */
xp_stx_alloc_word_object(stx,XP_STX_CLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_CLASS_SIZE);
/* Metaclass is a class so it has the same structure /* Metaclass is a class so it has the same structure
* as a normal class. "Metaclass class" is an instance of * as a normal class. "Metaclass class" is an instance of
* Metaclass. */ * Metaclass. */
class_SymlinkMeta = /* Symlink class */ class_SymlinkMeta = /* Symlink class */
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_METACLASS_SIZE);
class_SymbolMeta = /* Symbol class */ class_SymbolMeta = /* Symbol class */
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_METACLASS_SIZE);
class_MetaclassMeta = /* Metaclass class */ class_MetaclassMeta = /* Metaclass class */
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_METACLASS_SIZE);
class_PairlinkMeta = /* Pairlink class */ class_PairlinkMeta = /* Pairlink class */
xp_stx_alloc_word_object(stx,XP_STX_METACLASS_SIZE); xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_METACLASS_SIZE);
/* (Symlink class) setClass: Metaclass */ /* (Symlink class) setClass: Metaclass */
XP_STX_CLASS(stx,class_SymlinkMeta) = stx->class_metaclass; XP_STX_CLASS(stx,class_SymlinkMeta) = stx->class_metaclass;
@ -510,15 +510,6 @@ static void __create_builtin_classes (xp_stx_t* stx)
class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class); class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class);
/*
if (p->class_variables != XP_NULL) {
n = __count_names (p->class_variables);
array = xp_stx_new_array (stx, n);
__set_names (stx, XP_STX_DATA(stx,array), p->class_variables);
class_obj->class_variables = array;
}
*/
if (p->class_variables != XP_NULL) { if (p->class_variables != XP_NULL) {
class_obj->class_variables = class_obj->class_variables =
__make_classvar_dict(stx, class, p->class_variables); __make_classvar_dict(stx, class, p->class_variables);
@ -650,7 +641,7 @@ static xp_word_t __make_classvar_dict (
const xp_char_t* name; const xp_char_t* name;
dict = xp_stx_instantiate ( dict = xp_stx_instantiate (
stx, stx->class_dictionary, __count_names(names)); stx, stx->class_dictionary, XP_NULL, __count_names(names));
do { do {
while (*p == XP_CHAR(' ') || while (*p == XP_CHAR(' ') ||

View File

@ -1,5 +1,5 @@
/* /*
* $Id: class.c,v 1.17 2005-07-05 04:29:31 bacon Exp $ * $Id: class.c,v 1.18 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/class.h> #include <xp/stx/class.h>
@ -13,7 +13,7 @@ xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name)
xp_word_t meta, class; xp_word_t meta, class;
xp_word_t class_name; xp_word_t class_name;
meta = xp_stx_alloc_word_object (stx, XP_STX_METACLASS_SIZE); meta = xp_stx_alloc_word_object (stx, XP_NULL, XP_STX_METACLASS_SIZE);
XP_STX_CLASS(stx,meta) = stx->class_metaclass; XP_STX_CLASS(stx,meta) = stx->class_metaclass;
/* the spec of the metaclass must be the spec of its /* the spec of the metaclass must be the spec of its
* instance. so the XP_STX_CLASS_SIZE is set */ * instance. so the XP_STX_CLASS_SIZE is set */
@ -21,7 +21,7 @@ xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name)
XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE); XP_STX_TO_SMALLINT((XP_STX_CLASS_SIZE << XP_STX_SPEC_INDEXABLE_BITS) | XP_STX_SPEC_NOT_INDEXABLE);
/* the spec of the class is set later in __create_builtin_classes */ /* the spec of the class is set later in __create_builtin_classes */
class = xp_stx_alloc_word_object (stx, XP_STX_CLASS_SIZE); class = xp_stx_alloc_word_object (stx, XP_NULL, XP_STX_CLASS_SIZE);
XP_STX_CLASS(stx,class) = meta; XP_STX_CLASS(stx,class) = meta;
class_name = xp_stx_new_symbol (stx, name); class_name = xp_stx_new_symbol (stx, name);
XP_STX_WORDAT(stx,class,XP_STX_CLASS_NAME) = class_name; XP_STX_WORDAT(stx,class,XP_STX_CLASS_NAME) = class_name;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: context.c,v 1.8 2005-06-08 16:00:51 bacon Exp $ * $Id: context.c,v 1.9 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/context.h> #include <xp/stx/context.h>
@ -13,15 +13,7 @@ xp_word_t xp_stx_new_context (xp_stx_t* stx,
xp_word_t context; xp_word_t context;
xp_stx_context_t* obj; xp_stx_context_t* obj;
context = xp_stx_alloc_word_object(stx,XP_STX_CONTEXT_SIZE); context = xp_stx_alloc_word_object(stx, XP_NULL, XP_STX_CONTEXT_SIZE);
/*
XP_STX_CLASS(stx,context) = stx->class_context;
XP_STX_AT(stx,context,XP_STX_CONTEXT_IP) = XP_STX_TO_SMALLINT(0);
XP_STX_AT(stx,context,XP_STX_CONTEXT_METHOD) = method;
XP_STX_AT(stx,context,XP_STX_CONTEXT_ARGUMENTS) = args;
XP_STX_AT(stx,context,XP_STX_CONTEXT_TEMPORARIES) = temp;
*/
obj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context); obj = (xp_stx_context_t*)XP_STX_OBJECT(stx,context);
obj->header.class = xp_stx_lookup_class(stx,XP_TEXT("Context")); obj->header.class = xp_stx_lookup_class(stx,XP_TEXT("Context"));
obj->ip = XP_STX_TO_SMALLINT(0); obj->ip = XP_STX_TO_SMALLINT(0);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: hash.c,v 1.21 2005-06-30 12:07:02 bacon Exp $ * $Id: hash.c,v 1.22 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/hash.h> #include <xp/stx/hash.h>
@ -12,14 +12,8 @@ xp_word_t xp_stx_new_pairlink (
xp_word_t x; xp_word_t x;
xp_stx_pairlink_t* obj; xp_stx_pairlink_t* obj;
x = xp_stx_alloc_word_object (stx, XP_STX_PAIRLINK_SIZE); x = xp_stx_alloc_word_object (stx, XP_NULL, XP_STX_PAIRLINK_SIZE);
obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx, x); obj = (xp_stx_pairlink_t*)XP_STX_WORD_OBJECT(stx, x);
/*
XP_STX_CLASS(stx,x) = stx->class_pairlink;
XP_STX_WORDAT(stx,x,XP_STX_PAIRLINK_LINK) = stx->nil;
XP_STX_WORDAT(stx,x,XP_STX_PAIRLINK_KEY) = key;
XP_STX_WORDAT(stx,x,XP_STX_PAIRLINK_VALUE) = value;
*/
obj->header.class = stx->class_pairlink; obj->header.class = stx->class_pairlink;
obj->link = stx->nil; obj->link = stx->nil;
obj->key = key; obj->key = key;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.c,v 1.30 2005-07-05 04:29:31 bacon Exp $ * $Id: object.c,v 1.31 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/object.h> #include <xp/stx/object.h>
@ -10,7 +10,8 @@
#include <xp/stx/misc.h> #include <xp/stx/misc.h>
/* n: number of instance variables */ /* n: number of instance variables */
xp_word_t xp_stx_alloc_word_object (xp_stx_t* stx, xp_word_t n) xp_word_t xp_stx_alloc_word_object (
xp_stx_t* stx, const xp_word_t* data, xp_word_t n)
{ {
xp_word_t idx; xp_word_t idx;
xp_stx_word_object_t* obj; xp_stx_word_object_t* obj;
@ -32,7 +33,12 @@ xp_word_t xp_stx_alloc_word_object (xp_stx_t* stx, xp_word_t n)
obj = XP_STX_WORD_OBJECT(stx,idx); obj = XP_STX_WORD_OBJECT(stx,idx);
obj->header.class = stx->nil; obj->header.class = stx->nil;
obj->header.access = (n << 2) | XP_STX_WORD_INDEXED; obj->header.access = (n << 2) | XP_STX_WORD_INDEXED;
while (n-- > 0) obj->data[n] = stx->nil; if (data == XP_NULL) {
while (n-- > 0) obj->data[n] = stx->nil;
}
else {
while (n-- > 0) obj->data[n] = data[n];
}
return idx; return idx;
} }
@ -62,7 +68,7 @@ xp_word_t xp_stx_alloc_byte_object (
if (data == XP_NULL) { if (data == XP_NULL) {
while (n-- > 0) obj->data[n] = 0; while (n-- > 0) obj->data[n] = 0;
} }
else { else {
while (n-- > 0) obj->data[n] = data[n]; while (n-- > 0) obj->data[n] = data[n];
} }
@ -160,7 +166,7 @@ xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx)
} }
xp_word_t xp_stx_instantiate ( xp_word_t xp_stx_instantiate (
xp_stx_t* stx, xp_word_t class_index, xp_word_t size) xp_stx_t* stx, xp_word_t class_index, const void* data, xp_word_t size)
{ {
xp_stx_class_t* class_obj; xp_stx_class_t* class_obj;
xp_word_t spec, nfields, new; xp_word_t spec, nfields, new;
@ -181,20 +187,22 @@ xp_word_t xp_stx_instantiate (
if (indexable == XP_STX_SPEC_BYTE_INDEXABLE) { if (indexable == XP_STX_SPEC_BYTE_INDEXABLE) {
xp_assert (nfields == 0); xp_assert (nfields == 0);
new = xp_stx_alloc_byte_object ( new = xp_stx_alloc_byte_object (
stx, XP_NULL, nfields + size); stx, data, nfields + size);
} }
else if (indexable == XP_STX_SPEC_CHAR_INDEXABLE) { else if (indexable == XP_STX_SPEC_CHAR_INDEXABLE) {
xp_assert (nfields == 0); xp_assert (nfields == 0);
new = xp_stx_alloc_char_objectx ( new = xp_stx_alloc_char_objectx (
stx, XP_NULL, nfields + size); stx, data, nfields + size);
} }
else if (indexable == XP_STX_SPEC_WORD_INDEXABLE) { else if (indexable == XP_STX_SPEC_WORD_INDEXABLE) {
new = xp_stx_alloc_word_object (stx, nfields + size); new = xp_stx_alloc_word_object (
stx, data, nfields + size);
} }
else { else {
xp_assert (indexable == XP_STX_SPEC_NOT_INDEXABLE); xp_assert (indexable == XP_STX_SPEC_NOT_INDEXABLE);
xp_assert (size == 0); xp_assert (size == 0);
new = xp_stx_alloc_word_object (stx, nfields + size); new = xp_stx_alloc_word_object (
stx, data, nfields + size);
} }
XP_STX_CLASS(stx, new) = class_index; XP_STX_CLASS(stx, new) = class_index;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: object.h,v 1.20 2005-07-05 04:29:31 bacon Exp $ * $Id: object.h,v 1.21 2005-07-05 06:26:33 bacon Exp $
*/ */
#ifndef _XP_STX_OBJECT_H_ #ifndef _XP_STX_OBJECT_H_
@ -15,7 +15,8 @@
extern "C" { extern "C" {
#endif #endif
xp_word_t xp_stx_alloc_word_object (xp_stx_t* stx, xp_word_t n); xp_word_t xp_stx_alloc_word_object (
xp_stx_t* stx, const xp_word_t* data, xp_word_t n);
xp_word_t xp_stx_alloc_byte_object ( xp_word_t xp_stx_alloc_byte_object (
xp_stx_t* stx, const xp_byte_t* data, xp_word_t n); xp_stx_t* stx, const xp_byte_t* data, xp_word_t n);
@ -29,7 +30,7 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...);
xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx); xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx);
xp_word_t xp_stx_instantiate ( xp_word_t xp_stx_instantiate (
xp_stx_t* stx, xp_word_t class_index, xp_word_t size); xp_stx_t* stx, xp_word_t class_index, const void* data, xp_word_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,10 +1,11 @@
/* /*
* $Id: parser.c,v 1.50 2005-07-04 11:47:25 bacon Exp $ * $Id: parser.c,v 1.51 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/parser.h> #include <xp/stx/parser.h>
#include <xp/stx/misc.h> #include <xp/stx/object.h>
#include <xp/stx/class.h> #include <xp/stx/class.h>
#include <xp/stx/misc.h>
static int __parse_method ( static int __parse_method (
xp_stx_parser_t* parser, xp_stx_parser_t* parser,
@ -282,35 +283,35 @@ static int __parse_method (
return 0; return 0;
} }
static int __finish_method (xp_stx_parser_t* parser) static int __finish_method (xp_stx_parser_t* parser)
{ {
xp_stx_t* stx = parser->stx;
xp_stx_class_t* class_obj; xp_stx_class_t* class_obj;
xp_word_t bytecodes; xp_word_t bytecodes;
class_obj = (xp_stx_class_t*) class_obj = (xp_stx_class_t*)
XP_STX_WORD_OBJECT(parser->stx, parser->method_class); XP_STX_WORD_OBJECT(stx, parser->method_class);
if (class_obj->methods == parser->stx->nil) { if (class_obj->methods == stx->nil) {
/* TODO: reconfigure method dictionary size */ /* TODO: reconfigure method dictionary size */
class_obj->methods = xp_stx_alloc_word_object (parser->stx, 64); class_obj->methods = xp_stx_instantiate (
XP_STX_CLASS(parser->stx, class_obj->methods) = stx, stx->class_dictionary, XP_NULL, 64);
xp_stx_lookup_class (parser->stx, XP_TEXT("Dictionary"));
} }
xp_assert (class_obj->methods != parser->stx->nil); xp_assert (class_obj->methods != stx->nil);
/* /*
bytecodes = xp_stx_alloc_byte_object (parser->stx, bytecodes = xp_stx_instantiate (
stx, stx->class_bytearray,
parser->bytecodes, parser->bytecode_size); parser->bytecodes, parser->bytecode_size);
*/ */
/* TODO: text saving must be optional */ /* TODO: text saving must be optional */
/* /*
method_obj->text = method_obj->text =
xp_stx_new_string (parser->stx, parser->text); xp_stx_new_string (stx, parser->text);
method_obj->message = method_obj->message =
xp_stx_new_symbol (parser->stx, parser->method_name); xp_stx_new_symbol (stx, parser->method_name);
method_obj->bytecodes = bytecodes; method_obj->bytecodes = bytecodes;
//method_obj->literals = //method_obj->literals =
method_obj->stack_size = XP_STX_TO_SMALLINT(100); method_obj->stack_size = XP_STX_TO_SMALLINT(100);
@ -640,6 +641,7 @@ static int __parse_assignment (
*/ */
xp_word_t i; xp_word_t i;
xp_stx_t* stx = parser->stx;
for (i = 0; i < parser->temporary_count; i++) { for (i = 0; i < parser->temporary_count; i++) {
if (xp_strcmp (target, parser->temporary[i]) == 0) { if (xp_strcmp (target, parser->temporary[i]) == 0) {
@ -652,7 +654,7 @@ xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i);
} }
if (xp_stx_get_instance_variable_index ( if (xp_stx_get_instance_variable_index (
parser->stx, parser->method_class, target, &i) == 0) { stx, parser->method_class, target, &i) == 0) {
xp_char_t buf[100]; xp_char_t buf[100];
if (__parse_expression(parser) == -1) return -1; if (__parse_expression(parser) == -1) return -1;
xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i); xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i);
@ -661,7 +663,7 @@ xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i);
} }
if (xp_stx_lookup_class_variable ( if (xp_stx_lookup_class_variable (
parser->stx, parser->method_class, target) != parser->stx->nil) { stx, parser->method_class, target) != stx->nil) {
if (__parse_expression(parser) == -1) return -1; if (__parse_expression(parser) == -1) return -1;
EMIT_CODE (parser, XP_TEXT("ASSIGN_CLASSVAR #"), target); EMIT_CODE (parser, XP_TEXT("ASSIGN_CLASSVAR #"), target);
return 0; return 0;

View File

@ -1,5 +1,5 @@
/* /*
* $Id: symbol.c,v 1.10 2005-06-08 16:11:18 bacon Exp $ * $Id: symbol.c,v 1.11 2005-07-05 06:26:33 bacon Exp $
*/ */
#include <xp/stx/symbol.h> #include <xp/stx/symbol.h>
@ -9,11 +9,16 @@
xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t sym) xp_word_t xp_stx_new_symlink (xp_stx_t* stx, xp_word_t sym)
{ {
xp_word_t x; xp_word_t x;
xp_word_t data[] = { stx->nil, sym };
x = xp_stx_alloc_word_object (stx, XP_STX_SYMLINK_SIZE); /*
x = xp_stx_alloc_word_object (stx, XP_NULL, XP_STX_SYMLINK_SIZE);
XP_STX_CLASS(stx,x) = stx->class_symlink; XP_STX_CLASS(stx,x) = stx->class_symlink;
XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil; XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_LINK) = stx->nil;
XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_SYMBOL) = sym; XP_STX_WORDAT(stx,x,XP_STX_SYMLINK_SYMBOL) = sym;
*/
x = xp_stx_alloc_word_object (stx, data, XP_STX_SYMLINK_SIZE);
XP_STX_CLASS(stx,x) = stx->class_symlink;
return x; return x;
} }