diff --git a/ase/stx/bootstrp.c b/ase/stx/bootstrp.c index 2ff8d095..5e1dd590 100644 --- a/ase/stx/bootstrp.c +++ b/ase/stx/bootstrp.c @@ -1,5 +1,5 @@ /* - * $Id: bootstrp.c,v 1.21 2005-07-05 09:02:13 bacon Exp $ + * $Id: bootstrp.c,v 1.22 2005-07-05 11:15:51 bacon Exp $ */ #include @@ -307,7 +307,7 @@ int xp_stx_bootstrap (xp_stx_t* stx) symbol_Smalltalk = xp_stx_new_symbol (stx, XP_TEXT("Smalltalk")); xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, symbol_Smalltalk), + xp_stx_hash_object(stx, symbol_Smalltalk), symbol_Smalltalk, stx->smalltalk); /* create #nil, #true, #false */ @@ -441,16 +441,16 @@ static void __create_bootstrapping_objects (xp_stx_t* stx) /* register class names into the system dictionary */ xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, symbol_Symlink), + xp_stx_hash_object(stx, symbol_Symlink), symbol_Symlink, stx->class_symlink); xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, symbol_Symbol), + xp_stx_hash_object(stx, symbol_Symbol), symbol_Symbol, stx->class_symbol); xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, symbol_Metaclass), + xp_stx_hash_object(stx, symbol_Metaclass), symbol_Metaclass, stx->class_metaclass); xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, symbol_Pairlink), + xp_stx_hash_object(stx, symbol_Pairlink), symbol_Pairlink, stx->class_pairlink); } @@ -667,7 +667,7 @@ static xp_word_t __make_classvar_dict ( symbol = xp_stx_new_symbolx (stx, name, p - name); xp_stx_hash_insert (stx, dict, - xp_stx_hash_char_object(stx, symbol), symbol, stx->nil); + xp_stx_hash_object(stx, symbol), symbol, stx->nil); } while (1); return dict; diff --git a/ase/stx/class.c b/ase/stx/class.c index 5382ea06..20b5bdfe 100644 --- a/ase/stx/class.c +++ b/ase/stx/class.c @@ -1,5 +1,5 @@ /* - * $Id: class.c,v 1.19 2005-07-05 09:02:13 bacon Exp $ + * $Id: class.c,v 1.20 2005-07-05 11:15:51 bacon Exp $ */ #include @@ -29,7 +29,7 @@ xp_word_t xp_stx_new_class (xp_stx_t* stx, const xp_char_t* name) XP_STX_WORDAT(stx,class,XP_STX_CLASS_NAME) = class_name; xp_stx_hash_insert (stx, stx->smalltalk, - xp_stx_hash_char_object(stx, class_name), + xp_stx_hash_object(stx, class_name), class_name, class); return class; diff --git a/ase/stx/misc.c b/ase/stx/misc.c index d9c1f9b6..f5fa3dd4 100644 --- a/ase/stx/misc.c +++ b/ase/stx/misc.c @@ -1,9 +1,20 @@ /* - * $Id: misc.c,v 1.6 2005-06-30 15:11:00 bacon Exp $ + * $Id: misc.c,v 1.7 2005-07-05 11:15:51 bacon Exp $ */ #include +xp_word_t xp_stx_hash (const void* data, xp_word_t len) +{ + xp_word_t h = 0; + xp_byte_t* bp, * be; + + bp = (xp_byte_t*)data; be = bp + len; + while (bp < be) h = h * 31 + *bp++; + + return h; +} + xp_word_t xp_stx_strhash (const xp_char_t* str) { xp_word_t h = 0; diff --git a/ase/stx/misc.h b/ase/stx/misc.h index f6cafdc0..7dff3a56 100644 --- a/ase/stx/misc.h +++ b/ase/stx/misc.h @@ -1,5 +1,5 @@ /* - * $Id: misc.h,v 1.10 2005-07-03 16:37:01 bacon Exp $ + * $Id: misc.h,v 1.11 2005-07-05 11:15:51 bacon Exp $ */ #ifndef _XP_STX_MISC_H_ @@ -44,6 +44,7 @@ extern "C" { #endif +xp_word_t xp_stx_hash (const void* data, xp_word_t len); xp_word_t xp_stx_strhash (const xp_char_t* str); xp_word_t xp_stx_strxhash (const xp_char_t* str, xp_word_t len); diff --git a/ase/stx/object.c b/ase/stx/object.c index 1bfec5b2..632bd438 100644 --- a/ase/stx/object.c +++ b/ase/stx/object.c @@ -1,5 +1,5 @@ /* - * $Id: object.c,v 1.34 2005-07-05 10:22:35 bacon Exp $ + * $Id: object.c,v 1.35 2005-07-05 11:15:51 bacon Exp $ */ #include @@ -34,11 +34,7 @@ xp_word_t xp_stx_alloc_word_object ( obj->header.access = (n << 2) | XP_STX_WORD_INDEXED; if (variable_data == XP_NULL) { - while (n > nfields) { - n--; - xp_printf (XP_TEXT("%d\n"), n); - obj->data[n] = stx->nil; - } + while (n > nfields) obj->data[--n] = stx->nil; } else { while (n > nfields) { @@ -161,31 +157,28 @@ xp_word_t xp_stx_allocn_char_object (xp_stx_t* stx, ...) return idx; } -xp_word_t xp_stx_hash_char_object (xp_stx_t* stx, xp_word_t idx) -{ - xp_assert (!XP_STX_IS_SMALLINT(idx) && XP_STX_IS_CHAR_OBJECT(stx, idx)); - return xp_stx_strxhash ( - XP_STX_DATA(stx,idx), XP_STX_SIZE(stx,idx)); -} - xp_word_t xp_stx_hash_object (xp_stx_t* stx, xp_word_t object) { xp_word_t hv; - /* TODO: implement this function */ - if (XP_STX_IS_SMALLINT(object)) { - hv = 0; - } - else if (XP_STX_IS_BYTE_OBJECT(stx,object)) { - hv = 0; + xp_word_t tmp = XP_STX_FROM_SMALLINT(object); + hv = xp_stx_hash(&tmp, xp_sizeof(tmp)); } else if (XP_STX_IS_CHAR_OBJECT(stx,object)) { - hv = xp_stx_strxhash ( + /*hv = xp_stx_strxhash ( + XP_STX_DATA(stx,object), XP_STX_SIZE(stx,object));*/ + hv = xp_stx_hash (XP_STX_DATA(stx,object), + XP_STX_SIZE(stx,object) * xp_sizeof(xp_char_t)); + } + else if (XP_STX_IS_BYTE_OBJECT(stx,object)) { + hv = xp_stx_hash ( XP_STX_DATA(stx,object), XP_STX_SIZE(stx,object)); } - else if (XP_STX_IS_WORD_OBJECT(stx,object)) { - hv = 0; + else { + xp_assert (XP_STX_IS_WORD_OBJECT(stx,object)); + hv = xp_stx_hash (XP_STX_DATA(stx,object), + XP_STX_SIZE(stx,object) * xp_sizeof(xp_word_t)); } return hv; @@ -205,6 +198,7 @@ xp_word_t xp_stx_instantiate ( created in a different way */ /* TODO: maybe delete the following line */ xp_assert (class_obj->header.class != stx->class_metaclass); + xp_assert (XP_STX_IS_SMALLINT(class_obj->spec)); spec = XP_STX_FROM_SMALLINT(class_obj->spec); nfields = (spec >> XP_STX_SPEC_INDEXABLE_BITS); diff --git a/ase/stx/object.h b/ase/stx/object.h index 75dd674c..fa18963b 100644 --- a/ase/stx/object.h +++ b/ase/stx/object.h @@ -1,5 +1,5 @@ /* - * $Id: object.h,v 1.24 2005-07-05 10:22:35 bacon Exp $ + * $Id: object.h,v 1.25 2005-07-05 11:15:51 bacon Exp $ */ #ifndef _XP_STX_OBJECT_H_ @@ -24,7 +24,6 @@ xp_word_t xp_stx_alloc_char_objectx ( xp_stx_t* stx, const xp_char_t* str, xp_word_t n); 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_object (xp_stx_t* stx, xp_word_t object); xp_word_t xp_stx_instantiate ( diff --git a/ase/stx/parser.c b/ase/stx/parser.c index 24aafcda..9e295fc0 100644 --- a/ase/stx/parser.c +++ b/ase/stx/parser.c @@ -1,5 +1,5 @@ /* - * $Id: parser.c,v 1.53 2005-07-05 09:52:00 bacon Exp $ + * $Id: parser.c,v 1.54 2005-07-05 11:15:51 bacon Exp $ */ #include @@ -39,9 +39,6 @@ static int __parse_keyword_message (xp_stx_parser_t* parser); static int __parse_binary_message (xp_stx_parser_t* parser); static int __parse_unary_message (xp_stx_parser_t* parser); -static int __emit_code ( - xp_stx_parser_t* parser, const xp_char_t* high, const xp_char_t* low); - static int __get_token (xp_stx_parser_t* parser); static int __get_ident (xp_stx_parser_t* parser); static int __get_numlit (xp_stx_parser_t* parser, xp_bool_t negated); @@ -238,6 +235,20 @@ static INLINE xp_bool_t __is_closing_char (xp_cint_t c) c == XP_CHAR('\"') || c == XP_CHAR('\''); } +static INLINE int __emit_code ( + xp_stx_parser_t* parser, const xp_char_t* high, const xp_char_t* low) +{ + xp_printf (XP_TEXT("CODE: %s %s\n"), high, low); + return 0; +} + +/* +static INLINE int __emit_code (xp_stx_parser_t* parser, xp_byte_t code) +{ + return (xp_array_add_datum(&parser->bytecode, &code) == XP_NULL)? -1: 0; +} +*/ + int xp_stx_parser_parse_method ( xp_stx_parser_t* parser, xp_word_t method_class, void* input) { @@ -519,6 +530,15 @@ static int __parse_primitive (xp_stx_parser_t* parser) } EMIT_CODE (parser, XP_TEXT("DO_PRIMITIVE"), parser->token.name.buffer); +/* + EMIT_CODE (parser, DO_PRIMITIVE); + EMIT_CODE (parser, parser->token.ivalue); + + EMIT_CODE (parser, DO_PRIMITIVE_EXTENDED); + EMIT_CODE (parser, parser->token.ivalue); + EMIT_CODE (parser, parser->token.ivalue); +*/ + GET_TOKEN (parser); if (!__is_primitive_closer(&parser->token)) { parser->error_code = XP_STX_PARSER_ERROR_PRIMITIVE_NOT_CLOSED; @@ -905,13 +925,6 @@ static int __parse_unary_message (xp_stx_parser_t* parser) return 0; } -static int __emit_code ( - xp_stx_parser_t* parser, const xp_char_t* high, const xp_char_t* low) -{ - xp_printf (XP_TEXT("CODE: %s %s\n"), high, low); - return 0; -} - static int __get_token (xp_stx_parser_t* parser) { xp_cint_t c;