*** empty log message ***

This commit is contained in:
hyung-hwan 2005-07-11 13:41:59 +00:00
parent c21e7cb82b
commit bed09f1147
7 changed files with 105 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bootstrp.c,v 1.23 2005-07-07 07:45:05 bacon Exp $ * $Id: bootstrp.c,v 1.24 2005-07-11 13:41:59 bacon Exp $
*/ */
#include <xp/stx/bootstrp.h> #include <xp/stx/bootstrp.h>
@ -135,6 +135,14 @@ static class_info_t class_info[] =
XP_NULL, XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE XP_STX_SPEC_NOT_INDEXABLE
}, },
{
XP_TEXT("Character"),
XP_TEXT("Magnitude"),
XP_TEXT("value"),
XP_NULL,
XP_NULL,
XP_STX_SPEC_NOT_INDEXABLE
},
{ {
XP_TEXT("Collection"), XP_TEXT("Collection"),
XP_TEXT("Magnitude"), XP_TEXT("Magnitude"),
@ -242,7 +250,7 @@ static class_info_t class_info[] =
} }
}; };
xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size) xp_word_t INLINE __new_array (xp_stx_t* stx, xp_word_t size)
{ {
xp_word_t x; xp_word_t x;
@ -253,7 +261,7 @@ xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size)
return x; return x;
} }
xp_word_t xp_stx_new_string (xp_stx_t* stx, const xp_char_t* str) xp_word_t INLINE __new_string (xp_stx_t* stx, const xp_char_t* str)
{ {
xp_word_t x; xp_word_t x;
@ -278,6 +286,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
stx->class_array = xp_stx_new_class (stx, XP_TEXT("Array")); stx->class_array = xp_stx_new_class (stx, XP_TEXT("Array"));
stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray")); stx->class_bytearray = xp_stx_new_class (stx, XP_TEXT("ByteArray"));
stx->class_string = xp_stx_new_class (stx, XP_TEXT("String")); stx->class_string = xp_stx_new_class (stx, XP_TEXT("String"));
stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character"));
stx->class_dictionary = xp_stx_new_class (stx, XP_TEXT("Dictionary")); stx->class_dictionary = xp_stx_new_class (stx, XP_TEXT("Dictionary"));
stx->class_method = xp_stx_new_class (stx, XP_TEXT("Method")); stx->class_method = xp_stx_new_class (stx, XP_TEXT("Method"));
@ -293,7 +302,7 @@ int xp_stx_bootstrap (xp_stx_t* stx)
/* for some fun here */ /* for some fun here */
{ {
xp_word_t array; xp_word_t array;
array = xp_stx_new_array (stx, 1); array = __new_array (stx, 1);
XP_STX_WORDAT(stx,array,0) = object_meta; XP_STX_WORDAT(stx,array,0) = object_meta;
XP_STX_WORDAT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array; XP_STX_WORDAT(stx,stx->class_class,XP_STX_CLASS_SUBCLASSES) = array;
} }
@ -503,7 +512,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
if (p->instance_variables != XP_NULL) { if (p->instance_variables != XP_NULL) {
nfields += __count_names (p->instance_variables); nfields += __count_names (p->instance_variables);
class_obj->variables = class_obj->variables =
xp_stx_new_string (stx, p->instance_variables); __new_string (stx, p->instance_variables);
} }
xp_assert (nfields <= 0 || (nfields > 0 && xp_assert (nfields <= 0 || (nfields > 0 &&
@ -537,7 +546,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
/* fill subclasses */ /* fill subclasses */
for (p = class_info; p->name != XP_NULL; p++) { for (p = class_info; p->name != XP_NULL; p++) {
n = __count_subclasses (p->name); n = __count_subclasses (p->name);
array = xp_stx_new_array (stx, n); array = __new_array (stx, n);
__set_subclasses (stx, XP_STX_DATA(stx,array), p->name); __set_subclasses (stx, XP_STX_DATA(stx,array), p->name);
class = xp_stx_lookup_class(stx, p->name); class = xp_stx_lookup_class(stx, p->name);
@ -549,7 +558,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
/* fill subclasses for metaclasses */ /* fill subclasses for metaclasses */
for (p = class_info; p->name != XP_NULL; p++) { for (p = class_info; p->name != XP_NULL; p++) {
n = __count_subclasses (p->name); n = __count_subclasses (p->name);
array = xp_stx_new_array (stx, n); array = __new_array (stx, n);
__set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name); __set_metaclass_subclasses (stx, XP_STX_DATA(stx,array), p->name);
class = xp_stx_lookup_class(stx, p->name); class = xp_stx_lookup_class(stx, p->name);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bootstrp.h,v 1.5 2005-06-30 12:07:02 bacon Exp $ * $Id: bootstrp.h,v 1.6 2005-07-11 13:41:59 bacon Exp $
*/ */
#ifndef _XP_STX_BOOTSTRP_H_ #ifndef _XP_STX_BOOTSTRP_H_
@ -12,7 +12,6 @@ extern "C" {
#endif #endif
xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size); xp_word_t xp_stx_new_array (xp_stx_t* stx, xp_word_t size);
xp_word_t xp_stx_new_string (xp_stx_t* stx, const xp_char_t* str);
int xp_stx_bootstrap (xp_stx_t* stx); int xp_stx_bootstrap (xp_stx_t* stx);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,5 +1,5 @@
/* /*
* $Id: bytecode.c,v 1.6 2005-07-10 16:50:50 bacon Exp $ * $Id: bytecode.c,v 1.7 2005-07-11 13:41:59 bacon Exp $
*/ */
#include <xp/stx/bytecode.h> #include <xp/stx/bytecode.h>
#include <xp/stx/class.h> #include <xp/stx/class.h>
@ -17,19 +17,64 @@ int xp_stx_decode (xp_stx_t* stx, xp_word_t class)
class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class); class_obj = (xp_stx_class_t*)XP_STX_OBJECT(stx, class);
if (class_obj->methods == stx->nil) return 0; if (class_obj->methods == stx->nil) return 0;
/* TODO */ /* TODO */
xp_stx_hash_traverse (stx, class_obj->methods, __decode1, class_obj); xp_stx_hash_traverse (stx, class_obj->methods, __decode1, class_obj);
return 0; return 0;
} }
static void __dump_object (xp_stx_t* stx, xp_word_t obj)
{
if (XP_STX_IS_SMALLINT(obj)) {
xp_printf (XP_TEXT("%d"), XP_STX_FROM_SMALLINT(obj));
}
else if (XP_STX_CLASS(stx,obj) == stx->class_character) {
xp_printf (XP_TEXT("$%c"), XP_STX_WORDAT(stx,obj,0));
}
else if (XP_STX_CLASS(stx,obj) == stx->class_string) {
xp_printf (XP_TEXT("'%s'"), XP_STX_DATA(stx,obj));
}
else if (XP_STX_CLASS(stx,obj) == stx->class_symbol) {
xp_printf (XP_TEXT("#%s"), XP_STX_DATA(stx,obj));
}
else if (XP_STX_IS_CHAR_OBJECT(stx, obj)) {
xp_printf (XP_TEXT("unknow char object [%s]"), XP_STX_DATA(stx,obj));
}
else if (XP_STX_IS_BYTE_OBJECT(stx, obj)) {
xp_printf (XP_TEXT("unknown byte object"), XP_STX_DATA(stx,obj));
}
else if (XP_STX_IS_WORD_OBJECT(stx, obj)) {
xp_printf (XP_TEXT("unknown word object"), XP_STX_DATA(stx,obj));
}
else {
xp_printf (XP_TEXT("invalid object type"));
}
}
static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data) static void __decode1 (xp_stx_t* stx, xp_word_t idx, void* data)
{ {
xp_stx_method_t* method_obj; xp_stx_method_t* method_obj;
xp_stx_class_t* class_obj;
xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY); xp_word_t key = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_KEY);
xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE); xp_word_t value = XP_STX_WORDAT(stx,idx,XP_STX_PAIRLINK_VALUE);
xp_word_t* literals;
xp_word_t literal_count, i;
class_obj = (xp_stx_class_t*)data;
xp_printf (XP_TEXT("Method: %s\n"), XP_STX_DATA(stx, key)); xp_printf (XP_TEXT("Method: %s\n"), XP_STX_DATA(stx, key));
method_obj = (xp_stx_method_t*)XP_STX_OBJECT(stx, value); method_obj = (xp_stx_method_t*)XP_STX_OBJECT(stx, value);
literals = method_obj->literals;
literal_count = XP_STX_SIZE(stx, value) -
(XP_STX_FROM_SMALLINT(class_obj->spec) >> XP_STX_SPEC_INDEXABLE_BITS);
xp_printf (XP_TEXT("literal count %d\n"), literal_count);
for (i = 0; i < literal_count; i++) {
xp_printf (XP_TEXT("%d. ["), i);
__dump_object (stx, literals[i]);
xp_printf (XP_TEXT("]\n"));
}
__decode2 (stx, data, method_obj); __decode2 (stx, data, method_obj);
} }
@ -54,6 +99,7 @@ static int __decode2 (xp_stx_t* stx,
XP_TEXT("send_to_super") XP_TEXT("send_to_super")
}; };
bytecodes = XP_STX_BYTE_OBJECT(stx, method_obj->bytecodes); bytecodes = XP_STX_BYTE_OBJECT(stx, method_obj->bytecodes);
bytecode_size = XP_STX_SIZE(stx, method_obj->bytecodes); bytecode_size = XP_STX_SIZE(stx, method_obj->bytecodes);

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.c,v 1.62 2005-07-10 16:50:50 bacon Exp $ * $Id: parser.c,v 1.63 2005-07-11 13:41:59 bacon Exp $
*/ */
#include <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -164,7 +164,8 @@ const xp_char_t* xp_stx_parser_error_string (xp_stx_parser_t* parser)
XP_TEXT("block argument list not closed"), XP_TEXT("block argument list not closed"),
XP_TEXT("block not closed"), XP_TEXT("block not closed"),
XP_TEXT("undeclared name") XP_TEXT("undeclared name"),
XP_TEXT("too many literals")
}; };
if (parser->error_code >= 0 && if (parser->error_code >= 0 &&
@ -346,6 +347,8 @@ static INLINE int __emit_send_to_self (
EMIT_CODE (parser, nargs); EMIT_CODE (parser, nargs);
EMIT_CODE (parser, selector); EMIT_CODE (parser, selector);
} }
return 0;
} }
static INLINE int __emit_send_to_super ( static INLINE int __emit_send_to_super (
@ -363,6 +366,8 @@ static INLINE int __emit_send_to_super (
EMIT_CODE (parser, nargs); EMIT_CODE (parser, nargs);
EMIT_CODE (parser, selector); EMIT_CODE (parser, selector);
} }
return 0;
} }
static INLINE int __emit_do_primitive (xp_stx_parser_t* parser, int no) static INLINE int __emit_do_primitive (xp_stx_parser_t* parser, int no)
@ -375,6 +380,16 @@ static INLINE int __emit_do_primitive (xp_stx_parser_t* parser, int no)
return 0; return 0;
} }
static INLINE int __add_literal (xp_stx_parser_t* parser, xp_word_t literal)
{
if (parser->literal_count >= xp_countof(parser->literals)) {
parser->error_code = XP_STX_PARSER_ERROR_TOO_MANY_LITERALS;
return -1;
}
parser->literals[parser->literal_count++] = literal;
return parser->literal_count - 1;
}
int xp_stx_parser_parse_method ( int xp_stx_parser_parse_method (
xp_stx_parser_t* parser, xp_word_t method_class, void* input) xp_stx_parser_t* parser, xp_word_t method_class, void* input)
{ {
@ -850,17 +865,32 @@ static int __parse_primary (xp_stx_parser_t* parser, const xp_char_t* ident)
* <block constructor> | ( '('<expression>')' ) * <block constructor> | ( '('<expression>')' )
*/ */
xp_stx_t* stx = parser->stx;
if (ident == XP_NULL) { if (ident == XP_NULL) {
int pos;
xp_word_t literal;
if (parser->token.type == XP_STX_TOKEN_IDENT) { if (parser->token.type == XP_STX_TOKEN_IDENT) {
if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1; if (__parse_primary_ident(parser, parser->token.name.buffer) == -1) return -1;
GET_TOKEN (parser); GET_TOKEN (parser);
} }
else if (parser->token.type == XP_STX_TOKEN_CHARLIT) { else if (parser->token.type == XP_STX_TOKEN_CHARLIT) {
EMIT_CODE_TEST (parser, XP_TEXT("PushLiteral(CHAR)"), parser->token.name.buffer); literal = xp_stx_instantiate (
stx, stx->class_character,
parser->token.name.buffer, XP_NULL, 0);
pos = __add_literal(parser, literal);
if (pos == -1) return -1;
EMIT_PUSH_LITERAL_CONSTANT (parser, pos);
GET_TOKEN (parser); GET_TOKEN (parser);
} }
else if (parser->token.type == XP_STX_TOKEN_STRLIT) { else if (parser->token.type == XP_STX_TOKEN_STRLIT) {
EMIT_CODE_TEST (parser, XP_TEXT("PushLiteral(STR)"), parser->token.name.buffer); literal = xp_stx_instantiate (
stx, stx->class_string, XP_NULL,
parser->token.name.buffer, parser->token.name.size);
pos = __add_literal(parser, literal);
if (pos == -1) return -1;
EMIT_PUSH_LITERAL_CONSTANT (parser, pos);
GET_TOKEN (parser); GET_TOKEN (parser);
} }
else if (parser->token.type == XP_STX_TOKEN_NUMLIT) { else if (parser->token.type == XP_STX_TOKEN_NUMLIT) {

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parser.h,v 1.31 2005-07-07 16:32:37 bacon Exp $ * $Id: parser.h,v 1.32 2005-07-11 13:41:59 bacon Exp $
*/ */
#ifndef _XP_STX_PARSER_H_ #ifndef _XP_STX_PARSER_H_
@ -46,7 +46,8 @@ enum
XP_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST, XP_STX_PARSER_ERROR_BLOCK_ARGUMENT_LIST,
XP_STX_PARSER_ERROR_BLOCK_NOT_CLOSED, XP_STX_PARSER_ERROR_BLOCK_NOT_CLOSED,
XP_STX_PARSER_ERROR_UNDECLARED_NAME XP_STX_PARSER_ERROR_UNDECLARED_NAME,
XP_STX_PARSER_ERROR_TOO_MANY_LITERALS
}; };
enum enum

View File

@ -1,5 +1,5 @@
/* /*
* $Id: stx.h,v 1.34 2005-07-05 10:22:35 bacon Exp $ * $Id: stx.h,v 1.35 2005-07-11 13:41:59 bacon Exp $
*/ */
#ifndef _XP_STX_STX_H_ #ifndef _XP_STX_STX_H_
@ -78,6 +78,7 @@ struct xp_stx_t
xp_word_t class_array; xp_word_t class_array;
xp_word_t class_bytearray; xp_word_t class_bytearray;
xp_word_t class_string; xp_word_t class_string;
xp_word_t class_character;
xp_word_t class_dictionary; xp_word_t class_dictionary;
xp_word_t class_method; xp_word_t class_method;

View File

@ -10,7 +10,8 @@ perform: method with: x with: y with: z with: a1 with: b2 with: c2
" "
b := -30 xxx nil this. b := -30 xxx nil this.
b := 30 + 20. b := 30 + 20.
b := 30 xxx: 10 xy zzzz: 30 ccc:10. b := 'zzzzzz' xxx: 'cccccc' xy zzzz: 30 ccc:10.
$3 asString.
selector := 20. selector := 20.
" "