From 4564d3905270171aa37f864ee74c20e3ce1a435e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 29 Jun 2005 16:01:32 +0000 Subject: [PATCH] *** empty log message *** --- ase/stx/bootstrp.c | 3 ++- ase/stx/class.c | 45 ++++++++++++++++++++++++++++++++++++++++++- ase/stx/class.h | 7 ++++++- ase/stx/parser.c | 34 +++++++------------------------- ase/stx/parser.h | 6 +++--- ase/test/stx/parser.c | 1 - ase/test/stx/test.st | 2 +- 7 files changed, 63 insertions(+), 35 deletions(-) diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index a7133f3e..cd71efac 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -1,5 +1,5 @@ /* - * $Id: bootstrp.c,v 1.12 2005-06-08 16:11:18 bacon Exp $ + * $Id: bootstrp.c,v 1.13 2005-06-29 16:01:32 bacon Exp $ */ #include @@ -421,6 +421,7 @@ static void __create_builtin_classes (xp_stx_t* stx) __set_names (stx, XP_STX_DATA(stx,array), p->instance_variables); class_obj->variables = array; } + else n = 0; class_obj->spec = XP_STX_TO_SMALLINT(((spec + n) << 1) | p->is_indexable); diff --git a/ase/stx/class.c b/ase/stx/class.c index 1dd4cad0..00e660b9 100644 --- a/ase/stx/class.c +++ b/ase/stx/class.c @@ -1,5 +1,5 @@ /* - * $Id: class.c,v 1.9 2005-06-08 16:00:51 bacon Exp $ + * $Id: class.c,v 1.10 2005-06-29 16:01:32 bacon Exp $ */ #include @@ -48,3 +48,46 @@ xp_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_char_t* name) return value; } +int xp_stx_get_instance_variable_index ( + xp_stx_t* stx, xp_word_t class_index, + const xp_char_t* name, xp_word_t* index) +{ + xp_word_t i, size, index_super = 0; + xp_stx_class_t* class_obj; + xp_stx_word_object_t* array; + const xp_char_t* iname; + + class_obj = (xp_stx_class_t*)XP_STX_WORD_OBJECT(stx, class_index); + xp_assert (class_obj != XP_NULL); + + if (class_obj->superclass != stx->nil) { + if (xp_stx_get_instance_variable_index ( + stx, class_obj->superclass, name, &index_super) == 0) { + *index = index_super; + return 0; + } + } + + if (class_obj->header.class == stx->class_metaclass) { + /* metaclass */ + /* TODO: can a metaclas have instance variables? */ + + *index = index_super; + } + else { + size = XP_STX_SIZE(stx, class_obj->variables); + array = XP_STX_WORD_OBJECT(stx, class_obj->variables); + + for (i = 0; i < size; i++) { + iname = &XP_STX_CHARAT(stx, array->data[i], 0); + if (xp_strcmp(iname, name) == 0) { + *index = i + index_super; + return 0; + } + } + + *index = size + index_super; + } + + return -1; +} diff --git a/ase/stx/class.h b/ase/stx/class.h index 310ef958..21ea0e00 100644 --- a/ase/stx/class.h +++ b/ase/stx/class.h @@ -1,5 +1,5 @@ /* - * $Id: class.h,v 1.6 2005-06-08 16:00:51 bacon Exp $ + * $Id: class.h,v 1.7 2005-06-29 16:01:32 bacon Exp $ */ #ifndef _XP_STX_CLASS_H_ @@ -58,6 +58,11 @@ extern "C" { xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name); xp_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_char_t* name); +int xp_stx_get_instance_variable_index ( + xp_stx_t* stx, xp_word_t class_index, + const xp_char_t* name, xp_word_t* index); + + #ifdef __cplusplus } #endif diff --git a/ase/stx/parser.c b/ase/stx/parser.c index cb6d5821..92023201 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.44 2005-06-29 12:02:39 bacon Exp $ + * $Id: parser.c,v 1.45 2005-06-29 16:01:32 bacon Exp $ */ #include @@ -546,45 +546,25 @@ static int __parse_assignment ( * ::= assignmentOperator */ - xp_size_t i; - xp_stx_class_t* class_obj; + xp_word_t i; for (i = 0; i < parser->temporary_count; i++) { if (xp_strcmp (target, parser->temporary[i]) == 0) { xp_char_t buf[100]; if (__parse_expression(parser) == -1) return -1; - xp_sprintf (buf, xp_countof(buf), XP_TEXT("%d"), i); EMIT_CODE (parser, XP_TEXT("ASSIGN_TEMPORARY"), buf); return 0; } } - class_obj = (xp_stx_class_t*) - XP_STX_WORD_OBJECT(parser->stx, parser->method_class); - xp_assert (class_obj != XP_NULL); - if (class_obj->header.class == parser->stx->class_metaclass) { - /* metaclass */ - /* TODO: can metaclasses have instance variables? */ - } - else { - xp_size_t size; - xp_stx_word_object_t* array; - - size = XP_STX_SIZE(parser->stx, class_obj->variables); - array = XP_STX_WORD_OBJECT(parser->stx, class_obj->variables); - - for (i = 0; i < size; i++) { - const xp_char_t* iname = - &XP_STX_CHARAT(parser->stx, array->data[i], 0); - if (xp_strcmp(target, iname) == 0) { + if (xp_stx_get_instance_variable_index ( + parser->stx, parser->method_class, target, &i) == 0) { 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); - EMIT_CODE (parser, XP_TEXT("ASSIGN_INSTANCE"), buf); - return 0; - } - } + EMIT_CODE (parser, XP_TEXT("ASSIGN_INSTANCE"), buf); + return 0; } /* TODO: check it in class variables */ diff --git a/ase/stx/parser.h b/ase/stx/parser.h index 46e7b529..e58ff118 100644 --- a/ase/stx/parser.h +++ b/ase/stx/parser.h @@ -1,5 +1,5 @@ /* - * $Id: parser.h,v 1.25 2005-06-29 12:02:39 bacon Exp $ + * $Id: parser.h,v 1.26 2005-06-29 16:01:32 bacon Exp $ */ #ifndef _XP_STX_PARSER_H_ @@ -63,9 +63,9 @@ struct xp_stx_parser_t xp_stx_name_t method_name; xp_char_t* argument[32]; - xp_size_t argument_count; + xp_word_t argument_count; xp_char_t* temporary[32]; - xp_size_t temporary_count; + xp_word_t temporary_count; xp_array_t byte_code; diff --git a/ase/test/stx/parser.c b/ase/test/stx/parser.c index 3ff94199..f3c9d40a 100644 --- a/ase/test/stx/parser.c +++ b/ase/test/stx/parser.c @@ -94,7 +94,6 @@ int xp_main (int argc, xp_char_t* argv[]) { xp_stx_t stx; xp_stx_parser_t parser; - xp_word_t i; #ifdef __linux mtrace (); diff --git a/ase/test/stx/test.st b/ase/test/stx/test.st index 3d5ae9c8..a2cf6d60 100644 --- a/ase/test/stx/test.st +++ b/ase/test/stx/test.st @@ -8,7 +8,7 @@ perform: method with: x with: y with: z with: a with: b with: c a := #xxx niceMethod. " b := -30 xxx nil this. - spec := 10. + name := 10. (jjj xxx: 10 xy) zzz: (10 fuck: 20 you: 40) yyy: kkk. [ spec plus: 20]