*** empty log message ***

This commit is contained in:
hyung-hwan 2005-06-29 16:01:32 +00:00
parent f11c7a3046
commit 4564d39052
7 changed files with 63 additions and 35 deletions

View File

@ -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 <xp/stx/bootstrp.h> #include <xp/stx/bootstrp.h>
@ -421,6 +421,7 @@ static void __create_builtin_classes (xp_stx_t* stx)
__set_names (stx, XP_STX_DATA(stx,array), p->instance_variables); __set_names (stx, XP_STX_DATA(stx,array), p->instance_variables);
class_obj->variables = array; class_obj->variables = array;
} }
else n = 0;
class_obj->spec = XP_STX_TO_SMALLINT(((spec + n) << 1) | p->is_indexable); class_obj->spec = XP_STX_TO_SMALLINT(((spec + n) << 1) | p->is_indexable);

View File

@ -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 <xp/stx/class.h> #include <xp/stx/class.h>
@ -48,3 +48,46 @@ xp_word_t xp_stx_lookup_class (xp_stx_t* stx, const xp_char_t* name)
return value; 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;
}

View File

@ -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_ #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_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); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -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 <xp/stx/parser.h> #include <xp/stx/parser.h>
@ -546,46 +546,26 @@ static int __parse_assignment (
* <assignment> ::= <assignment target> assignmentOperator <expression> * <assignment> ::= <assignment target> assignmentOperator <expression>
*/ */
xp_size_t i; xp_word_t i;
xp_stx_class_t* class_obj;
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) {
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);
EMIT_CODE (parser, XP_TEXT("ASSIGN_TEMPORARY"), buf); EMIT_CODE (parser, XP_TEXT("ASSIGN_TEMPORARY"), buf);
return 0; return 0;
} }
} }
class_obj = (xp_stx_class_t*) if (xp_stx_get_instance_variable_index (
XP_STX_WORD_OBJECT(parser->stx, parser->method_class); parser->stx, parser->method_class, target, &i) == 0) {
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) {
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);
EMIT_CODE (parser, XP_TEXT("ASSIGN_INSTANCE"), buf); EMIT_CODE (parser, XP_TEXT("ASSIGN_INSTANCE"), buf);
return 0; return 0;
} }
}
}
/* TODO: check it in class variables */ /* TODO: check it in class variables */

View File

@ -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_ #ifndef _XP_STX_PARSER_H_
@ -63,9 +63,9 @@ struct xp_stx_parser_t
xp_stx_name_t method_name; xp_stx_name_t method_name;
xp_char_t* argument[32]; xp_char_t* argument[32];
xp_size_t argument_count; xp_word_t argument_count;
xp_char_t* temporary[32]; xp_char_t* temporary[32];
xp_size_t temporary_count; xp_word_t temporary_count;
xp_array_t byte_code; xp_array_t byte_code;

View File

@ -94,7 +94,6 @@ int xp_main (int argc, xp_char_t* argv[])
{ {
xp_stx_t stx; xp_stx_t stx;
xp_stx_parser_t parser; xp_stx_parser_t parser;
xp_word_t i;
#ifdef __linux #ifdef __linux
mtrace (); mtrace ();

View File

@ -8,7 +8,7 @@ perform: method with: x with: y with: z with: a with: b with: c
a := #xxx niceMethod. a := #xxx niceMethod.
" "
b := -30 xxx nil this. b := -30 xxx nil this.
spec := 10. name := 10.
(jjj xxx: 10 xy) zzz: (10 fuck: 20 you: 40) yyy: kkk. (jjj xxx: 10 xy) zzz: (10 fuck: 20 you: 40) yyy: kkk.
[ spec plus: 20] [ spec plus: 20]