From dc02325fd82602bc9f9e6d1b85b5b03425d6d43f Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 14 Aug 2008 08:57:07 +0000 Subject: * include/ruby/encoding.h (rb_enc_ispunct): added. * common.mk (COMMONOBJS), inits.c (rb_call_inits): id.c is now included from parse.c. * id.c (Init_id), id.h (ruby_method_ids): added IDs used by VM. * parse.y (global_symbols): added rooms for VM IDs. * parse.y (rb_intern3, rb_id2str): single puctuation symbol is now same as char code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++ common.mk | 1 - id.c | 71 ++++++++++++++++-------------------- id.h | 72 ++++++++++++++++++++++--------------- include/ruby/encoding.h | 1 + inits.c | 2 -- parse.y | 95 ++++++++++++++++++++++++++++++------------------- 7 files changed, 148 insertions(+), 108 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8dc23520be..75599f9ec5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Thu Aug 14 17:57:05 2008 Nobuyoshi Nakada + + * include/ruby/encoding.h (rb_enc_ispunct): added. + + * common.mk (COMMONOBJS), inits.c (rb_call_inits): id.c is now + included from parse.c. + + * id.c (Init_id), id.h (ruby_method_ids): added IDs used by VM. + + * parse.y (global_symbols): added rooms for VM IDs. + + * parse.y (rb_intern3, rb_id2str): single puctuation symbol is now + same as char code. + Thu Aug 14 17:46:21 2008 Nobuyoshi Nakada * parse.y (union tmpyystype): no longer needed, since YYSTYPE is diff --git a/common.mk b/common.mk index 40716461a9..390b443fee 100644 --- a/common.mk +++ b/common.mk @@ -79,7 +79,6 @@ COMMONOBJS = array.$(OBJEXT) \ vm_dump.$(OBJEXT) \ thread.$(OBJEXT) \ cont.$(OBJEXT) \ - id.$(OBJEXT) \ $(BUILTIN_ENCOBJS) \ $(MISSING) diff --git a/id.c b/id.c index 5166309402..c34f0c8dd9 100644 --- a/id.c +++ b/id.c @@ -11,49 +11,40 @@ #include "ruby/ruby.h" -#define YYSTYPE_IS_DECLARED -#define extern #include "id.h" -#undef extern -void +static void Init_id(void) { #undef rb_intern - - /* Symbols */ - symIFUNC = ID2SYM(rb_intern("")); - symCFUNC = ID2SYM(rb_intern("")); - - /* IDs */ - idEach = rb_intern("each"); - idTimes = rb_intern("times"); - idLength = rb_intern("length"); - idLambda = rb_intern("lambda"); - idIntern = rb_intern("intern"); - idGets = rb_intern("gets"); - idSucc = rb_intern("succ"); - idEnd = rb_intern("end"); - idRangeEachLT = rb_intern("Range#each#LT"); - idRangeEachLE = rb_intern("Range#each#LE"); - idArrayEach = rb_intern("Array#each"); - idMethodMissing = rb_intern("method_missing"); - - idThrowState = rb_intern("#__ThrowState__"); - - idBitblt = rb_intern("bitblt"); - idAnswer = rb_intern("the_answer_to_life_the_universe_and_everything"); - - idSend = rb_intern("send"); - id__send__ = rb_intern("__send__"); - - idRespond_to = rb_intern("respond_to?"); - idInitialize = rb_intern("initialize"); - - id_core_set_method_alias = rb_intern("core_set_method_alias"); - id_core_set_variable_alias = rb_intern("core_set_variable_alias"); - id_core_undef_method = rb_intern("core_undef_method"); - id_core_define_method = rb_intern("core_define_method"); - id_core_define_singleton_method = rb_intern("core_define_singleton_method"); - id_core_set_postexe = rb_intern("core_set_postexe"); +#define rb_intern(str) rb_intern2(str, strlen(str)) + rb_encoding *enc = rb_usascii_encoding(); + + REGISTER_SYMID(idNULL, ""); + REGISTER_SYMID(idIFUNC, ""), + REGISTER_SYMID(idCFUNC, ""), + REGISTER_SYMID(idRespond_to, "respond_to?"), + REGISTER_SYMID(idThrowState, "#__ThrowState__"), + + REGISTER_SYMID(id_core_set_method_alias, "core#set_method_alias"), + REGISTER_SYMID(id_core_set_variable_alias, "core#set_variable_alias"), + REGISTER_SYMID(id_core_undef_method, "core#undef_method"), + REGISTER_SYMID(id_core_define_method, "core#define_method"), + REGISTER_SYMID(id_core_define_singleton_method, "core#define_singleton_method"), + REGISTER_SYMID(id_core_set_postexe, "core#set_postexe"), + + REGISTER_SYMID(idEach, "each"); + REGISTER_SYMID(idLength, "length"); + REGISTER_SYMID(idLambda, "lambda"); + REGISTER_SYMID(idIntern, "intern"); + REGISTER_SYMID(idGets, "gets"); + REGISTER_SYMID(idSucc, "succ"); + REGISTER_SYMID(idMethodMissing, "method_missing"); +#if SUPPORT_JOKE + REGISTER_SYMID(idBitblt, "bitblt"); + REGISTER_SYMID(idAnswer, "the_answer_to_life_the_universe_and_everything"); +#endif + REGISTER_SYMID(idSend, "send"); + REGISTER_SYMID(id__send__, "__send__"); + REGISTER_SYMID(idInitialize, "initialize"); } diff --git a/id.h b/id.h index ece5ae0d00..04cf72e976 100644 --- a/id.h +++ b/id.h @@ -12,10 +12,21 @@ #ifndef RUBY_ID_H #define RUBY_ID_H +#define ID_SCOPE_SHIFT 3 +#define ID_SCOPE_MASK 0x07 +#define ID_LOCAL 0x00 +#define ID_INSTANCE 0x01 +#define ID_GLOBAL 0x03 +#define ID_ATTRSET 0x04 +#define ID_CONST 0x05 +#define ID_CLASS 0x06 +#define ID_JUNK 0x07 +#define ID_INTERNAL ID_JUNK + #include "parse.h" -extern VALUE symIFUNC; -extern VALUE symCFUNC; +#define symIFUNC ID2SYM(idIFUNC) +#define symCFUNC ID2SYM(idCFUNC) enum ruby_method_ids { idPLUS = '+', @@ -36,34 +47,37 @@ enum ruby_method_ids { idEqTilde = tMATCH, idAREF = tAREF, idASET = tASET, - idDummy + idLAST_TOKEN = tLAST_TOKEN >> ID_SCOPE_SHIFT, + tIntern, + tMethodMissing, + tLength, + tGets, + tSucc, + tEach, + tLambda, + tSend, + t__send__, + tInitialize, +#if SUPPORT_JOKE + tBitblt, + tAnswer, +#endif + tLAST_ID }; -extern ID idThrowState; -extern ID idIntern; -extern ID idMethodMissing; -extern ID idLength; -extern ID idGets; -extern ID idSucc; -extern ID idEach; -extern ID idLambda; -extern ID idRangeEachLT; -extern ID idRangeEachLE; -extern ID idArrayEach; -extern ID idTimes; -extern ID idEnd; -extern ID idBitblt; -extern ID idAnswer; -extern ID idSend; -extern ID id__send__; -extern ID idRespond_to; -extern ID idInitialize; - -extern ID id_core_set_method_alias; -extern ID id_core_set_variable_alias; -extern ID id_core_undef_method; -extern ID id_core_define_method; -extern ID id_core_define_singleton_method; -extern ID id_core_set_postexe; +#define idIntern ((tIntern<tLAST_TOKEN) #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL) @@ -495,6 +490,10 @@ static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,V static VALUE ripper_intern(const char*); static VALUE ripper_id2sym(ID); +#ifdef __GNUC__ +#define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \ + ID2SYM(id) : ripper_id2sym(id)) +#endif #define arg_new() dispatch0(args_new) #define arg_add(l,a) dispatch2(args_add, l, a) @@ -732,6 +731,18 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...); %right tPOW %right '!' '~' tUPLUS +%nonassoc idNULL +%nonassoc idRespond_to +%nonassoc idIFUNC +%nonassoc idCFUNC +%nonassoc idThrowState +%nonassoc id_core_set_method_alias +%nonassoc id_core_set_variable_alias +%nonassoc id_core_undef_method +%nonassoc id_core_define_method +%nonassoc id_core_define_singleton_method +%nonassoc id_core_set_postexe + %token tLAST_TOKEN %% @@ -8796,41 +8807,28 @@ static const struct { } op_tbl[] = { {tDOT2, ".."}, {tDOT3, "..."}, - {'+', "+"}, - {'-', "-"}, {'+', "+(binary)"}, {'-', "-(binary)"}, - {'*', "*"}, - {'/', "/"}, - {'%', "%"}, {tPOW, "**"}, {tUPLUS, "+@"}, {tUMINUS, "-@"}, - {'|', "|"}, - {'^', "^"}, - {'&', "&"}, - {'!', "!"}, {tCMP, "<=>"}, - {'>', ">"}, {tGEQ, ">="}, - {'<', "<"}, {tLEQ, "<="}, {tEQ, "=="}, {tEQQ, "==="}, {tNEQ, "!="}, {tMATCH, "=~"}, {tNMATCH, "!~"}, - {'~', "~"}, - {'!', "!"}, {tAREF, "[]"}, {tASET, "[]="}, {tLSHFT, "<<"}, {tRSHFT, ">>"}, {tCOLON2, "::"}, - {'`', "`"}, - {0, 0} }; +#define op_tbl_count (sizeof(op_tbl) / sizeof(op_tbl[0])) + static struct symbols { ID last_id; st_table *sym_id; @@ -8838,7 +8836,7 @@ static struct symbols { st_table *ivar2_id; st_table *id_ivar2; VALUE op_sym[tLAST_TOKEN]; -} global_symbols = {tLAST_TOKEN >> ID_SCOPE_SHIFT}; +} global_symbols = {tLAST_ID}; static const struct st_hash_type symhash = { rb_str_hash_cmp, @@ -8877,7 +8875,8 @@ Init_sym(void) global_symbols.id_str = st_init_numtable_with_size(1000); global_symbols.ivar2_id = st_init_table_with_size(&ivar2_hash_type, 1000); global_symbols.id_ivar2 = st_init_numtable_with_size(1000); - rb_intern2("", 0); + + Init_id(); } void @@ -9022,11 +9021,22 @@ rb_enc_symname2_p(const char *name, int len, rb_encoding *enc) return *m ? Qfalse : Qtrue; } +static ID +register_symid(ID id, const char *name, long len, rb_encoding *enc) +{ + VALUE str = rb_enc_str_new(name, len, enc); + OBJ_FREEZE(str); + st_add_direct(global_symbols.sym_id, (st_data_t)str, id); + st_add_direct(global_symbols.id_str, id, (st_data_t)str); + return id; +} + ID rb_intern3(const char *name, long len, rb_encoding *enc) { const char *m = name; const char *e = m + len; + unsigned char c; VALUE str; ID id; int last; @@ -9068,12 +9078,16 @@ rb_intern3(const char *name, long len, rb_encoding *enc) m++; break; default: - if (m[0] != '_' && rb_enc_isascii((unsigned char)m[0], enc) - && !rb_enc_isalnum(m[0], enc)) { + c = m[0]; + if (c != '_' && rb_enc_isascii(c, enc) && rb_enc_ispunct(c, enc)) { /* operators */ int i; - for (i=0; op_tbl[i].token; i++) { + if (len == 1) { + id = c; + goto id_register; + } + for (i = 0; i < op_tbl_count; i++) { if (*op_tbl[i].name == *m && strcmp(op_tbl[i].name, m) == 0) { id = op_tbl[i].token; @@ -9129,11 +9143,7 @@ rb_intern3(const char *name, long len, rb_encoding *enc) new_id: id |= ++global_symbols.last_id << ID_SCOPE_SHIFT; id_register: - str = rb_enc_str_new(name, len, enc); - OBJ_FREEZE(str); - st_add_direct(global_symbols.sym_id, (st_data_t)str, id); - st_add_direct(global_symbols.id_str, id, (st_data_t)str); - return id; + return register_symid(id, name, len, enc); } ID @@ -9174,7 +9184,19 @@ rb_id2str(ID id) if (id < tLAST_TOKEN) { int i = 0; - for (i=0; op_tbl[i].token; i++) { + if (rb_ispunct(id)) { + VALUE str = global_symbols.op_sym[i = (int)id]; + if (!str) { + char name[2]; + name[0] = (char)id; + name[1] = 0; + str = rb_usascii_str_new(name, 1); + OBJ_FREEZE(str); + global_symbols.op_sym[i] = str; + } + return str; + } + for (i = 0; i < op_tbl_count; i++) { if (op_tbl[i].token == id) { VALUE str = global_symbols.op_sym[i]; if (!str) { @@ -9694,6 +9716,7 @@ keyword_id_to_str(ID id) return NULL; } +#undef ripper_id2sym static VALUE ripper_id2sym(ID id) { -- cgit v1.2.3