[前][次][番号順一覧][スレッド一覧]

ruby-changes:7096

From: nobu <ko1@a...>
Date: Thu, 14 Aug 2008 17:57:49 +0900 (JST)
Subject: [ruby-changes:7096] Ruby:r18614 (trunk): * include/ruby/encoding.h (rb_enc_ispunct): added.

nobu	2008-08-14 17:57:07 +0900 (Thu, 14 Aug 2008)

  New Revision: 18614

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18614

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/id.c
    trunk/id.h
    trunk/include/ruby/encoding.h
    trunk/inits.c
    trunk/parse.y

Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 18613)
+++ include/ruby/encoding.h	(revision 18614)
@@ -143,6 +143,7 @@
 #define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA(enc,c)
 #define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER(enc,c)
 #define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER(enc,c)
+#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT(enc,c)
 #define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM(enc,c)
 #define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT(enc,c)
 #define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE(enc,c)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18613)
+++ ChangeLog	(revision 18614)
@@ -1,3 +1,17 @@
+Thu Aug 14 17:57:05 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <nobu@r...>
 
 	* parse.y (union tmpyystype): no longer needed, since YYSTYPE is
Index: common.mk
===================================================================
--- common.mk	(revision 18613)
+++ common.mk	(revision 18614)
@@ -79,7 +79,6 @@
 		vm_dump.$(OBJEXT) \
 		thread.$(OBJEXT) \
 		cont.$(OBJEXT) \
-		id.$(OBJEXT) \
 		$(BUILTIN_ENCOBJS) \
 		$(MISSING)
 
Index: id.c
===================================================================
--- id.c	(revision 18613)
+++ id.c	(revision 18614)
@@ -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
+#define rb_intern(str) rb_intern2(str, strlen(str))
+    rb_encoding *enc = rb_usascii_encoding();
 
-    /* Symbols */
-    symIFUNC = ID2SYM(rb_intern("<IFUNC>"));
-    symCFUNC = ID2SYM(rb_intern("<CFUNC>"));
+    REGISTER_SYMID(idNULL, "");
+    REGISTER_SYMID(idIFUNC, "<IFUNC>"),
+    REGISTER_SYMID(idCFUNC, "<CFUNC>"),
+    REGISTER_SYMID(idRespond_to, "respond_to?"),
+    REGISTER_SYMID(idThrowState, "#__ThrowState__"),
 
-    /* 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");
+    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"),
 
-    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");
+    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");
 }
Index: parse.y
===================================================================
--- parse.y	(revision 18613)
+++ parse.y	(revision 18614)
@@ -35,16 +35,11 @@
 #define calloc	YYCALLOC
 #define free	YYFREE
 
-#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
+#ifndef RIPPER
+static ID register_symid(ID, const char *, long, rb_encoding *);
+#define REGISTER_SYMID(id, name) register_symid(id, name, strlen(name), enc)
+#include "id.c"
+#endif
 
 #define is_notop_id(id) ((id)>tLAST_TOKEN)
 #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
@@ -495,6 +490,10 @@
 
 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 @@
 %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 @@
 } 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 @@
     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 @@
     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 @@
     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 @@
 	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 @@
   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 @@
     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 @@
     return NULL;
 }
 
+#undef ripper_id2sym
 static VALUE
 ripper_id2sym(ID id)
 {
Index: id.h
===================================================================
--- id.h	(revision 18613)
+++ id.h	(revision 18614)
@@ -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 @@
     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;
+#define idIntern ((tIntern<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idMethodMissing ((tMethodMissing<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idLength ((tLength<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idGets ((tGets<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idSucc ((tSucc<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idEach ((tEach<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idLambda ((tLambda<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idSend ((tSend<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define id__send__ ((t__send__<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idInitialize ((tInitialize<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#if SUPPORT_JOKE
+#define idBitblt ((tBitblt<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#define idAnswer ((tAnswer<<ID_SCOPE_SHIFT)|ID_LOCAL)
+#endif
 
-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;
-
 #endif /* RUBY_ID_H */
Index: inits.c
===================================================================
--- inits.c	(revision 18613)
+++ inits.c	(revision 18614)
@@ -36,7 +36,6 @@
 void Init_pack(void);
 void Init_Precision(void);
 void Init_sym(void);
-void Init_id(void);
 void Init_process(void);
 void Init_RandomSeed(void);
 void Init_Random(void);
@@ -61,7 +60,6 @@
 {
     Init_RandomSeed();
     Init_sym();
-    Init_id();
     Init_var_tables();
     Init_Object();
     Init_top_self();

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]