From d92291a5f667238e8ecf88dada7bccbedcf9bcea Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 12 Jul 2005 16:16:42 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/bootstrp.c | 35 ++++++++++++++++++++- ase/stx/name.c | 7 +---- ase/stx/parser.c | 73 ++++++++++++++++++++++++++++++++++++++------ ase/stx/stx.c | 3 +- ase/stx/stx.h | 3 +- ase/test/stx/test.st | 8 +++-- 6 files changed, 108 insertions(+), 21 deletions(-) diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index 4bc5ed53..a5f1e5eb 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -1,5 +1,5 @@ /* - * $Id: bootstrp.c,v 1.24 2005-07-11 13:41:59 bacon Exp $ + * $Id: bootstrp.c,v 1.25 2005-07-12 16:16:42 bacon Exp $ */ #include @@ -143,6 +143,38 @@ static class_info_t class_info[] = XP_NULL, XP_STX_SPEC_NOT_INDEXABLE }, + { + XP_TEXT("Number"), + XP_TEXT("Magnitude"), + XP_NULL, + XP_NULL, + XP_NULL, + XP_STX_SPEC_NOT_INDEXABLE + }, + { + XP_TEXT("Integer"), + XP_TEXT("Number"), + XP_NULL, + XP_NULL, + XP_NULL, + XP_STX_SPEC_NOT_INDEXABLE + }, + { + XP_TEXT("SmallInteger"), + XP_TEXT("Integer"), + XP_NULL, + XP_NULL, + XP_NULL, + XP_STX_SPEC_NOT_INDEXABLE + }, + { + XP_TEXT("LargeInteger"), + XP_TEXT("Integer"), + XP_NULL, + XP_NULL, + XP_NULL, + XP_STX_SPEC_BYTE_INDEXABLE + }, { XP_TEXT("Collection"), XP_TEXT("Magnitude"), @@ -289,6 +321,7 @@ int xp_stx_bootstrap (xp_stx_t* stx) stx->class_character = xp_stx_new_class (stx, XP_TEXT("Character")); stx->class_dictionary = xp_stx_new_class (stx, XP_TEXT("Dictionary")); stx->class_method = xp_stx_new_class (stx, XP_TEXT("Method")); + stx->class_smallinteger = xp_stx_new_class (stx, XP_TEXT("SmallInteger")); __create_builtin_classes (stx); diff --git a/ase/stx/name.c b/ase/stx/name.c index 0f946cb2..8cecdd6e 100644 --- a/ase/stx/name.c +++ b/ase/stx/name.c @@ -1,5 +1,5 @@ /* - * $Id: name.c,v 1.1 2005-06-12 16:22:03 bacon Exp $ + * $Id: name.c,v 1.2 2005-07-12 16:16:42 bacon Exp $ */ #include @@ -31,11 +31,6 @@ xp_stx_name_t* xp_stx_name_open ( } } - /* - name->ivalue = 0; - name->fvalue = .0; - */ - name->size = 0; name->capacity = capacity; name->buffer[0] = XP_CHAR('\0'); diff --git a/ase/stx/parser.c b/ase/stx/parser.c index a6f79748..85c0813f 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.63 2005-07-11 13:41:59 bacon Exp $ + * $Id: parser.c,v 1.64 2005-07-12 16:16:42 bacon Exp $ */ #include @@ -380,16 +380,67 @@ static INLINE int __emit_do_primitive (xp_stx_parser_t* parser, int no) return 0; } -static INLINE int __add_literal (xp_stx_parser_t* parser, xp_word_t literal) +static int __add_literal (xp_stx_parser_t* parser, xp_word_t literal) { + xp_word_t i; + + for (i = 0; i < parser->literal_count; i++) { + /* + * it would remove redundancy of symbols and small integers. + * more complex redundacy check may be done somewhere else + * like in __add_string_literal. + */ + if (parser->literals[i] == literal) return i; + } + 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; } +static int __add_character_literal (xp_stx_parser_t* parser, xp_char_t ch) +{ + xp_word_t i, c, literal; + xp_stx_t* stx = parser->stx; + + for (i = 0; i < parser->literal_count; i++) { + c = XP_STX_IS_SMALLINT(parser->literals[i])? + stx->class_smallinteger: XP_STX_CLASS (stx, parser->literals[i]); + if (c != stx->class_character) continue; + + if (ch == XP_STX_CHARAT(stx,parser->literals[i],0)) return i; + } + + literal = xp_stx_instantiate ( + stx, stx->class_character, &ch, XP_NULL, 0); + return __add_literal (parser, literal); +} + +static int __add_string_literal ( + xp_stx_parser_t* parser, const xp_char_t* str, xp_word_t size) +{ + xp_word_t i, c, literal; + xp_stx_t* stx = parser->stx; + + for (i = 0; i < parser->literal_count; i++) { + c = XP_STX_IS_SMALLINT(parser->literals[i])? + stx->class_smallinteger: XP_STX_CLASS (stx, parser->literals[i]); + if (c != stx->class_string) continue; + + if (xp_strxncmp (str, size, + XP_STX_DATA(stx,parser->literals[i]), + XP_STX_SIZE(stx,parser->literals[i])) == 0) return i; + } + + literal = xp_stx_instantiate ( + stx, stx->class_string, XP_NULL, str, size); + return __add_literal (parser, literal); +} + int xp_stx_parser_parse_method ( xp_stx_parser_t* parser, xp_word_t method_class, void* input) { @@ -876,25 +927,27 @@ static int __parse_primary (xp_stx_parser_t* parser, const xp_char_t* ident) GET_TOKEN (parser); } else if (parser->token.type == XP_STX_TOKEN_CHARLIT) { - literal = xp_stx_instantiate ( - stx, stx->class_character, - parser->token.name.buffer, XP_NULL, 0); - pos = __add_literal(parser, literal); + pos = __add_character_literal( + parser, parser->token.name.buffer[0]); if (pos == -1) return -1; EMIT_PUSH_LITERAL_CONSTANT (parser, pos); GET_TOKEN (parser); } else if (parser->token.type == XP_STX_TOKEN_STRLIT) { - literal = xp_stx_instantiate ( - stx, stx->class_string, XP_NULL, + pos = __add_string_literal (parser, 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); } else if (parser->token.type == XP_STX_TOKEN_NUMLIT) { - EMIT_CODE_TEST (parser, XP_TEXT("PushLiteral(NUM)"), parser->token.name.buffer); + /* TODO: other types of numbers, negative numbers, etc */ + xp_word_t tmp; + XP_STRTOI (tmp, parser->token.name.buffer, XP_NULL, 10); + literal = XP_STX_TO_SMALLINT(tmp); + pos = __add_literal(parser, literal); + if (pos == -1) return -1; + EMIT_PUSH_LITERAL_CONSTANT (parser, pos); GET_TOKEN (parser); } else if (parser->token.type == XP_STX_TOKEN_SYMLIT) { diff --git a/ase/stx/stx.c b/ase/stx/stx.c index c8039d44..9916dbe8 100644 --- a/ase/stx/stx.c +++ b/ase/stx/stx.c @@ -1,5 +1,5 @@ /* - * $Id: stx.c,v 1.32 2005-07-05 09:02:13 bacon Exp $ + * $Id: stx.c,v 1.33 2005-07-12 16:16:42 bacon Exp $ */ #include @@ -39,6 +39,7 @@ xp_stx_t* xp_stx_open (xp_stx_t* stx, xp_word_t capacity) stx->class_string = XP_STX_NIL; stx->class_dictionary = XP_STX_NIL; stx->class_method = XP_STX_NIL; + stx->class_smallinteger = XP_STX_NIL; stx->__wantabort = xp_false; return stx; diff --git a/ase/stx/stx.h b/ase/stx/stx.h index 4489ce16..f7f96316 100644 --- a/ase/stx/stx.h +++ b/ase/stx/stx.h @@ -1,5 +1,5 @@ /* - * $Id: stx.h,v 1.35 2005-07-11 13:41:59 bacon Exp $ + * $Id: stx.h,v 1.36 2005-07-12 16:16:42 bacon Exp $ */ #ifndef _XP_STX_STX_H_ @@ -81,6 +81,7 @@ struct xp_stx_t xp_word_t class_character; xp_word_t class_dictionary; xp_word_t class_method; + xp_word_t class_smallinteger; xp_bool_t __malloced; xp_bool_t __wantabort; /* TODO: make it a function pointer */ diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 6859f81d..f2dcec0d 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -8,10 +8,14 @@ perform: method with: x with: y with: z with: a1 with: b2 with: c2 a := 'this is ''good'. a := #xxx niceMethod. " - b := -30 xxx nil this. + b := 12345 xxx nil this. b := 30 + 20. - b := 'zzzzzz' xxx: 'cccccc' xy zzzz: 30 ccc:10. + b := 'zzzzzz' xxx: 'cccccc' xy zzzz: 30 ccc:10 ccc: 'cccccc'. $3 asString. + $4 asString. + $4 asString. + $5 asString. + $5 asString. selector := 20. "