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

ruby-changes:39252

From: nobu <ko1@a...>
Date: Wed, 22 Jul 2015 09:37:19 +0900 (JST)
Subject: [ruby-changes:39252] nobu:r51333 (trunk): Makefile.in: PIC lex.c

nobu	2015-07-22 09:37:09 +0900 (Wed, 22 Jul 2015)

  New Revision: 51333

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

  Log:
    Makefile.in: PIC lex.c
    
    * Makefile.in (lex.c): make position independent table.

  Modified files:
    trunk/Makefile.in
    trunk/defs/keywords
    trunk/defs/lex.c.src
    trunk/lex.c.blt
Index: defs/lex.c.src
===================================================================
--- defs/lex.c.src	(revision 51332)
+++ defs/lex.c.src	(revision 51333)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/defs/lex.c.src#L1
 %{
-struct kwtable {const char *name; int id[2]; enum lex_state_e state;};
+struct kwtable {unsigned int name, id[2], state;};
 const struct kwtable *rb_reserved_word(const char *, unsigned int);
 #ifndef RIPPER
 static const struct kwtable *reserved_word(const char *, unsigned int);
Index: defs/keywords
===================================================================
--- defs/keywords	(revision 51332)
+++ defs/keywords	(revision 51333)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/defs/keywords#L1
 %{
-struct kwtable {const char *name; int id[2]; enum lex_state_e state;};
+struct kwtable {unsigned int name, id[2], state;};
 const struct kwtable *rb_reserved_word(const char *, unsigned int);
 #ifndef RIPPER
 static const struct kwtable *reserved_word(const char *, unsigned int);
Index: lex.c.blt
===================================================================
--- lex.c.blt	(revision 51332)
+++ lex.c.blt	(revision 51333)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L1
 /* C code produced by gperf version 3.0.4 */
-/* Command-line: gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' defs/keywords  */
+/* Command-line: gperf -C -P -p -j1 -i 1 -g -o -t -N rb_reserved_word -k'1,3,$' defs/keywords  */
 
 #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
       && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -30,7 +30,7 @@ error "gperf generated tables don't work https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L30
 
 #line 1 "defs/keywords"
 
-struct kwtable {const char *name; int id[2]; enum lex_state_e state;};
+struct kwtable {unsigned int name, id[2], state;};
 const struct kwtable *rb_reserved_word(const char *, unsigned int);
 #ifndef RIPPER
 static const struct kwtable *reserved_word(const char *, unsigned int);
@@ -45,12 +45,10 @@ struct kwtable; https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L45
 #define MAX_HASH_VALUE 50
 /* maximum key range = 43, duplicates = 0 */
 
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
+#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) || defined(__GNUC_STDC_INLINE__)
 inline
-#endif
+#elif defined(__GNUC__)
+__inline
 #endif
 static unsigned int
 hash (str, len)
@@ -101,6 +99,95 @@ hash (str, len) https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L99
   return hval + asso_values[(unsigned char)str[len - 1]];
 }
 
+struct stringpool_t
+  {
+    char stringpool_str8[sizeof("break")];
+    char stringpool_str9[sizeof("else")];
+    char stringpool_str10[sizeof("nil")];
+    char stringpool_str11[sizeof("ensure")];
+    char stringpool_str12[sizeof("end")];
+    char stringpool_str13[sizeof("then")];
+    char stringpool_str14[sizeof("not")];
+    char stringpool_str15[sizeof("false")];
+    char stringpool_str16[sizeof("self")];
+    char stringpool_str17[sizeof("elsif")];
+    char stringpool_str18[sizeof("rescue")];
+    char stringpool_str19[sizeof("true")];
+    char stringpool_str20[sizeof("until")];
+    char stringpool_str21[sizeof("unless")];
+    char stringpool_str22[sizeof("return")];
+    char stringpool_str23[sizeof("def")];
+    char stringpool_str24[sizeof("and")];
+    char stringpool_str25[sizeof("do")];
+    char stringpool_str26[sizeof("yield")];
+    char stringpool_str27[sizeof("for")];
+    char stringpool_str28[sizeof("undef")];
+    char stringpool_str29[sizeof("or")];
+    char stringpool_str30[sizeof("in")];
+    char stringpool_str31[sizeof("when")];
+    char stringpool_str32[sizeof("retry")];
+    char stringpool_str33[sizeof("if")];
+    char stringpool_str34[sizeof("case")];
+    char stringpool_str35[sizeof("redo")];
+    char stringpool_str36[sizeof("next")];
+    char stringpool_str37[sizeof("super")];
+    char stringpool_str38[sizeof("module")];
+    char stringpool_str39[sizeof("begin")];
+    char stringpool_str40[sizeof("__LINE__")];
+    char stringpool_str41[sizeof("__FILE__")];
+    char stringpool_str42[sizeof("__ENCODING__")];
+    char stringpool_str43[sizeof("END")];
+    char stringpool_str44[sizeof("alias")];
+    char stringpool_str45[sizeof("BEGIN")];
+    char stringpool_str46[sizeof("defined?")];
+    char stringpool_str47[sizeof("class")];
+    char stringpool_str50[sizeof("while")];
+  };
+static const struct stringpool_t stringpool_contents =
+  {
+    "break",
+    "else",
+    "nil",
+    "ensure",
+    "end",
+    "then",
+    "not",
+    "false",
+    "self",
+    "elsif",
+    "rescue",
+    "true",
+    "until",
+    "unless",
+    "return",
+    "def",
+    "and",
+    "do",
+    "yield",
+    "for",
+    "undef",
+    "or",
+    "in",
+    "when",
+    "retry",
+    "if",
+    "case",
+    "redo",
+    "next",
+    "super",
+    "module",
+    "begin",
+    "__LINE__",
+    "__FILE__",
+    "__ENCODING__",
+    "END",
+    "alias",
+    "BEGIN",
+    "defined?",
+    "class",
+    "while"
+  };
+#define stringpool ((const char *) &stringpool_contents)
 #ifdef __GNUC__
 __inline
 #if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
@@ -114,90 +201,90 @@ rb_reserved_word (str, len) https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L201
 {
   static const struct kwtable wordlist[] =
     {
-      {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
+      {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1}, {-1},
 #line 19 "defs/keywords"
-      {"break", {keyword_break, keyword_break}, EXPR_MID},
+      {offsetof(struct stringpool_t, stringpool_str8), {keyword_break, keyword_break}, EXPR_MID},
 #line 25 "defs/keywords"
-      {"else", {keyword_else, keyword_else}, EXPR_BEG},
+      {offsetof(struct stringpool_t, stringpool_str9), {keyword_else, keyword_else}, EXPR_BEG},
 #line 35 "defs/keywords"
-      {"nil", {keyword_nil, keyword_nil}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str10), {keyword_nil, keyword_nil}, EXPR_END},
 #line 28 "defs/keywords"
-      {"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
+      {offsetof(struct stringpool_t, stringpool_str11), {keyword_ensure, keyword_ensure}, EXPR_BEG},
 #line 27 "defs/keywords"
-      {"end", {keyword_end, keyword_end}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str12), {keyword_end, keyword_end}, EXPR_END},
 #line 44 "defs/keywords"
-      {"then", {keyword_then, keyword_then}, EXPR_BEG},
+      {offsetof(struct stringpool_t, stringpool_str13), {keyword_then, keyword_then}, EXPR_BEG},
 #line 36 "defs/keywords"
-      {"not", {keyword_not, keyword_not}, EXPR_ARG},
+      {offsetof(struct stringpool_t, stringpool_str14), {keyword_not, keyword_not}, EXPR_ARG},
 #line 29 "defs/keywords"
-      {"false", {keyword_false, keyword_false}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str15), {keyword_false, keyword_false}, EXPR_END},
 #line 42 "defs/keywords"
-      {"self", {keyword_self, keyword_self}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str16), {keyword_self, keyword_self}, EXPR_END},
 #line 26 "defs/keywords"
-      {"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str17), {keyword_elsif, keyword_elsif}, EXPR_VALUE},
 #line 39 "defs/keywords"
-      {"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
+      {offsetof(struct stringpool_t, stringpool_str18), {keyword_rescue, modifier_rescue}, EXPR_MID},
 #line 45 "defs/keywords"
-      {"true", {keyword_true, keyword_true}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str19), {keyword_true, keyword_true}, EXPR_END},
 #line 48 "defs/keywords"
-      {"until", {keyword_until, modifier_until}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str20), {keyword_until, modifier_until}, EXPR_VALUE},
 #line 47 "defs/keywords"
-      {"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str21), {keyword_unless, modifier_unless}, EXPR_VALUE},
 #line 41 "defs/keywords"
-      {"return", {keyword_return, keyword_return}, EXPR_MID},
+      {offsetof(struct stringpool_t, stringpool_str22), {keyword_return, keyword_return}, EXPR_MID},
 #line 22 "defs/keywords"
-      {"def", {keyword_def, keyword_def}, EXPR_FNAME},
+      {offsetof(struct stringpool_t, stringpool_str23), {keyword_def, keyword_def}, EXPR_FNAME},
 #line 17 "defs/keywords"
-      {"and", {keyword_and, keyword_and}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str24), {keyword_and, keyword_and}, EXPR_VALUE},
 #line 24 "defs/keywords"
-      {"do", {keyword_do, keyword_do}, EXPR_BEG},
+      {offsetof(struct stringpool_t, stringpool_str25), {keyword_do, keyword_do}, EXPR_BEG},
 #line 51 "defs/keywords"
-      {"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
+      {offsetof(struct stringpool_t, stringpool_str26), {keyword_yield, keyword_yield}, EXPR_ARG},
 #line 30 "defs/keywords"
-      {"for", {keyword_for, keyword_for}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str27), {keyword_for, keyword_for}, EXPR_VALUE},
 #line 46 "defs/keywords"
-      {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
+      {offsetof(struct stringpool_t, stringpool_str28), {keyword_undef, keyword_undef}, EXPR_FNAME},
 #line 37 "defs/keywords"
-      {"or", {keyword_or, keyword_or}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str29), {keyword_or, keyword_or}, EXPR_VALUE},
 #line 32 "defs/keywords"
-      {"in", {keyword_in, keyword_in}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str30), {keyword_in, keyword_in}, EXPR_VALUE},
 #line 49 "defs/keywords"
-      {"when", {keyword_when, keyword_when}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str31), {keyword_when, keyword_when}, EXPR_VALUE},
 #line 40 "defs/keywords"
-      {"retry", {keyword_retry, keyword_retry}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str32), {keyword_retry, keyword_retry}, EXPR_END},
 #line 31 "defs/keywords"
-      {"if", {keyword_if, modifier_if}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str33), {keyword_if, modifier_if}, EXPR_VALUE},
 #line 20 "defs/keywords"
-      {"case", {keyword_case, keyword_case}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str34), {keyword_case, keyword_case}, EXPR_VALUE},
 #line 38 "defs/keywords"
-      {"redo", {keyword_redo, keyword_redo}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str35), {keyword_redo, keyword_redo}, EXPR_END},
 #line 34 "defs/keywords"
-      {"next", {keyword_next, keyword_next}, EXPR_MID},
+      {offsetof(struct stringpool_t, stringpool_str36), {keyword_next, keyword_next}, EXPR_MID},
 #line 43 "defs/keywords"
-      {"super", {keyword_super, keyword_super}, EXPR_ARG},
+      {offsetof(struct stringpool_t, stringpool_str37), {keyword_super, keyword_super}, EXPR_ARG},
 #line 33 "defs/keywords"
-      {"module", {keyword_module, keyword_module}, EXPR_VALUE},
+      {offsetof(struct stringpool_t, stringpool_str38), {keyword_module, keyword_module}, EXPR_VALUE},
 #line 18 "defs/keywords"
-      {"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
+      {offsetof(struct stringpool_t, stringpool_str39), {keyword_begin, keyword_begin}, EXPR_BEG},
 #line 12 "defs/keywords"
-      {"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str40), {keyword__LINE__, keyword__LINE__}, EXPR_END},
 #line 13 "defs/keywords"
-      {"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str41), {keyword__FILE__, keyword__FILE__}, EXPR_END},
 #line 11 "defs/keywords"
-      {"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str42), {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
 #line 15 "defs/keywords"
-      {"END", {keyword_END, keyword_END}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str43), {keyword_END, keyword_END}, EXPR_END},
 #line 16 "defs/keywords"
-      {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
+      {offsetof(struct stringpool_t, stringpool_str44), {keyword_alias, keyword_alias}, EXPR_FNAME},
 #line 14 "defs/keywords"
-      {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
+      {offsetof(struct stringpool_t, stringpool_str45), {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
 #line 23 "defs/keywords"
-      {"defined?", {keyword_defined, keyword_defined}, EXPR_ARG},
+      {offsetof(struct stringpool_t, stringpool_str46), {keyword_defined, keyword_defined}, EXPR_ARG},
 #line 21 "defs/keywords"
-      {"class", {keyword_class, keyword_class}, EXPR_CLASS},
-      {""}, {""},
+      {offsetof(struct stringpool_t, stringpool_str47), {keyword_class, keyword_class}, EXPR_CLASS},
+      {-1}, {-1},
 #line 50 "defs/keywords"
-      {"while", {keyword_while, modifier_while}, EXPR_VALUE}
+      {offsetof(struct stringpool_t, stringpool_str50), {keyword_while, modifier_while}, EXPR_VALUE}
     };
 
   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
@@ -206,10 +293,14 @@ rb_reserved_word (str, len) https://github.com/ruby/ruby/blob/trunk/lex.c.blt#L293
 
       if (key <= MAX_HASH_VALUE && key >= 0)
         {
-          register const char *s = wordlist[key].name;
+          register int o = wordlist[key].name;
+          if (o >= 0)
+            {
+              register const char *s = o + stringpool;
 
-          if (*str == *s && !strcmp (str + 1, s + 1))
-            return &wordlist[key];
+              if (*str == *s && !strcmp (str + 1, s + 1))
+                return &wordlist[key];
+            }
         }
     }
   return 0;
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 51332)
+++ Makefile.in	(revision 51333)
@@ -321,7 +321,9 @@ lex.c: defs/keywords https://github.com/ruby/ruby/blob/trunk/Makefile.in#L321
 	  $(CP) $(srcdir)/lex.c.blt $@; \
 	else \
 	  [ $(Q) ] && echo generating $@ || set -x; \
-	  gperf -C -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? > $@.tmp && \
+	  gperf -C -P -p -j1 -i 1 -g -o -t -N rb_reserved_word -k1,3,$$ $? \
+	  | sed 's/(int)(long)&((\(struct stringpool_t\) *\*)0)->\(stringpool_[a-z0-9]*\)/offsetof(\1, \2)/g' \
+	  > $@.tmp && \
 	  $(MV) $@.tmp $@ && \
 	  $(CP) $? $(srcdir)/defs/lex.c.src && \
 	  $(CP) $@ $(srcdir)/lex.c.blt; \

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

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